Package ortus.boxlang.runtime.events
Class InterceptorPool
java.lang.Object
ortus.boxlang.runtime.events.InterceptorPool
- Direct Known Subclasses:
InterceptorService
An InterceptorPool is a pool of interceptors that can be used to intercept events
within the BoxLang runtime.
This pool can be used at any level to provide encapsulation of events and provide a way to intercept and modify the behavior of the runtime, service, etc.
This class should be instantiated and used as a singleton.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe list of interception points we can listen forprotected Map<Key, InterceptorState> The collection of interception states registered with the serviceprotected ConcurrentHashMap<String, Key> Key registry of announced states, to avoid key creationprotected KeyThe name of the poolprotected BoxRuntimeThe runtime singleton -
Constructor Summary
ConstructorsConstructorDescriptionInterceptorPool(String name, BoxRuntime runtime) Construct a pool with a unique nameInterceptorPool(Key name, BoxRuntime runtime) Construct a pool with a unique name -
Method Summary
Modifier and TypeMethodDescriptionvoidAnnounce an event with the providedIStructof data.voidAnnounce a BoxEvent with no data using a BoxEvent object as the statevoidAnnounce an event with the providedIStructof data.voidAnnounce an event with no data using a Key object as the statevoidAnnounce an event with the providedIStructof data.voidannounce(Key state, IStruct data, IBoxContext context) Announce an event with the providedIStructof data and contextannounceAsync(String state, IStruct data) Announce an event with the providedIStructof data asynchronously.announceAsync(BoxEvent state) Announce a BoxEvent with no data using a BoxEvent object as the state asynchronouslyannounceAsync(BoxEvent state, IStruct data) Announce an event with the providedIStructof data asynchronously.announceAsync(Key state) Announce an event with no data using a Key object as the state asynchronouslyannounceAsync(Key state, IStruct data) Announce an event with the providedIStructof data asynchronously.announceAsync(Key state, IStruct data, IBoxContext context) Announce an event with the providedIStructof data and context asynchronouslyvoidClear all the interception states Use with caution.Get the list of interception points that the pool can announceGet the list of interception points that the pool can announce but as a Set of string names not case insensitive Key objectsGet the registered interception statesGet the runtime logger for interceptorsgetName()Get the name of the poolGet theInterceptorStateby namehasInterceptionPoint(Key interceptionPoint) Check if the pool has an interception pointCheck if the service has theInterceptorStatestatic Key[]inflateStates(Object states) Inflates an array or string of states into a list of keysnewAndRegister(String clazz, IStruct properties, String name, ModuleRecord moduleRecord) This method resolves, creates, wires, and registers a BoxLang interceptor Class with the service.register(IInterceptor interceptor) This method registers a Java interceptor with the pool by metadata inspection of theInterceptionPointannotation.register(IInterceptorLambda interceptor, Key... states) Register a Java Lambda Interceptor with the pool on the provided states.register(IInterceptor interceptor, IStruct properties) This method registers a Java interceptor with the pool by metadata inspection of theInterceptionPointannotation.register(DynamicObject interceptor, Key... states) Register an interceptor with the pool which must be an instance ofDynamicObject.register(IClassRunnable interceptor) This method registers a BoxLang interceptor with the pool by metadata inspection.registerInterceptionPoint(Key... points) Register an interception point(s) with the poolregisterState(Key name) Register a newInterceptorStatewith the pool and returns it.removeInterceptionPoint(Key... points) Remove an interception point(s) from the poolremoveState(Key name) Remove theInterceptorStatefrom the pool.unregister(IInterceptor interceptor) This method UNregisters a Java interceptor with the pool by metadata inspection of theInterceptionPointannotation.unregister(DynamicObject interceptor) Unregister an interceptor from all statesunregister(DynamicObject interceptor, Key... states) Unregister an interceptor from the provided states.
-
Field Details
-
interceptionPoints
The list of interception points we can listen for -
interceptionStates
The collection of interception states registered with the service -
keyRegistry
Key registry of announced states, to avoid key creation -
name
The name of the pool -
runtime
The runtime singleton
-
-
Constructor Details
-
InterceptorPool
Construct a pool with a unique name- Parameters:
name- The name of the poolruntime- The runtime singleton
-
InterceptorPool
Construct a pool with a unique name- Parameters:
name- The name of the pool
-
-
Method Details
-
getName
Get the name of the pool- Returns:
- The name of the pool
-
getInterceptionPoints
Get the list of interception points that the pool can announce- Returns:
- A set of unique interception points
-
getInterceptionStates
Get the registered interception states- Returns:
- The registered interception states
-
clearInterceptionStates
public void clearInterceptionStates()Clear all the interception states Use with caution. Mostly left for testing purposes -
getInterceptionPointsNames
Get the list of interception points that the pool can announce but as a Set of string names not case insensitive Key objects- Returns:
- The list of interception points
-
hasInterceptionPoint
Check if the pool has an interception point- Parameters:
interceptionPoint- The interception point to check- Returns:
- True if the pool has the interception point, false otherwise
-
registerInterceptionPoint
Register an interception point(s) with the pool- Parameters:
points- The interception point(s) to register- Returns:
- The same pool
-
removeInterceptionPoint
Remove an interception point(s) from the pool- Parameters:
points- The interception point(s) to remove- Returns:
- The same pool
-
getState
Get theInterceptorStateby name- Parameters:
name- The name of the state- Returns:
- The state if it exists, null otherwise
-
hasState
Check if the service has theInterceptorState- Parameters:
name- The name of the state- Returns:
- True if the service has the state, false otherwise
-
registerState
Register a newInterceptorStatewith the pool and returns it. This verifies if there is already an interception point by that name. If there is not, it will add it.- Parameters:
name- The name of the state- Returns:
- The registered
InterceptorState
-
removeState
Remove theInterceptorStatefrom the pool. This essentially destroys all the interceptor references in the state- Parameters:
name- The name of the state- Returns:
- The same pool
-
newAndRegister
public IClassRunnable newAndRegister(String clazz, IStruct properties, String name, ModuleRecord moduleRecord) This method resolves, creates, wires, and registers a BoxLang interceptor Class with the service.- Parameters:
clazz- The BoxLang class invocation path of the interceptor to resolve. Example: "ortus.interceptors.MyInterceptor"properties- A of properties to wire the interceptor withname- The unique name of the interceptormoduleRecord- If passed (it can be null), it means that a module is registering the interceptor- Returns:
- The newly built interceptor
- Throws:
BoxRuntimeException- If the interceptor class cannot be found
-
register
This method registers a Java interceptor with the pool by metadata inspection of theInterceptionPointannotation. It will inspect the interceptor for methods that match the states that the pool can announce. If the- Parameters:
interceptor- The interceptor to register that must implementIInterceptor- Returns:
- The pool
-
register
This method registers a Java interceptor with the pool by metadata inspection of theInterceptionPointannotation. It will inspect the interceptor for methods that match the states that the pool can announce. If the interceptor has a method that matches the state, it will register it with the pool.- Parameters:
interceptor- The interceptor to register that must implementIInterceptorproperties- A of properties to wire the interceptor with- Returns:
- The same pool
-
unregister
This method UNregisters a Java interceptor with the pool by metadata inspection of theInterceptionPointannotation. It will inspect the interceptor for methods that match the states that the pool can announce. If the interceptor has a method that matches the state, it will UNregister it with the pool.- Parameters:
interceptor- The interceptor to UNregister that must implementIInterceptor- Returns:
- The same pool
-
register
This method registers a BoxLang interceptor with the pool by metadata inspection. It will inspect the interceptor for methods that match the states that the pool can announce. If the interceptor has a method that matches the state, it will register it with the pool. If a method has ainterceptionPointBoxLang annotation, then the name of the method will be registered as a valid state and auto-registered.- Parameters:
interceptor- The interceptor to register that must implementIClassRunnable- Returns:
- The same pool
-
register
Register an interceptor with the pool which must be an instance ofDynamicObject. The interceptor must have a method(s) according to the passed states.- Parameters:
interceptor- The interceptor to registerstates- The states to register the interceptor with- Returns:
- The same pool
-
register
Register a Java Lambda Interceptor with the pool on the provided states.- Parameters:
interceptor- The interceptor lambda to registerstates- The states to register the interceptor with- Returns:
- The same pool
-
unregister
Unregister an interceptor from the provided states.- Parameters:
interceptor- The interceptor to unregisterstates- The states to unregister the interceptor from- Returns:
- The same pool
-
unregister
Unregister an interceptor from all states- Parameters:
interceptor- The interceptor to unregister- Returns:
- The same pool
-
announce
Announce an event with no data using a Key object as the state- Parameters:
state- The state key to announce
-
announce
Announce a BoxEvent with no data using a BoxEvent object as the state- Parameters:
state- The state key to announce
-
announce
Announce an event with the providedIStructof data.- Parameters:
state- The state to announcedata- The data to announce
-
announce
Announce an event with the providedIStructof data.- Parameters:
state- The state to announcedata- The data to announce
-
announce
Announce an event with the providedIStructof data.- Parameters:
state- The state key to announcedata- The data to announce
-
announce
Announce an event with the providedIStructof data and context- Parameters:
state- The state key to announcedata- The data to announce
-
announceAsync
Announce an event with no data using a Key object as the state asynchronously- Parameters:
state- The state key to announce- Returns:
- A CompletableFuture of the data or null if the state does not exist
-
announceAsync
Announce a BoxEvent with no data using a BoxEvent object as the state asynchronously- Parameters:
state- The state key to announce- Returns:
- A CompletableFuture of the data or null if the state does not exist
-
announceAsync
Announce an event with the providedIStructof data asynchronously.- Parameters:
state- The state to announcedata- The data to announce- Returns:
- A CompletableFuture of the data or null if the state does not exist
-
announceAsync
Announce an event with the providedIStructof data asynchronously.- Parameters:
state- The state to announcedata- The data to announce- Returns:
- A CompletableFuture of the data or null if the state does not exist
-
announceAsync
Announce an event with the providedIStructof data asynchronously.- Parameters:
state- The state key to announcedata- The data to announce- Returns:
- A CompletableFuture of the data or null if the state does not exist
-
announceAsync
Announce an event with the providedIStructof data and context asynchronously- Parameters:
state- The state key to announcedata- The data to announce- Returns:
- A CompletableFuture of the data or null if the state does not exist
-
getLogger
Get the runtime logger for interceptors -
inflateStates
Inflates an array or string of states into a list of keys- Parameters:
states- The states to inflate- Returns:
- The list of keys representing the states
-