Package dev.relism.flash.extension
Class FlashApp
Single entry point for Flash. Owns one flat Startup sequence (both
FastPathRouterImpl —
all routes (app-level and scoped) compile into a single FSM at startup.
FlashApp.create(8080)
.install(new JacksonExtension())
.use(cors)
.get("/ping", (req, res) -> "pong")
.get("/secured", (req, res) -> user(), oidc.protect())
.scan("dev.example.handlers")
.mount("/api", scope -> scope.get("/health", (req, res) -> "ok"))
.startAndBlock(); // blocks main thread
Startup sequence (both start() and startAndBlock())
- Extensions sorted by
FlashExtension.priority()— lower first. - All
FlashExtension.provide(dev.relism.flash.extension.FlashContext)— register services, processors, listeners. FlashContext.resolveAll()— topo-sort, cycle detection.- All
FlashExtension.routes(dev.relism.flash.extension.FlashRegistrar<?>, dev.relism.flash.extension.FlashContext)— routes registered, services available. - Compile all routes into one flat FSM — zero prefix scanning at runtime.
- Accept loop started.
Default error handlers
Dev mode (-Dflash.env=dev): rich HTML with stack traces.
Prod mode (default): generic JSON — no internal details leaked.
Override via onException(dev.relism.flash.routing.AbstractRouter.ExceptionHandler) / onNotFound(dev.relism.flash.models.SimpleHandler.FunctionalHandler).-
Method Summary
Modifier and TypeMethodDescriptionprotected voidRegisters a middleware in this registrar's own scope (global or scope-level).protected voidaddRoute(HttpMethod method, String path, RequestHandler handler, List<Middleware> mw) Adds a route immediately to this registrar's deferred compilation list.protected voidaddWsRoute(String path, WebSocketEndpoint endpoint) static FlashAppcreate(int port) static FlashAppcreate(FlashConfiguration cfg) ctx()Returns theFlashContextfor this registrar.install(FlashExtension ext) Registers an extension for two-phase installation at startup.mount(String namespace, Consumer<FlashScope> configure) Mounts a scoped group of routes undernamespace.start()Boots the server and starts accepting connections.voidBoots the server and blocks the calling thread until the server is stopped.stop()ws(String path, WebSocketHandler handler) Registers a WebSocket endpoint atpath.Methods inherited from class dev.relism.flash.extension.FlashRegistrar
connect, delete, get, head, instantiate, instantiateWs, options, patch, post, purge, put, scan, trace, use
-
Method Details
-
create
-
create
-
mount
Mounts a scoped group of routes undernamespace. Routes accumulate in aFlashScopebuilder and merge into this app's single flat router at startup — pure syntactic sugar, no extra router involved. -
ws
Registers a WebSocket endpoint atpath. Runs on the same virtual-thread model as HTTP handlers. A path may have both an HTTP handler and a WS endpoint simultaneously. -
onException
-
onNotFound
-
ctx
Description copied from class:FlashRegistrarReturns theFlashContextfor this registrar.- Specified by:
ctxin classFlashRegistrar<FlashApp>
-
install
Registers an extension for two-phase installation at startup. Install order is irrelevant — allFlashExtension.provide(dev.relism.flash.extension.FlashContext)calls complete before anyFlashExtension.routes(dev.relism.flash.extension.FlashRegistrar<?>, dev.relism.flash.extension.FlashContext)call begins. Extensions are sorted byFlashExtension.priority()before execution. -
start
Boots the server and starts accepting connections. Returns immediately — the accept loop runs on a background platform thread.Use
startAndBlock()inmain()if you have no other work to do after startup.- Returns:
thisfor storing or chaining (e.g..start().ctx().require(...))
-
startAndBlock
public void startAndBlock()Boots the server and blocks the calling thread until the server is stopped. Suitable for the end ofmain()— no need to keep the JVM alive manually. -
stop
-
addRoute
protected void addRoute(HttpMethod method, String path, RequestHandler handler, List<Middleware> mw) Description copied from class:FlashRegistrarAdds a route immediately to this registrar's deferred compilation list. Subclasses may prepend a namespace prefix and inject scope middlewares before storing.- Specified by:
addRoutein classFlashRegistrar<FlashApp>
-
addWsRoute
- Specified by:
addWsRoutein classFlashRegistrar<FlashApp>
-
addMiddleware
Description copied from class:FlashRegistrarRegisters a middleware in this registrar's own scope (global or scope-level).- Specified by:
addMiddlewarein classFlashRegistrar<FlashApp>
-