
Package ca.uhn.fhir.interceptor.executor
Class BaseInterceptorService<POINTCUT extends IPointcut>
java.lang.Object
ca.uhn.fhir.interceptor.executor.BaseInterceptorService<POINTCUT>
- All Implemented Interfaces:
IBaseInterceptorBroadcaster<POINTCUT>
,IBaseInterceptorService<POINTCUT>
- Direct Known Subclasses:
InterceptorService
public abstract class BaseInterceptorService<POINTCUT extends IPointcut>
extends Object
implements IBaseInterceptorService<POINTCUT>, IBaseInterceptorBroadcaster<POINTCUT>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
protected static class
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor which uses a default name of "default"BaseInterceptorService
(String theName) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
callHooks
(POINTCUT thePointcut, HookParams theParams) Invoke registered interceptor hook methods for the given Pointcut.callHooksAndReturnObject
(POINTCUT thePointcut, HookParams theParams) Invoke registered interceptor hook methods for the given Pointcut.protected static <T extends Annotation>
Optional<T>findAnnotation
(AnnotatedElement theObject, Class<T> theHookClass) Returns all currently registered interceptors (excluding any thread local interceptors).boolean
Does this broadcaster have any hooks for the given pointcut?boolean
Are threadlocal interceptors enabled on this registry (defaults to true)protected void
registerAnonymousInterceptor
(POINTCUT thePointcut, Object theInterceptor, BaseInterceptorService.BaseInvoker theInvoker) boolean
registerInterceptor
(Object theInterceptor) Register an interceptor.void
registerInterceptors
(Collection<?> theInterceptors) boolean
registerThreadLocalInterceptor
(Object theInterceptor) Register an interceptor that will be used in aThreadLocal
context.protected abstract Optional<BaseInterceptorService.HookDescriptor>
scanForHook
(Method nextMethod) void
void
setThreadlocalInvokersEnabled
(boolean theThreadlocalInvokersEnabled) Are threadlocal interceptors enabled on this registry (defaults to true)void
setWarnOnInterceptorWithNoHooks
(boolean theWarnOnInterceptorWithNoHooks) Should a warning be issued if an interceptor is registered and it has no hooksvoid
Unregisters all anonymous interceptors (i.e.void
Unregisters all registered interceptors.boolean
unregisterInterceptor
(Object theInterceptor) Unregister an interceptor.void
unregisterInterceptors
(Collection<?> theInterceptors) void
unregisterInterceptorsIf
(Predicate<Object> theShouldUnregisterFunction) Unregisters all interceptors that are indicated by the given callback function returningtrue
void
unregisterThreadLocalInterceptor
(Object theInterceptor) Unregisters a ThreadLocal interceptor
-
Constructor Details
-
BaseInterceptorService
public BaseInterceptorService()Constructor which uses a default name of "default" -
BaseInterceptorService
Constructor- Parameters:
theName
- The name for this registry (useful for troubleshooting)
-
-
Method Details
-
setWarnOnInterceptorWithNoHooks
Should a warning be issued if an interceptor is registered and it has no hooks -
isThreadlocalInvokersEnabled
Are threadlocal interceptors enabled on this registry (defaults to true) -
setThreadlocalInvokersEnabled
Are threadlocal interceptors enabled on this registry (defaults to true) -
setName
-
registerAnonymousInterceptor
protected void registerAnonymousInterceptor(POINTCUT thePointcut, Object theInterceptor, BaseInterceptorService.BaseInvoker theInvoker) -
getAllRegisteredInterceptors
Description copied from interface:IBaseInterceptorService
Returns all currently registered interceptors (excluding any thread local interceptors).- Specified by:
getAllRegisteredInterceptors
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
-
unregisterAllInterceptors
Description copied from interface:IBaseInterceptorService
Unregisters all registered interceptors. Note that this method does not unregister anythread local interceptors
.- Specified by:
unregisterAllInterceptors
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
-
unregisterInterceptors
- Specified by:
unregisterInterceptors
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
-
registerInterceptors
- Specified by:
registerInterceptors
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
-
unregisterAllAnonymousInterceptors
Description copied from interface:IBaseInterceptorService
Unregisters all anonymous interceptors (i.e. all interceptors registered withregisterAnonymousInterceptor
)- Specified by:
unregisterAllAnonymousInterceptors
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
-
unregisterInterceptorsIf
Description copied from interface:IBaseInterceptorService
Unregisters all interceptors that are indicated by the given callback function returningtrue
- Specified by:
unregisterInterceptorsIf
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
-
registerThreadLocalInterceptor
Description copied from interface:IBaseInterceptorService
Register an interceptor that will be used in aThreadLocal
context. This means that events will only be broadcast to the given interceptor if they were fired from the current thread.Note that it is almost always desirable to call this method with a try-finally statement that removes the interceptor afterwards, since this can lead to memory leakage, poor performance due to ever-increasing numbers of interceptors, etc.
Note that most methods such as
IBaseInterceptorService.getAllRegisteredInterceptors()
andIBaseInterceptorService.unregisterAllInterceptors()
do not affect thread local interceptors as they are kept in a separate list.- Specified by:
registerThreadLocalInterceptor
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
- Parameters:
theInterceptor
- The interceptor- Returns:
- Returns
true
if at least one valid hook method was found on this interceptor
-
unregisterThreadLocalInterceptor
Description copied from interface:IBaseInterceptorService
Unregisters a ThreadLocal interceptor- Specified by:
unregisterThreadLocalInterceptor
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
- Parameters:
theInterceptor
- The interceptor- See Also:
-
registerInterceptor
Description copied from interface:IBaseInterceptorService
Register an interceptor. This method has no effect if the given interceptor is already registered.- Specified by:
registerInterceptor
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
- Parameters:
theInterceptor
- The interceptor to register- Returns:
- Returns
true
if at least one valid hook method was found on this interceptor
-
unregisterInterceptor
Description copied from interface:IBaseInterceptorService
Unregister an interceptor. This method has no effect if the given interceptor is not already registered.- Specified by:
unregisterInterceptor
in interfaceIBaseInterceptorService<POINTCUT extends IPointcut>
- Parameters:
theInterceptor
- The interceptor to unregister- Returns:
- Returns
true
if the interceptor was found and removed
-
callHooksAndReturnObject
Description copied from interface:IBaseInterceptorBroadcaster
Invoke registered interceptor hook methods for the given Pointcut. This method should only be called for pointcuts that return a type other thanvoid
orboolean
- Specified by:
callHooksAndReturnObject
in interfaceIBaseInterceptorBroadcaster<POINTCUT extends IPointcut>
- Returns:
- Returns the object returned by the first hook method that did not return
null
-
hasHooks
Description copied from interface:IBaseInterceptorBroadcaster
Does this broadcaster have any hooks for the given pointcut?- Specified by:
hasHooks
in interfaceIBaseInterceptorBroadcaster<POINTCUT extends IPointcut>
- Parameters:
thePointcut
- The poointcut- Returns:
- Does this broadcaster have any hooks for the given pointcut?
-
callHooks
Description copied from interface:IBaseInterceptorBroadcaster
Invoke registered interceptor hook methods for the given Pointcut.- Specified by:
callHooks
in interfaceIBaseInterceptorBroadcaster<POINTCUT extends IPointcut>
- Returns:
- Returns
false
if any of the invoked hook methods returnedfalse
, and returnstrue
otherwise.
-
scanForHook
-
findAnnotation
protected static <T extends Annotation> Optional<T> findAnnotation(AnnotatedElement theObject, Class<T> theHookClass)
-