Interface FilterFactory<C,I>
- Type Parameters:
C- the type of configuration used to create theFilter. UseVoidif theFilteris not configurable.I- The type of the initialization data
A pluggable source of Filter instances.
FilterFactories are:
- service implementations provided by filter authors
- called by the proxy runtime to create filter instances
Lifecycle scope
FilterFactory instances are scoped per virtual cluster: each virtual
cluster that references a filter definition gets its own FilterFactory instance with its
own initialize/close
pair. The same filter type used by two virtual clusters produces two independent instances with
independent initialization data — there is no cross-virtual-cluster sharing. Within a single
virtual cluster, a filter definition referenced multiple times in the chain (e.g. an audit filter
applied before and after a transformation) is initialized once and its initialization data is
shared across all positions in that virtual cluster's chain.
Per virtual cluster, the proxy runtime guarantees that:
- instances will be initialized before any attempt to create filter instances,
- instances will eventually be close(Object) closed} if and only if they were successfully initialized,
- no attempts to create filter instances will be made once a
FilterFactoryinstance is closed, initializeandcloseare never invoked on a Netty event loop thread — blocking work (e.g. closing an HTTP/KMS client) is safe in either method.
Filter instance creation can happen on a different thread than initialization or cleanup.
It is suggested to pass state using via the return value from createFilter(FilterFactoryContext, Object) rather than
relying on synchronization within a filter factory implementation.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidCalled by the runtime to release any resources associated with the giveninitializationData.createFilter(FilterFactoryContext context, I initializationData) Creates an instance of the Filter.initialize(FilterFactoryContext context, C config) Initializes the factory with the specified configuration.
-
Method Details
-
initialize
@UnknownNullness I initialize(FilterFactoryContext context, @UnknownNullness C config) throws PluginConfigurationException Initializes the factory with the specified configuration.
This method is guaranteed to be called at most once per virtual cluster for each filter definition referenced by that virtual cluster, and before any call to
createFilter(FilterFactoryContext, Object)on that virtual cluster. Note that becauseFilterFactoryinstances are per-virtual-cluster (see the class javadoc), the same filter type used by multiple virtual clusters will see oneinitializecall per virtual cluster — each on a differentFilterFactoryinstance with its own initialization data.This method may provide extra semantic validation of the config, and returns some object (which may be the config, or some other object) which will be passed to
createFilter(FilterFactoryContext, Object).- Parameters:
context- contextconfig- configuration- Returns:
- A configuration state object, specific to the given
config, which will be passed to the other methods of this interface. - Throws:
PluginConfigurationException- when the configuration is invalid
-
createFilter
Creates an instance of the Filter.This can be called on a different thread from
initialize(FilterFactoryContext, Object)andclose(I). Implementors should either use theinitializationDatato pass state frominitialize(FilterFactoryContext, Object)or use appropriate synchronization.- Parameters:
context- The runtime context for the filter's creation.initializationData- The initialization data that was returned frominitialize(FilterFactoryContext, Object).- Returns:
- the Filter instance.
-
close
Called by the runtime to release any resources associated with the giveninitializationData. This is guaranteed to eventually be called for each successful call toinitialize(FilterFactoryContext, Object). Once this method has been calledcreateFilter(FilterFactoryContext, Object)won't be called again.- Parameters:
initializationData- The initialization data that was returned frominitialize(FilterFactoryContext, Object).
-