public class RouterHandler extends Object implements Handler
DispatchHandler
.
It looks for route configuration files (very similar to the usual general config file)
in a defined directory (by default it looks in config/routes/).
{
"name": "Router",
"type": "Router",
"config": {
"directory": "/tmp/routes",
"defaultHandler": "404NotFound",
"scanInterval": 2 or "2 seconds"
}
}
Note that scanInterval can be defined in 2 ways :
Modifier and Type | Class and Description |
---|---|
static class |
RouterHandler.Heaplet
Creates and initializes a routing handler in a heap environment.
|
Constructor and Description |
---|
RouterHandler(org.forgerock.openig.handler.router.RouteBuilder builder,
org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor,
MeterRegistry routerMeterRegistry)
Builds a router that loads its configuration from the given directory.
|
Modifier and Type | Method and Description |
---|---|
void |
deploy(String routeId,
String routeName,
JsonValue routeConfig)
Deploy a route, meaning that it loads it but also stores it in a file.
|
Promise<Response,NeverThrowsException> |
handle(Context context,
Request request)
|
void |
onChanges(org.forgerock.openig.handler.router.FileChangeSet changes)
Notify that changes has been detected in the monitored directory.
|
void |
stop()
Stops this handler, shutting down and clearing all the managed routes.
|
JsonValue |
undeploy(String routeId)
Undeploy a route, meaning that it unloads it but also deletes the associated file.
|
void |
update(String routeId,
String routeName,
JsonValue routeConfig)
Update a route.
|
public RouterHandler(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor, MeterRegistry routerMeterRegistry)
builder
- route builderdirectoryMonitor
- the directory monitorrouterMeterRegistry
- The router's meter registrypublic void stop()
public void deploy(String routeId, String routeName, JsonValue routeConfig) throws RouterHandlerException
routeId
- the id of the route to deployrouteName
- the name of the route to deployrouteConfig
- the configuration of the route to deployRouterHandlerException
- if the given routeConfig is not validpublic JsonValue undeploy(String routeId) throws RouterHandlerException
routeId
- the id of the route to removeRouterHandlerException
- if the given routeId is not validpublic void update(String routeId, String routeName, JsonValue routeConfig) throws RouterHandlerException
routeId
- the id of the route to updaterouteName
- the name of the route to updaterouteConfig
- the new route's configurationRouterHandlerException
- if the given routeConfig is not validpublic Promise<Response,NeverThrowsException> handle(Context context, Request request)
Handler
Promise
representing the asynchronous Response
of the given request
.
If any (asynchronous) processing goes wrong, the promise still contains a Response
(probably from the
4xx or 5xx status code family).
A handler that doesn't hand-off the processing to another downstream handler is responsible for creating the response.
The returned Promise
contains the response returned from the server as-is.
This is responsibility of the handler to produce the appropriate error response (404,
500, ...) in case of processing error.
Note: As of Promise 2.0 implementation, it is not permitted to throw any runtime exception here. Doing so produce unexpected behaviour (most likely a server-side hang of the processing thread).
public void onChanges(org.forgerock.openig.handler.router.FileChangeSet changes)
changes
- Content of the change setCopyright 2011-2017 ForgeRock AS.