public class EventBus extends Object
EventBusReader
and
EventBusWriter
, the bus allows pipelines to be loosely coupled and used in one-to-many (publish-subscribe)
scenarios.EventBusReader
,
EventBusWriter
Modifier and Type | Class and Description |
---|---|
static class |
EventBus.State |
Modifier and Type | Field and Description |
---|---|
static Logger |
log |
Constructor and Description |
---|
EventBus()
Creates a bus using a single thread to deliver events.
|
EventBus(ExecutorService executorService)
Creates a bus using the specified ExecutorService to deliver events to listeners.
|
Modifier and Type | Method and Description |
---|---|
static void |
addEventBusLifecycleListener(EventBusLifecycleListener listener) |
EventBus |
addExceptionListener(EventFilter filter,
ExceptionListener listener) |
EventBus |
addExceptionListener(ExceptionListener listener) |
<T> EventBus |
addListener(Class<T> eventListenerClass,
EventFilter filter,
T listener) |
<T> EventBus |
addListener(Class<T> eventListenerClass,
EventFilter filter,
T listener,
Object topic) |
<T> EventBus |
addListener(Class<T> eventListenerClass,
T listener) |
EventBus |
addListener(EventFilter filter,
UntypedEventListener listener)
Deprecated.
|
EventBus |
addListener(EventFilter filter,
UntypedEventListener listener,
Object topic)
Deprecated.
|
EventBus |
addListener(UntypedEventListener listener)
Deprecated.
Use
addUntypedEventListener(UntypedEventListener) instead. |
EventBus |
addShutdownListener(EventFilter filter,
ShutdownListener listener) |
EventBus |
addUntypedEventListener(EventFilter filter,
UntypedEventListener listener) |
EventBus |
addUntypedEventListener(EventFilter filter,
UntypedEventListener listener,
Object topic) |
EventBus |
addUntypedEventListener(UntypedEventListener listener) |
void |
assertAlive()
Asserts that this endpoint has started reading or writing, otherwise an exception is thrown.
|
protected void |
cleanupGarbage() |
protected Object |
clone() |
protected <T> void |
deliverEvent(Event<T> event) |
protected void |
finalize() |
static List<EventBus> |
getAll() |
long |
getCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution by this bus' executorService or -1 if unknown.
|
long |
getCorePoolSize()
Returns the core number of threads in this bus' executorService or -1 if unknown.
|
Date |
getCreatedOn()
The time this job instance was created.
|
static Event<?> |
getCurrentEvent()
Returns the event currently being delivered on this thread.
|
long |
getErrorCount()
Returns the number of exceptions this bus has experienced.
|
long |
getEventsActive()
Returns the approximate number of threads that are actively delivering events using this bus' executorService or -1 if unknown.
|
long |
getEventsDelivered()
Returns the combined number of events each listener on this event bus has received (typically
getEventsPublished() * getListenerCount() ). |
long |
getEventsPublished()
Returns the number of events sent to this event bus for delivery to listeners.
|
long |
getEventsQueued()
Returns the number of events waiting to be executed by this bus' executorService or -1 if unknown.
|
long |
getId()
Returns the unique (sequential) ID of this event bus (within this JVM/classloader).
|
long |
getLargestPoolSize()
Returns the largest number of threads that have ever simultaneously been in the pool in this bus' executorService or -1 if unknown.
|
int |
getListenerCount()
Returns the total number of listeners subscribed to this bus.
|
long |
getMaximumPoolSize()
Returns the maximum allowed number of threads in this bus' executorService or -1 if unknown.
|
String |
getName()
Returns the name assigned to this bus or its default name if one was not assigned.
|
long |
getPoolSize()
Returns the current number of threads in this bus' executorService pool or -1 if unknown.
|
<T> T |
getPublisher(Class<T> eventListenerClass) |
<T> T |
getPublisher(Object eventSource,
Class<T> eventListenerClass) |
<T> T |
getPublisher(Object eventSource,
Class<T> eventListenerClass,
Object topic) |
long |
getPublishersCreated()
Returns the number of event publishers created by this bus.
|
long |
getShutdownTimeout()
Returns the time in milliseconds this bus will wait for events to complete before forcibly shutting down (defaults to 30 seconds).
|
String |
getShutdownTimeoutAsString()
Returns time as human readable string this bus will wait for events to complete before forcibly shutting down (defaults to 30 seconds).
|
EventBus.State |
getState()
Returns the current state of this bus.
|
static EventBus |
getSystemEventBus() |
long |
getTaskCount()
Returns the approximate total number of tasks that have ever been scheduled for execution by this bus' executorService or -1 if unknown.
|
int |
getTypedListenerCount()
Returns the number of type-specific listeners subscribed to this bus.
|
protected <T> TypedListenerList<T> |
getTypedListenerList(Class<T> eventListenerClass) |
int |
getUntypedEventListenerCount()
Returns the number of non-type-specific listeners subscribed to this bus.
|
int |
getUntypedListenerCount()
Deprecated.
Use
getUntypedEventListenerCount() instead. |
UUID |
getUuid()
Returns the universally unique identifier (UUID) for this job.
|
protected void |
handleException(Event<?> event,
Object listener,
Throwable e) |
protected long |
incEventsDelivered() |
boolean |
isAlive()
Returns true if this bus has not been shutdown.
|
boolean |
isDebug()
Indicates if the bus should emit debug log messages when events are published or delivered and during the shutdown process.
|
boolean |
isNotAlive()
Returns true if this bus has been shutdown or is in the process of shutting down.
|
boolean |
isPublishLifecycleEvents()
Indicates if the bus should publish its own EventBusLifecycleListener and ShutdownListener events (defaults to
true ). |
boolean |
isUseStrongListenerReference()
Indicates if the event bus uses strong references (default) or soft references for holding listeners added to the bus.
|
protected <T> void |
publishEvent(Event<T> event) |
static void |
removeEventBusLifecycleListener(EventBusLifecycleListener listener) |
EventBus |
removeExceptionListener(ExceptionListener listener) |
<T> EventBus |
removeListener(Class<T> eventListenerClass,
T listener) |
EventBus |
removeListener(Object listener) |
EventBus |
removeListener(UntypedEventListener listener)
Deprecated.
Use
removeUntypedEventListener(UntypedEventListener) instead. |
<T> EventBus |
removeListenersByTopic(Class<T> eventListenerClass,
Object topic) |
EventBus |
removeShutdownListener(ShutdownListener listener) |
protected EventBus |
removeTypedListenerReference(Reference<?> reference) |
EventBus |
removeUntypedEventListener(UntypedEventListener listener) |
protected EventBus |
removeUntypedEventListenerReference(Reference<?> reference) |
EventBus |
removeUntypedEventListenersByTopic(Object topic) |
protected EventBus |
removeUntypedListenerReference(Reference<?> reference)
Deprecated.
Use
removeUntypedEventListenerReference(Reference) instead. |
EventBus |
setDebug(boolean debug)
Indicates if the bus should emit debug log messages when events are published or delivered and during the shutdown process.
|
EventBus |
setName(String name)
Assigns a new name to this bus.
|
EventBus |
setPublishLifecycleEvents(boolean publishLifecycleEvents)
Indicates if the bus should publish its own EventBusLifecycleListener and ShutdownListener events (defaults to
true ). |
EventBus |
setShutdownTimeout(long shutdownTimeout)
Sets the time in milliseconds this bus will wait for events to complete before forcibly shutting down (defaults to 30 seconds).
|
EventBus |
setUseStrongListenerReference(boolean useStrongListenerReference)
Indicates if the event bus uses strong references (default) or soft references for holding listeners added to the bus.
|
void |
shutdown() |
public EventBus(ExecutorService executorService)
public EventBus()
public static EventBus getSystemEventBus()
public static void addEventBusLifecycleListener(EventBusLifecycleListener listener)
public static void removeEventBusLifecycleListener(EventBusLifecycleListener listener)
public static Event<?> getCurrentEvent()
public long getId()
public UUID getUuid()
public String getName()
public EventBus.State getState()
public boolean isAlive()
getState()
== EventBus.State.ALIVE
public boolean isNotAlive()
getState()
!= EventBus.State.ALIVE
public void assertAlive()
public Date getCreatedOn()
public boolean isDebug()
public EventBus setDebug(boolean debug)
public long getShutdownTimeout()
public String getShutdownTimeoutAsString()
public boolean isPublishLifecycleEvents()
true
).public EventBus setPublishLifecycleEvents(boolean publishLifecycleEvents)
true
).public EventBus setShutdownTimeout(long shutdownTimeout)
public boolean isUseStrongListenerReference()
public EventBus setUseStrongListenerReference(boolean useStrongListenerReference)
public long getPublishersCreated()
public long getEventsPublished()
public long getEventsDelivered()
getEventsPublished()
* getListenerCount()
).protected long incEventsDelivered()
public long getEventsActive()
public long getEventsQueued()
public long getTaskCount()
public long getCompletedTaskCount()
public long getCorePoolSize()
public long getLargestPoolSize()
public long getMaximumPoolSize()
public long getPoolSize()
public long getErrorCount()
public EventBus addExceptionListener(ExceptionListener listener)
public EventBus addExceptionListener(EventFilter filter, ExceptionListener listener)
public EventBus removeExceptionListener(ExceptionListener listener)
public EventBus addShutdownListener(EventFilter filter, ShutdownListener listener)
public EventBus removeShutdownListener(ShutdownListener listener)
protected <T> TypedListenerList<T> getTypedListenerList(Class<T> eventListenerClass)
public <T> EventBus addListener(Class<T> eventListenerClass, EventFilter filter, T listener)
public <T> EventBus addListener(Class<T> eventListenerClass, EventFilter filter, T listener, Object topic)
public <T> EventBus removeListenersByTopic(Class<T> eventListenerClass, Object topic)
protected EventBus removeTypedListenerReference(Reference<?> reference)
public int getTypedListenerCount()
@Deprecated public EventBus addListener(UntypedEventListener listener)
addUntypedEventListener(UntypedEventListener)
instead.public EventBus addUntypedEventListener(UntypedEventListener listener)
@Deprecated public EventBus addListener(EventFilter filter, UntypedEventListener listener)
addUntypedEventListener(EventFilter, UntypedEventListener)
instead.public EventBus addUntypedEventListener(EventFilter filter, UntypedEventListener listener)
@Deprecated public EventBus addListener(EventFilter filter, UntypedEventListener listener, Object topic)
addUntypedEventListener(EventFilter, UntypedEventListener, Object)
instead.public EventBus addUntypedEventListener(EventFilter filter, UntypedEventListener listener, Object topic)
@Deprecated public EventBus removeListener(UntypedEventListener listener)
removeUntypedEventListener(UntypedEventListener)
instead.public EventBus removeUntypedEventListener(UntypedEventListener listener)
@Deprecated protected EventBus removeUntypedListenerReference(Reference<?> reference)
removeUntypedEventListenerReference(Reference)
instead.protected EventBus removeUntypedEventListenerReference(Reference<?> reference)
@Deprecated public int getUntypedListenerCount()
getUntypedEventListenerCount()
instead.public int getUntypedEventListenerCount()
public int getListenerCount()
public <T> T getPublisher(Class<T> eventListenerClass)
public <T> T getPublisher(Object eventSource, Class<T> eventListenerClass, Object topic)
protected <T> void publishEvent(Event<T> event)
protected void cleanupGarbage()
protected void finalize() throws Throwable
public void shutdown() throws InterruptedException
InterruptedException
protected Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.