Interface RouterFactory<C,I>
- Type Parameters:
C- the configuration type, deserialized from the router'sconfigproperty in the configuration file. UseVoidif not configurable.I- the initialisation data type
Router instances.
RouterFactories are service
implementations called by the proxy
runtime to create router instances. Each RouterFactory instance
is scoped to a single virtual cluster.
The proxy runtime guarantees that:
- instances will be initialized before any attempt to create router instances,
- instances will eventually be closed if and only if they were successfully initialized,
- no attempts to create router instances will be made once a
RouterFactoryinstance is closed, - instances will be initialized and closed on the same thread.
Per-connection router instances:
createRouter(io.kroxylicious.proxy.router.RouterFactoryContext, I) is called once per client connection, so each
connection gets its own Router instance. Any state that must
survive a client disconnect and reconnect (e.g. producer ID mappings)
must be stored in the shared initialisation data I, not in
the Router instance itself.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidReleases resources associated with the given initialisation data.createRouter(RouterFactoryContext context, I initializationData) Creates a new router instance.initialize(RouterFactoryContext context, C config) Initializes the factory with the given configuration.
-
Method Details
-
initialize
@UnknownNullness I initialize(RouterFactoryContext context, @UnknownNullness C config) throws PluginConfigurationException Initializes the factory with the given configuration.Called once per virtual cluster. The returned initialisation data is shared across all
Routerinstances created bycreateRouter(io.kroxylicious.proxy.router.RouterFactoryContext, I)and must be thread-safe, since routers run on different Netty event loop threads.- Parameters:
context- the factory contextconfig- the configuration- Returns:
- initialisation data to be passed to
createRouter(io.kroxylicious.proxy.router.RouterFactoryContext, I) - Throws:
PluginConfigurationException- if the configuration is invalid
-
createRouter
Creates a new router instance.This may be called on a different thread from
initialize(io.kroxylicious.proxy.router.RouterFactoryContext, C)andclose(I).- Parameters:
context- the factory contextinitializationData- the data returned frominitialize(io.kroxylicious.proxy.router.RouterFactoryContext, C)- Returns:
- a new router instance
-
close
Releases resources associated with the given initialisation data.- Parameters:
initializationData- the data returned frominitialize(io.kroxylicious.proxy.router.RouterFactoryContext, C)
-