Interface NodeCommandInterceptor
- All Superinterfaces:
AutoCloseable, Closeable
ServiceLoader and may be provided at startup via --ext.
Interceptors are called in the order they are loaded. Each interceptor receives a next
callable that, when invoked, advances to the next interceptor or executes the actual command.
The lifecycle of an enabled interceptor mirrors the LocalNode that hosts it: initialize(Config, EventBus) is called once at node startup and close() is called once when the node shuts
down. Implementations that hold resources (thread pools, file handles, network connections)
should release them in close().
Typical usage — subscribe to session-lifecycle events in initialize(Config, EventBus) (via the
bus), then annotate or observe each command in intercept(SessionId, HttpRequest, Callable):
public void initialize(Config config, EventBus bus) {
bus.addListener(SessionCreatedEvent.listener(data -> onSessionStarted(data)));
bus.addListener(SessionClosedEvent.listener(data -> onSessionStopped(data)));
}
public HttpResponse intercept(SessionId id, HttpRequest req, Callable<HttpResponse> next)
throws Exception {
before(id, req);
HttpResponse response = next.call();
after(id, req, response);
return response;
}
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Called once when theLocalNodeshuts down.voidinitialize(Config config, EventBus bus) Called once during node startup afterisEnabled(Config)returnstrue.intercept(SessionId id, HttpRequest req, Callable<HttpResponse> next) Wraps execution of a single WebDriver HTTP command.booleanReturnstruewhen this interceptor should be activated for the given config.
-
Method Details
-
isEnabled
Returnstruewhen this interceptor should be activated for the given config. -
initialize
Called once during node startup afterisEnabled(Config)returnstrue. Implementations should subscribe to session-lifecycle events on thebushere. -
close
Called once when theLocalNodeshuts down. Implementations should release any resources acquired ininitialize(Config, EventBus)(thread pools, open files, network connections).The default implementation is a no-op; override only when cleanup is needed.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
intercept
Wraps execution of a single WebDriver HTTP command. Implementations MUST callnext.call()exactly once and return its result (possibly augmented).- Parameters:
id- the session ID extracted from the request URIreq- the incoming HTTP requestnext- callable that advances to the next interceptor or executes the command- Returns:
- the HTTP response to return to the caller
- Throws:
Exception
-