public final class LockFreeEventPublisher extends Object implements EventPublisher
EventPublisher
interface.
This class is a drop-in replacement for EventPublisherImpl
except that it does not
synchronise on the internal map of event type to ListenerInvoker
, and should handle
much higher parallelism of event dispatch.
One can customise the event listening by instantiating with custom
listener handlers
and the event dispatching through
EventDispatcher
. See the com.atlassian.event.spi
package
for more information.
ListenerHandler
,
EventDispatcher
Constructor and Description |
---|
LockFreeEventPublisher(EventDispatcher eventDispatcher,
ListenerHandlersConfiguration listenerHandlersConfiguration) |
LockFreeEventPublisher(EventDispatcher eventDispatcher,
ListenerHandlersConfiguration listenerHandlersConfiguration,
InvokerTransformer transformer)
If you need to customise the asynchronous handling, you should use the
AsynchronousAbleEventDispatcher
together with a custom executor. |
Modifier and Type | Method and Description |
---|---|
void |
publish(Object event)
Publish an event that will be consumed by all listeners which have registered to receive it.
|
void |
register(Object listener)
Register a listener to receive events.
|
void |
unregister(Object listener)
Un-register a listener so that it will no longer receive events.
|
void |
unregisterAll()
Un-register all listeners that this registrar knows about.
|
public LockFreeEventPublisher(EventDispatcher eventDispatcher, ListenerHandlersConfiguration listenerHandlersConfiguration)
public LockFreeEventPublisher(EventDispatcher eventDispatcher, ListenerHandlersConfiguration listenerHandlersConfiguration, InvokerTransformer transformer)
AsynchronousAbleEventDispatcher
together with a custom executor.
You might also want to have a look at using the
EventThreadFactory
to keep the naming
of event threads consistent with the default naming of the Atlassian Event
library.
eventDispatcher
- the event dispatcher to be used with the publisherlistenerHandlersConfiguration
- the list of listener handlers to be used with this publishertransformer
- the batcher for batching up listener invocationsAsynchronousAbleEventDispatcher
,
EventThreadFactory
public void publish(@Nonnull Object event)
EventPublisher
EventListener
and one argument which is assignable from the event type (i.e. a superclass
or interface implemented by the event object). Implementations may also dispatch events
to legacy EventListener
implementations based on the types returned
from EventListener.getHandledEventClasses()
.
This method should process all event listeners, despite any errors or exceptions that are generated
as a result of dispatching the event.publish
in interface EventPublisher
event
- the event to publishpublic void register(@Nonnull Object listener)
EventListenerRegistrar
EventListener
annotation. Legacy
implementations may also support listeners which implement the now-deprecated
EventListener
interface.register
in interface EventListenerRegistrar
listener
- The listener that is being registeredannotation which can be used to indicate event listener methods
public void unregister(@Nonnull Object listener)
EventListenerRegistrar
unregister
in interface EventListenerRegistrar
listener
- The listener to un-registerpublic void unregisterAll()
EventListenerRegistrar
unregisterAll
in interface EventListenerRegistrar
Copyright © 2006-2016 Atlassian. All Rights Reserved.