Class ListenerService
java.lang.Object
org.exoplatform.services.listener.ListenerService
- All Implemented Interfaces:
org.picocontainer.Startable
Created by The eXo Platform SAS
Listener Service is reponsible for notifying the
Listener Service is reponsible for notifying the
Listener
when a given event is broadcasted.- Author:
- : Nhu Dinh Thuan.
- eXo level API
- Platform
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThis AsynchronousListener is a wrapper for original listener, that executes wrapped listeners onEvent() in separate thread.protected classThis thread executes listener.onEvent(event) method. -
Constructor Summary
ConstructorsConstructorDescriptionListenerService(org.exoplatform.container.ExoContainerContext ctx) Construct a listener service.ListenerService(org.exoplatform.container.ExoContainerContext ctx, org.exoplatform.container.xml.InitParams params) Construct a listener service.ListenerService(org.exoplatform.container.ExoContainerContext ctx, InitialContextInitializer initializer) Construct a listener service.ListenerService(org.exoplatform.container.ExoContainerContext ctx, InitialContextInitializer initializer, org.exoplatform.container.xml.InitParams params) Construct a listener service. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(String eventName, Listener listener) This method is used to register a newListener.voidaddListener(Listener listener) This method is used to register aListenerto the events of the same name.<S,D> void This method is used to broadcast an event.<T extends Event>
voidbroadcast(T event) This method is used when a developer want to implement his own event object and broadcast the event.voidstart()voidstop()
-
Constructor Details
-
ListenerService
public ListenerService(org.exoplatform.container.ExoContainerContext ctx) Construct a listener service. -
ListenerService
public ListenerService(org.exoplatform.container.ExoContainerContext ctx, InitialContextInitializer initializer) Construct a listener service. -
ListenerService
public ListenerService(org.exoplatform.container.ExoContainerContext ctx, org.exoplatform.container.xml.InitParams params) Construct a listener service. -
ListenerService
public ListenerService(org.exoplatform.container.ExoContainerContext ctx, InitialContextInitializer initializer, org.exoplatform.container.xml.InitParams params) Construct a listener service.
-
-
Method Details
-
addListener
This method is used to register aListenerto the events of the same name. It is similar to addListener(listener.getName(), listener)- Parameters:
listener- the listener to notify any time an even of the same name is triggered
-
addListener
This method is used to register a newListener. Any time an event of the given event name has been triggered, theListenerwill be notified. This method will:- Check if it exists a list of listeners that have been registered for the given event name, create a new list if no list exists
- Add the listener to the list
- Parameters:
eventName- The name of the event to listen tolistener- The Listener to notify any time the event with the given name is triggered
-
broadcast
This method is used to broadcast an event. This method should: 1. Check if there is a list of listener that listen to the event name. 2. If there is a list of listener, create the event object with the given name , source and data 3. For each listener in the listener list, invoke the method onEvent(Event)- Type Parameters:
S- The type of the source that broacast the eventD- The type of the data that the source object is working on- Parameters:
name- The name of the eventsource- The source object instancedata- The data object instance- Throws:
Exception- if an exception occurs
-
broadcast
This method is used when a developer want to implement his own event object and broadcast the event. The method should: 1. Check if there is a list of listener that listen to the event name. 2. If there is a list of the listener, ror each listener in the listener list, invoke the method onEvent(Event)- Type Parameters:
T- The type of the event object, the type of the event object has to be extended from the Event type- Parameters:
event- The event instance- Throws:
Exception
-
start
public void start()- Specified by:
startin interfaceorg.picocontainer.Startable
-
stop
public void stop()- Specified by:
stopin interfaceorg.picocontainer.Startable
-