Class AbstractRouter

java.lang.Object
dev.relism.flash.routing.AbstractRouter
Direct Known Subclasses:
FastPathRouterImpl

public abstract class AbstractRouter extends Object
Base router contract. Owns error handlers and the compile-time middleware wrapping logic. The only concrete implementation is FastPathRouterImpl.

All middleware composition happens once at boot time; the hot-path sees only a plain RequestHandler call with zero allocation overhead.

Default error handlers

  • Dev mode (-Dflash.env=dev): rich HTML pages with full stack traces.
  • Prod mode (default): generic JSON — no internal detail leaked to clients.
Override via FlashApp.onNotFound(dev.relism.flash.models.SimpleHandler.FunctionalHandler) / FlashApp.onException(dev.relism.flash.routing.AbstractRouter.ExceptionHandler).

Registration: use FlashApp — the single public registration API. doRegister(dev.relism.flash.http.HttpMethod, java.lang.String, dev.relism.flash.models.RequestHandler, dev.relism.flash.routing.Middleware[]) is an infrastructure method.

  • Field Details

  • Constructor Details

    • AbstractRouter

      public AbstractRouter()
  • Method Details

    • compile

      public void compile()
      Eagerly validates and compiles this route graph before traffic is accepted.
    • getNotFoundHandler

      public SimpleHandler getNotFoundHandler()
    • getExceptionHandler

      public AbstractRouter.ExceptionHandler getExceptionHandler()
    • onNotFound

      public void onNotFound(SimpleHandler.FunctionalHandler handler)
    • onException

      public void onException(AbstractRouter.ExceptionHandler handler)
    • doRegister

      public AbstractRouter doRegister(HttpMethod method, String path, RequestHandler handler, Middleware[] middlewares)
      Registers a handler with a pre-built middleware array. Compiles the middleware chain once at boot — zero overhead on hot-path.
    • newScratch

      public Object newScratch()
      Creates a fresh per-connection scratch object for 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 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).
    • route

      public abstract RequestHandler route(Request request, Object scratch)
    • addRoute

      protected abstract AbstractRouter addRoute(HttpMethod method, String path, RequestHandler handler)