Class Backend.Builder
- Enclosing class:
Backend
-
Method Summary
Modifier and TypeMethodDescriptionapplication(Backend.Application application) The build-generated wiring of this server's beans.backlog(int backlog) The listen backlog.compiledSettings(String[] keysAndValues) Settings compiled in from the settings annotations, as key and value pairs: the bottom layer of the configuration, below the properties files and the environment.createTables(boolean create) Whether to create the table of every generated entity at start-up.dataSource(DataSource dataSource) A pool the caller opened.dataSource(String url) The database, as a SQLite path or a postgres:// or mysql:// URL.handler(HttpServer.Handler handler) Adds a handler.handlers(Backend.Handlers factory) Adds handlers built once the database exists.The address to bind, or null for every interface.Serves the management endpoints -- health, metrics, jobs and managed beans -- when the configuration turns them on; seeManagement.mcp(McpServer.Extension devTools) Serves the MCP endpoint, with the application's@McpToolmethods and, whendevToolsis given and the profile is a development one, the development tools.Adds a tool of the program's own to the MCP endpoint, beside the@McpToolmethods the build found.metrics(MetricReader reader) Exports metrics with this reader, onceopenhas read the configuration and agreed to.port(int port) The port.quiet()Suppresses the line this prints when the server comes up.Says that the handlers this server builds need a database, so one is opened even when nothing else asks for it.voidrun()Starts the server, drains it on SIGTERM or SIGINT, and blocks until it stops.serviceName(String name) The name this server reports itself as, to MCP clients.sessionStore(SessionStore store) Keeps sessions instoreinstead of the configured one.shutdownTimeoutMillis(int millis) How long a stop waits for requests in flight.start()Starts the server and returns, without installing a signal handler or waiting.staticFiles(String root, String prefix, String indexFile, String cacheControl) Serves a directory, after every handler, so a file cannot shadow a route.Terminates TLS with a context the caller built.Terminates TLS with this certificate and key.Traces every request with this tracer, onceTracer.open(Config)has read the configuration and agreed to.webSockets(Backend.WebSocketEndpoints endpoints) Registers this server's websocket endpoints when it starts.workers(int workers) The size of the request thread pool.
-
Method Details
-
handler
Adds a handler. They are tried in the order they were added and the first that answers wins, so the generated routers go in before any catch-all. -
application
The build-generated wiring of this server's beans. SeeBackend.Application; the generated entry point calls this. -
handlers
Adds handlers built once the database exists. SeeBackend.Handlers. -
webSockets
Registers this server's websocket endpoints when it starts.
Called once, before the listener accepts anything, so there is no window in which a route exists in the application's mind and not in the server's -- which is what a
websocket(path, endpoint)setter on a started server left open. -
port
The port. Otherwise cn1.server.port, PORT, or 8080. -
host
The address to bind, or null for every interface. -
backlog
The listen backlog. Otherwise cn1.server.backlog, or 512. -
workers
The size of the request thread pool. Otherwise cn1.server.workers, or 16. -
shutdownTimeoutMillis
How long a stop waits for requests in flight. -
tls
Terminates TLS with this certificate and key.
Drops a context given to the other overload earlier, because resolveTls answers from the context FIRST: without this, a builder configured conditionally kept serving the old certificate and this call did nothing at all -- silently, which is the part that matters, since an obsolete certificate looks like a working server until it expires. The last TLS choice wins, as it does for every other setter here.
Only when something is actually supplied. tls(null, null) is not a way to turn a context off; it would make an argument nobody meant as a choice erase one that was.
-
tls
Terminates TLS with a context the caller built.
Drops paths given to the other overload earlier, for the reason stated there, and on the same terms: a null context is not a choice and erases nothing.
-
staticFiles
public Backend.Builder staticFiles(String root, String prefix, String indexFile, String cacheControl) throws IOException Serves a directory, after every handler, so a file cannot shadow a route.- Throws:
IOException
-
dataSource
The database, as a SQLite path or a postgres:// or mysql:// URL.
Drops a pool given to the other overload earlier: openDataSource answers from the pool FIRST, so without this a builder configured conditionally kept the earlier pool and this call was ignored -- which is a server reading and WRITING to the wrong database while its configuration says otherwise. The last choice wins.
Ownership follows the same rule and stays correct either way: the builder opens this URL itself and therefore closes it, while a pool handed in belongs to the caller.
-
dataSource
A pool the caller opened. It is closed when this server stops.
Drops a URL given to the other overload earlier, for the reason stated there. A null pool is not a choice and erases nothing.
-
createTables
Whether to create the table of every generated entity at start-up. Otherwise cn1.orm.createTables, which defaults to true on a development profile and false everywhere else. -
requiresDataSource
Says that the handlers this server builds need a database, so one is opened even when nothing else asks for it.
The generated entry point calls this when any controller declares a constructor taking a
DataSourceor anEntityManager. Without it, a controller that declares a database dependency, has no entities behind it, and runs on a development profile with no URL configured was refused at start-up byBackend.requireDataSource(DataSource, String)-- whose message suggests running on a development profile, which is what was already happening.The alternative was to open the development default whenever the profile allows it. That is the wrong fix: it would give a database to every server that has no use for one, which contradicts "a server with no database opens none" and costs a file handle to prove it. What was actually missing is that a DECLARED dependency did not drive the decision, and the build knows exactly which controllers declare one.
-
tracing
Traces every request with this tracer, onceTracer.open(Config)has read the configuration and agreed to. The build calls this from the entry point it generates for a project that enables OpenTelemetry, which is why nothing else refers to a tracer implementation. -
metrics
Exports metrics with this reader, onceopenhas read the configuration and agreed to. The build calls this from the entry point of a project that enables OpenTelemetry. -
mcp
Serves the MCP endpoint, with the application's
@McpToolmethods and, whendevToolsis given and the profile is a development one, the development tools. The build calls this; seeMcpServer.This method is the only code that names the endpoint's classes. The generated entry point calls it only for a build that asked for MCP, and the translator drops a method nothing calls -- so a server that did not ask has none of the endpoint in its binary.
-
management
Serves the management endpoints -- health, metrics, jobs and managed beans -- when the configuration turns them on; seeManagement. Likemcp(McpServer.Extension), this is the only code that names them, and the generated entry point calls it only for a build that asked for them. -
compiledSettings
Settings compiled in from the settings annotations, as key and value pairs: the bottom layer of the configuration, below the properties files and the environment. The build calls this. -
mcpTool
Adds a tool of the program's own to the MCP endpoint, beside the@McpToolmethods the build found. Needsmcp(McpServer.Extension). -
serviceName
The name this server reports itself as, to MCP clients. -
quiet
Suppresses the line this prints when the server comes up. -
sessionStore
Keeps sessions instoreinstead of the configured one. Installed before the server listens, so no request can have used another store first -- which is why this is the way to set one, rather than replacing the store of a server already running. -
start
-
run
-