Class CustomHandlerServer
WebhookHandler, no framework.
Azure starts the custom-handler process and tells it which port to listen on via the
FUNCTIONS_CUSTOMHANDLER_PORT environment variable; startFromEnvironment(WebhookHandler)
reads it. Nothing here is Azure-specific beyond that one variable — the same server runs
identically under func start locally, or under any other host that can point HTTP
traffic at a port.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhich pathexecuteShutdown(HttpServer, AtomicBoolean, String, String, long)took. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadattachShutdownHook(HttpServer server, AtomicBoolean isDraining, String token, String baseUrl, long drainDeadlineSeconds) Attaches a JVM shutdown hook that runsexecuteShutdown(HttpServer, AtomicBoolean, String, String, long)on SIGTERM.executeShutdown(HttpServer server, AtomicBoolean isDraining, String token, String baseUrl, long drainDeadlineSeconds) Executes the shutdown procedure and reports which path was taken.static HttpServerstart(int port, String path, WebhookHandler handler) Starts the server on an explicit port and path.static HttpServerstart(int port, String path, WebhookHandler handler, AtomicBoolean isDraining) Starts the server on an explicit port and path with a shared drain flag.static HttpServerstartFromEnvironment(WebhookHandler handler) Starts the server on the port named byFUNCTIONS_CUSTOMHANDLER_PORT(default8080), servinghandlerat/api/webhook, and attaches a SIGTERM shutdown hook using environment variables.
-
Field Details
-
ENV_BOT_TOKEN
Environment variable name holding the bot bearer token.- See Also:
-
ENV_PLAY_API_BASE_URL
Environment variable name holding play-api's base URL.- See Also:
-
ENV_DRAIN_DEADLINE_SECONDS
Environment variable name holding the drain deadline in seconds.- See Also:
-
-
Method Details
-
startFromEnvironment
Starts the server on the port named byFUNCTIONS_CUSTOMHANDLER_PORT(default8080), servinghandlerat/api/webhook, and attaches a SIGTERM shutdown hook using environment variables.- Parameters:
handler- the webhook logic to serve- Returns:
- the running server; call
HttpServer.stop(int)to shut it down - Throws:
IOException- if the port cannot be bound
-
start
Starts the server on an explicit port and path.- Parameters:
port- the port to listen onpath- the pathhandleranswers onhandler- the webhook logic to serve- Returns:
- the running server; call
HttpServer.stop(int)to shut it down - Throws:
IOException- if the port cannot be bound
-
start
public static HttpServer start(int port, String path, WebhookHandler handler, AtomicBoolean isDraining) throws IOException Starts the server on an explicit port and path with a shared drain flag.- Parameters:
port- the port to listen onpath- the pathhandleranswers onhandler- the webhook logic to serveisDraining- the flag indicating whether drain mode is active- Returns:
- the running server; call
HttpServer.stop(int)to shut it down - Throws:
IOException- if the port cannot be bound
-
executeShutdown
public static CustomHandlerServer.ShutdownOutcome executeShutdown(HttpServer server, AtomicBoolean isDraining, String token, String baseUrl, long drainDeadlineSeconds) Executes the shutdown procedure and reports which path was taken.With a token,
POST /bot/games/resign-allconcedes every game the bot is seated in and pauses its seating, which is the only mechanism that reaches a game whose turn is not currently the bot's. A refused or unreachable call falls through to drain mode rather than exiting as if the games had been conceded: an expired token answers401, and silently treating that as success leaves the bot's games running until they flag.Drain mode answers every further delivery with a resignation until
drainDeadlineSecondselapses. It is best-effort by nature: a game only receives a delivery when it is the bot's turn.This method never calls
System.exit. It is invoked from a shutdown hook, andRuntime.exitcalled while the shutdown sequence is already running blocks that thread indefinitely, so the JVM would hang until the orchestrator's SIGKILL instead of stopping cleanly.- Parameters:
server- the server to stopisDraining- the flag controlling drain modetoken- the bot token, ornull/blank if unconfiguredbaseUrl- play-api base URLdrainDeadlineSeconds- drain mode timeout in seconds- Returns:
- which path the shutdown actually took
-
attachShutdownHook
public static Thread attachShutdownHook(HttpServer server, AtomicBoolean isDraining, String token, String baseUrl, long drainDeadlineSeconds) Attaches a JVM shutdown hook that runsexecuteShutdown(HttpServer, AtomicBoolean, String, String, long)on SIGTERM.- Parameters:
server- the server to stopisDraining- the flag controlling drain modetoken- the bot token, ornull/blank if unconfiguredbaseUrl- play-api base URLdrainDeadlineSeconds- drain mode timeout in seconds- Returns:
- the attached shutdown hook thread
-