public abstract class AbstractDispatcher extends Object implements MessageDispatcher
MessageDispatcher
implementations.
The subclasses implement the actual dispatching strategy, but this base class
manages the registration of MessageHandler
s. Although the implemented
dispatching strategies may invoke handles in different ways (e.g. round-robin
vs. failover), this class does maintain the order of the underlying
collection. See the OrderedAwareCopyOnWriteArraySet
for more detail.
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
AbstractDispatcher() |
Modifier and Type | Method and Description |
---|---|
boolean |
addHandler(MessageHandler handler)
Add the handler to the internal Set.
|
int |
getHandlerCount() |
protected Set<MessageHandler> |
getHandlers()
Returns an unmodifiable
Set of this dispatcher's handlers. |
boolean |
removeHandler(MessageHandler handler)
Remove the handler from the internal handler Set.
|
void |
setMaxSubscribers(int maxSubscribers)
Set the maximum subscribers allowed by this dispatcher.
|
String |
toString() |
protected boolean |
tryOptimizedDispatch(Message<?> message) |
protected RuntimeException |
wrapExceptionIfNecessary(Message<?> message,
Exception e) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
dispatch
public void setMaxSubscribers(int maxSubscribers)
maxSubscribers
- The maximum number of subscribers allowed.protected Set<MessageHandler> getHandlers()
Set
of this dispatcher's handlers. This
is provided for access by subclasses.public boolean addHandler(MessageHandler handler)
addHandler
in interface MessageDispatcher
handler
- The handler to add.Set.add(Object)
public boolean removeHandler(MessageHandler handler)
removeHandler
in interface MessageDispatcher
Set.remove(Object)
protected boolean tryOptimizedDispatch(Message<?> message)
protected RuntimeException wrapExceptionIfNecessary(Message<?> message, Exception e)
public int getHandlerCount()