Class FastPathRouterImpl

java.lang.Object
dev.relism.flash.routing.AbstractRouter
dev.relism.flash.routing.routers.fastpathrouter.FastPathRouterImpl

public class FastPathRouterImpl extends AbstractRouter
Router backed by the fpr-core byte-level state machine. Routes are compiled lazily on the first request and recompiled when routes are added after startup. Matching runs on a virtual METHOD + path byte sequence in a single pass; the per-connection FastPathRouterImpl.RouteScratch (newScratch()) owns the reused MatchResult, FastPathViews.MethodPathByteView and path-param arrays that would otherwise allocate request.
  • Constructor Details

    • FastPathRouterImpl

      public FastPathRouterImpl()
  • Method Details

    • newScratch

      public Object newScratch()
      Description copied from class: AbstractRouter
      Creates a fresh per-connection scratch object for AbstractRouter.route(dev.relism.flash.models.Request, java.lang.Object), or null if this router implementation keeps no reusable per-connection state. Called once per connection by the connection driver (e.g. Http1Connection), which holds the opaque result and passes it back into every AbstractRouter.route(dev.relism.flash.models.Request, java.lang.Object) call for that connection's whole lifetime — the same "create once per connection, reuse across requests" shape already used there for RequestParser. thread", which under this codebase's one-virtual-thread-per-connection model is "one per connection with no upper bound and no pooling" — exactly the failure mode ConnectionScratch already exists to avoid for every other per-connection buffer. An explicit, caller-owned scratch object achieves the same per-connection reuse without that unbounded-growth risk, and without requiring routing to depend on transport's ConnectionScratch type (this package has no such dependency than extending ConnectionScratch itself, which is what an earlier draft of this fix assumed).
      Overrides:
      newScratch in class AbstractRouter
    • addRoute

      protected AbstractRouter addRoute(HttpMethod method, String path, RequestHandler handler)
      Specified by:
      addRoute in class AbstractRouter
    • route

      public RequestHandler route(Request request, Object scratchObj)
      Specified by:
      route in class AbstractRouter
    • compile

      public void compile()
      Description copied from class: AbstractRouter
      Eagerly validates and compiles this route graph before traffic is accepted.
      Overrides:
      compile in class AbstractRouter