Package org.ametys.core.observation
Class ObservationManager
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.core.observation.ObservationManager
-
- All Implemented Interfaces:
Disposable
,Component
,Contextualizable
,LogEnabled
,Serviceable
public class ObservationManager extends AbstractLogEnabled implements Component, Serviceable, Contextualizable, Disposable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
ObservationManager.AbstractAsyncObserve
Runnable to be used for asynchronous calls(package private) static class
ObservationManager.AsyncObserveThreadFactory
Thread factory for async observers.(package private) class
ObservationManager.NonParallelAsyncObserve
Runnable for non parallel observers(package private) class
ObservationManager.ParallelAsyncObserve
Runnable for parallel observers
-
Field Summary
Fields Modifier and Type Field Description private static String
__ADDITIONAL_ARGS_TO_PASS_BY_EVENT_ID_REQUEST_ATTR_NAME
private static org.slf4j.Logger
__ALL_EVENTS_LOGGER
private static String
__CURRENT_FUTURES_REQUEST_ATTR_NAME
private static ExecutorService
__PARALLEL_THREAD_EXECUTOR
The executor service managing the thread pool of asynchronous observers allowed to run in parallel.private static ExecutorService
__SINGLE_THREAD_EXECUTOR
The executor service managing the single thread pool.private Context
_avalonContext
protected Context
_context
Cocoon contextprotected ServiceManager
_manager
Service managerprivate ObserverExtensionPoint
_observerExtPt
private Collection<Observer>
_registeredObservers
static String
ROLE
Avalon ROLE.
-
Constructor Summary
Constructors Constructor Description ObservationManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_addSupportedObserver(List<Observer> supportedObservers, Observer observer, Event event)
private void
_asyncObserve(Collection<AsyncObserver> parallelObservers, List<AsyncObserver> nonParallelObservers, Event event, Map<String,Object> transientVars, List<Future> result)
Async observe through a thread poolprivate List<Future>
_getFuturesForRequest()
protected void
_observesEvent(Event event, List<Observer> supportedObservers, List<Future> result)
Observes the eventprivate void
_putAdditionalArgs(Event event)
void
addArgumentForEvents(String[] eventIds, String argName, Object argValue)
For all events of the given event id which will be notified during the current request, add an additional argumentvoid
contextualize(Context context)
void
dispose()
List<Future>
getFuturesForRequest()
Gets all theFuture
s of all theAsyncObserver
s notified by the call tonotify(Event)
during the current request.List<Future>
notify(Event event)
Notify of a event which will be dispatch to registered observers.void
registerObserver(Observer observer)
Registers anObserver
.void
removeArgumentForEvents(String[] eventIds, String argName)
For all events of the given event id which will be notified during the current request, removes the additional argument with the given name which was added with theaddArgumentForEvents(String[], String, Object)
method.void
service(ServiceManager manager)
void
unregisterObserver(Observer observer)
Unregisters anObserver
.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
__CURRENT_FUTURES_REQUEST_ATTR_NAME
private static final String __CURRENT_FUTURES_REQUEST_ATTR_NAME
-
__ADDITIONAL_ARGS_TO_PASS_BY_EVENT_ID_REQUEST_ATTR_NAME
private static final String __ADDITIONAL_ARGS_TO_PASS_BY_EVENT_ID_REQUEST_ATTR_NAME
-
__ALL_EVENTS_LOGGER
private static final org.slf4j.Logger __ALL_EVENTS_LOGGER
-
__SINGLE_THREAD_EXECUTOR
private static ExecutorService __SINGLE_THREAD_EXECUTOR
The executor service managing the single thread pool. This threads is used to run non-parallelizable observers.
-
__PARALLEL_THREAD_EXECUTOR
private static ExecutorService __PARALLEL_THREAD_EXECUTOR
The executor service managing the thread pool of asynchronous observers allowed to run in parallel.
-
_manager
protected ServiceManager _manager
Service manager
-
_avalonContext
private Context _avalonContext
-
_observerExtPt
private ObserverExtensionPoint _observerExtPt
-
_registeredObservers
private Collection<Observer> _registeredObservers
-
-
Constructor Detail
-
ObservationManager
public ObservationManager()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
notify
public List<Future> notify(Event event)
Notify of a event which will be dispatch to registered observers.- Parameters:
event
- the event to notify.- Returns:
- The
Future
objects of the asynchronous observers
-
_addSupportedObserver
private void _addSupportedObserver(List<Observer> supportedObservers, Observer observer, Event event)
-
getFuturesForRequest
public List<Future> getFuturesForRequest()
Gets all theFuture
s of all theAsyncObserver
s notified by the call tonotify(Event)
during the current request.
This can be useful to callFuture.get()
in order to ensure allAsyncObserver
s notified by the current request have finished to work.- Returns:
- the
Future
s of the notified observers during the current request.
-
_getFuturesForRequest
private List<Future> _getFuturesForRequest() throws CascadingRuntimeException
- Throws:
CascadingRuntimeException
-
addArgumentForEvents
public void addArgumentForEvents(String[] eventIds, String argName, Object argValue)
For all events of the given event id which will be notified during the current request, add an additional argument- Parameters:
eventIds
- The event idsargName
- The name of the additional argumentargValue
- The value of the additional argument
-
removeArgumentForEvents
public void removeArgumentForEvents(String[] eventIds, String argName)
For all events of the given event id which will be notified during the current request, removes the additional argument with the given name which was added with theaddArgumentForEvents(String[], String, Object)
method.- Parameters:
eventIds
- The event idsargName
- The name of the additional argument to remove
-
_putAdditionalArgs
private void _putAdditionalArgs(Event event)
-
_observesEvent
protected void _observesEvent(Event event, List<Observer> supportedObservers, List<Future> result) throws Exception
Observes the event- Parameters:
event
- The eventsupportedObservers
- list of observersresult
- The result object to fill- Throws:
Exception
- on error
-
_asyncObserve
private void _asyncObserve(Collection<AsyncObserver> parallelObservers, List<AsyncObserver> nonParallelObservers, Event event, Map<String,Object> transientVars, List<Future> result)
Async observe through a thread pool- Parameters:
parallelObservers
- parallelizable asynchronous observersnonParallelObservers
- non parallelizable asynchronous observersevent
- The event to observetransientVars
- The observer transient varsresult
- The future results
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
registerObserver
public void registerObserver(Observer observer)
Registers anObserver
.- Parameters:
observer
- theObserver
.
-
unregisterObserver
public void unregisterObserver(Observer observer)
Unregisters anObserver
.- Parameters:
observer
- theObserver
.
-
-