Package ca.uhn.fhir.interceptor.executor
Class InterceptorService
- java.lang.Object
-
- ca.uhn.fhir.interceptor.executor.InterceptorService
-
- All Implemented Interfaces:
IInterceptorBroadcaster,IInterceptorService
public class InterceptorService extends Object implements IInterceptorService, IInterceptorBroadcaster
-
-
Constructor Summary
Constructors Constructor Description InterceptorService()Constructor which uses a default name of "default"InterceptorService(String theName)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancallHooks(Pointcut thePointcut, HookParams theParams)Invoke registered interceptor hook methods for the given Pointcut.ObjectcallHooksAndReturnObject(Pointcut thePointcut, HookParams theParams)Invoke registered interceptor hook methods for the given Pointcut.List<Object>getAllRegisteredInterceptors()Returns all currently registered interceptors (excluding any thread local interceptors).booleanhasHooks(Pointcut thePointcut)Does this broadcaster have any hooks for the given pointcut?booleanisThreadlocalInvokersEnabled()Are threadlocal interceptors enabled on this registry (defaults to true)voidregisterAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor)voidregisterAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor)booleanregisterInterceptor(Object theInterceptor)Register an interceptor.voidregisterInterceptors(Collection<?> theInterceptors)booleanregisterThreadLocalInterceptor(Object theInterceptor)Register an interceptor that will be used in aThreadLocalcontext.voidsetName(String theName)voidsetThreadlocalInvokersEnabled(boolean theThreadlocalInvokersEnabled)Are threadlocal interceptors enabled on this registry (defaults to true)voidunregisterAllInterceptors()Unregisters all registered interceptors.booleanunregisterInterceptor(Object theInterceptor)Unregister an interceptor.voidunregisterInterceptors(Collection<?> theInterceptors)voidunregisterThreadLocalInterceptor(Object theInterceptor)Unregisters a ThreadLocal interceptor
-
-
-
Constructor Detail
-
InterceptorService
public InterceptorService()
Constructor which uses a default name of "default"
-
InterceptorService
public InterceptorService(String theName)
Constructor- Parameters:
theName- The name for this registry (useful for troubleshooting)
-
-
Method Detail
-
isThreadlocalInvokersEnabled
public boolean isThreadlocalInvokersEnabled()
Are threadlocal interceptors enabled on this registry (defaults to true)
-
setThreadlocalInvokersEnabled
public void setThreadlocalInvokersEnabled(boolean theThreadlocalInvokersEnabled)
Are threadlocal interceptors enabled on this registry (defaults to true)
-
registerAnonymousInterceptor
public void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor)
- Specified by:
registerAnonymousInterceptorin interfaceIInterceptorService
-
registerAnonymousInterceptor
public void registerAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor)
- Specified by:
registerAnonymousInterceptorin interfaceIInterceptorService
-
getAllRegisteredInterceptors
public List<Object> getAllRegisteredInterceptors()
Description copied from interface:IInterceptorServiceReturns all currently registered interceptors (excluding any thread local interceptors).- Specified by:
getAllRegisteredInterceptorsin interfaceIInterceptorService
-
unregisterAllInterceptors
public void unregisterAllInterceptors()
Description copied from interface:IInterceptorServiceUnregisters all registered interceptors. Note that this method does not unregister anythread local interceptors.- Specified by:
unregisterAllInterceptorsin interfaceIInterceptorService
-
unregisterInterceptors
public void unregisterInterceptors(@Nullable Collection<?> theInterceptors)
- Specified by:
unregisterInterceptorsin interfaceIInterceptorService
-
registerInterceptors
public void registerInterceptors(@Nullable Collection<?> theInterceptors)
- Specified by:
registerInterceptorsin interfaceIInterceptorService
-
registerThreadLocalInterceptor
public boolean registerThreadLocalInterceptor(Object theInterceptor)
Description copied from interface:IInterceptorServiceRegister an interceptor that will be used in aThreadLocalcontext. 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
IInterceptorService.getAllRegisteredInterceptors()andIInterceptorService.unregisterAllInterceptors()do not affect thread local interceptors as they are kept in a separate list.- Specified by:
registerThreadLocalInterceptorin interfaceIInterceptorService- Parameters:
theInterceptor- The interceptor- Returns:
- Returns
trueif at least one valid hook method was found on this interceptor
-
unregisterThreadLocalInterceptor
public void unregisterThreadLocalInterceptor(Object theInterceptor)
Description copied from interface:IInterceptorServiceUnregisters a ThreadLocal interceptor- Specified by:
unregisterThreadLocalInterceptorin interfaceIInterceptorService- Parameters:
theInterceptor- The interceptor- See Also:
IInterceptorService.registerThreadLocalInterceptor(Object)
-
registerInterceptor
public boolean registerInterceptor(Object theInterceptor)
Description copied from interface:IInterceptorServiceRegister an interceptor. This method has no effect if the given interceptor is already registered.- Specified by:
registerInterceptorin interfaceIInterceptorService- Parameters:
theInterceptor- The interceptor to register- Returns:
- Returns
trueif at least one valid hook method was found on this interceptor
-
unregisterInterceptor
public boolean unregisterInterceptor(Object theInterceptor)
Description copied from interface:IInterceptorServiceUnregister an interceptor. This method has no effect if the given interceptor is not already registered.- Specified by:
unregisterInterceptorin interfaceIInterceptorService- Parameters:
theInterceptor- The interceptor to unregister- Returns:
- Returns
trueif the interceptor was found and removed
-
callHooksAndReturnObject
public Object callHooksAndReturnObject(Pointcut thePointcut, HookParams theParams)
Description copied from interface:IInterceptorBroadcasterInvoke registered interceptor hook methods for the given Pointcut. This method should only be called for pointcuts that return a type other thanvoidorboolean- Specified by:
callHooksAndReturnObjectin interfaceIInterceptorBroadcaster- Returns:
- Returns the object returned by the first hook method that did not return
null
-
hasHooks
public boolean hasHooks(Pointcut thePointcut)
Description copied from interface:IInterceptorBroadcasterDoes this broadcaster have any hooks for the given pointcut?- Specified by:
hasHooksin interfaceIInterceptorBroadcaster- Parameters:
thePointcut- The poointcut- Returns:
- Does this broadcaster have any hooks for the given pointcut?
-
callHooks
public boolean callHooks(Pointcut thePointcut, HookParams theParams)
Description copied from interface:IInterceptorBroadcasterInvoke registered interceptor hook methods for the given Pointcut.- Specified by:
callHooksin interfaceIInterceptorBroadcaster- Returns:
- Returns
falseif any of the invoked hook methods returnedfalse, and returnstrueotherwise.
-
-