public class EventServiceImpl extends Object implements InternalEventService, MetricsProvider
eventSyncFrequency remote
event is sent as an operation and we wait for it to be submitted to the remote queue.
This implementation keeps registrations grouped into EventServiceSegments. Each segment is
responsible for a single service (e.g. map service, cluster service, proxy service).
The events are processed on a StripedExecutor. The executor has a fixed queue and thread size
and it is shared between all events meaning that it is important to configure it correctly. Inadequate thread
count sizing can lead to wasted threads or low throughput. Inadequate queue size can lead
to OutOfMemoryError or events being dropped when the queue is full.
The events are ordered by order key which can be defined when publishing the event meaning that you can
define your custom ordering. Events with the same order key will be processed by the same thread on
the executor.
This order can still be broken in some cases. This is possible because remote events are asynchronous and we don't wait for the response before publishing the next event. The previously published event can be retransmitted causing it to be received by the target node at a later time.
| Modifier and Type | Field and Description |
|---|---|
static String |
EVENT_SYNC_FREQUENCY_PROP
Usually remote events are sent asynchronously.
|
static String |
SERVICE_NAME |
| Constructor and Description |
|---|
EventServiceImpl(NodeEngineImpl nodeEngine) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(Packet packet)
Performs this operation on the given argument.
|
void |
close(EventRegistration eventRegistration)
Closes an EventRegistration.
|
void |
deregisterAllListeners(String serviceName,
String topic)
Deregisters all listeners belonging to the given service and topic.
|
boolean |
deregisterListener(String serviceName,
String topic,
Object id)
Deregisters a listener with the given registration ID.
|
void |
executeEventCallback(Runnable callback)
Executes an event callback on a random event thread.
|
StripedExecutor |
getEventExecutor() |
int |
getEventQueueCapacity()
Returns the queue capacity per event thread.
|
int |
getEventQueueSize()
Returns the current total event queue size.
|
int |
getEventThreadCount()
Returns the event thread count.
|
Operation |
getPostJoinOperation()
Post join operations must be lock free, meaning no locks at all:
no partition locks, no key-based locks, no service level locks, no database interaction!
The
Operation.getPartitionId() method should return a negative value. |
Operation |
getPreJoinOperation()
An operation to be executed on the joining member before it is set as joined.
|
Collection<EventRegistration> |
getRegistrations(String serviceName,
String topic)
Returns all registrations belonging to the given service and topic.
|
EventRegistration[] |
getRegistrationsAsArray(String serviceName,
String topic)
Returns all registrations belonging to the given service and topic as an array.
|
EventServiceSegment |
getSegment(String service,
boolean forceCreate)
Returns the
EventServiceSegment for the service. |
boolean |
handleRegistration(Registration reg) |
boolean |
hasEventRegistration(String serviceName,
String topic)
Returns true if a listener is registered with the specified service name and topic.
|
void |
onMemberLeft(MemberImpl member) |
void |
provideMetrics(MetricsRegistry registry) |
void |
publishEvent(String serviceName,
Collection<EventRegistration> registrations,
Object event,
int orderKey)
Publishes an event for multiple event registrations.
|
void |
publishEvent(String serviceName,
EventRegistration registration,
Object event,
int orderKey)
Publishes an event for a specific event registration.
|
void |
publishEvent(String serviceName,
String topic,
Object event,
int orderKey)
Publishes an event for all event registrations belonging to the specified service name and topic.
|
void |
publishRemoteEvent(String serviceName,
Collection<EventRegistration> registrations,
Object event,
int orderKey)
Publishes an event for multiple event registrations, excluding local ones.
|
EventRegistration |
registerListener(String serviceName,
String topic,
EventFilter filter,
Object listener)
Registers a listener on all cluster nodes with an event filter.
|
EventRegistration |
registerListener(String serviceName,
String topic,
Object listener)
Registers a listener on all cluster nodes.
|
EventRegistration |
registerLocalListener(String serviceName,
String topic,
EventFilter filter,
Object listener)
Registers a local only listener with an event filter.
|
EventRegistration |
registerLocalListener(String serviceName,
String topic,
Object listener)
Registers a local only listener.
|
void |
shutdown() |
public static final String SERVICE_NAME
public static final String EVENT_SYNC_FREQUENCY_PROP
SendEventOperation and we will
wait for the response. The default value is .public EventServiceImpl(NodeEngineImpl nodeEngine)
public void provideMetrics(MetricsRegistry registry)
provideMetrics in interface MetricsProviderpublic void close(EventRegistration eventRegistration)
InternalEventServiceIf the EventRegistration has any closeable resource, e.g. a listener, than this listener is closed.
close in interface InternalEventServiceeventRegistration - the EventRegistration to close.public int getEventThreadCount()
EventServicegetEventThreadCount in interface EventServiceGroupProperty.EVENT_THREAD_COUNTpublic int getEventQueueCapacity()
EventServicegetEventQueueCapacity in interface EventServiceGroupProperty.EVENT_QUEUE_CAPACITYpublic int getEventQueueSize()
EventServicegetEventQueueSize in interface EventServicepublic EventRegistration registerLocalListener(String serviceName, String topic, Object listener)
EventServiceregisterLocalListener in interface EventServiceserviceName - service nametopic - topic namelistener - listener instancepublic EventRegistration registerLocalListener(String serviceName, String topic, EventFilter filter, Object listener)
EventServiceregisterLocalListener in interface EventServiceserviceName - service nametopic - topic namefilter - event filterlistener - listener instancepublic EventRegistration registerListener(String serviceName, String topic, Object listener)
EventServiceregisterListener in interface EventServiceserviceName - service nametopic - topic namelistener - listener instancepublic EventRegistration registerListener(String serviceName, String topic, EventFilter filter, Object listener)
EventServiceregisterListener in interface EventServiceserviceName - service nametopic - topic namefilter - event filterlistener - listener instancepublic boolean handleRegistration(Registration reg)
public boolean deregisterListener(String serviceName, String topic, Object id)
EventServicederegisterListener in interface EventServiceserviceName - service nametopic - topic nameid - registration IDEventRegistration.getId(),
EventService.registerListener(String, String, Object),
EventService.registerLocalListener(String, String, Object)public void deregisterAllListeners(String serviceName, String topic)
EventServicederegisterAllListeners in interface EventServiceserviceName - service nametopic - topic namepublic StripedExecutor getEventExecutor()
public EventRegistration[] getRegistrationsAsArray(String serviceName, String topic)
EventServicegetRegistrationsAsArray in interface EventServiceserviceName - service nametopic - topic namepublic Collection<EventRegistration> getRegistrations(String serviceName, String topic)
getRegistrations in interface EventServiceserviceName - service nametopic - topic namepublic boolean hasEventRegistration(String serviceName, String topic)
EventServicehasEventRegistration in interface EventServiceserviceName - service nametopic - topic namepublic void publishEvent(String serviceName, String topic, Object event, int orderKey)
EventServiceorderKey are ordered, otherwise the order is not preserved.
NOTE : The order may not be preserved in case the event needs to be republished (e.g. when the registration is not on this node and the event has to be retransmitted)
publishEvent in interface EventServiceserviceName - service nametopic - topic nameevent - event objectorderKey - the order key for this event. All events with the same order key are ordered.public void publishEvent(String serviceName, EventRegistration registration, Object event, int orderKey)
EventServiceorderKey are ordered, otherwise the order is not preserved.
NOTE : The order may not be preserved in case the event needs to be republished (e.g. when the registration is not on this node and the event has to be retransmitted)
publishEvent in interface EventServiceserviceName - service nameregistration - event registrationevent - event objectorderKey - the order key for this event. All events with the same order key are ordered.public void publishEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey)
EventServiceorderKey are ordered, otherwise the order is not preserved.
NOTE : The order may not be preserved in case the event needs to be republished (e.g. when the registration is not on this node and the event has to be retransmitted)
publishEvent in interface EventServiceserviceName - service nameregistrations - multiple event registrationsevent - event objectorderKey - the order key for this event. All events with the same order key are ordered.public void publishRemoteEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey)
orderKey are ordered, otherwise the order is not preserved.
NOTE : The order may not be preserved in case the event needs to be republished (e.g. when the registration is not on this node and the event has to be retransmitted)
publishRemoteEvent in interface EventServiceserviceName - service nameregistrations - multiple event registrationsevent - event objectorderKey - order keyIllegalArgumentException - if any registration is not an instance of Registrationpublic EventServiceSegment getSegment(String service, boolean forceCreate)
EventServiceSegment for the service. If the segment is null and
forceCreate is true, the segment is created and registered with the MetricsRegistry.service - the service of the segmentforceCreate - whether the segment should be created in case there is no segmentforceCreate is falsepublic void executeEventCallback(Runnable callback)
If callback is an instance of StripedRunnable,
then StripedRunnable.getKey() will be used as order key
to pick event thread.
executeEventCallback in interface EventServicecallback - the callback to execute on a random event threadStripedRunnablepublic void accept(Packet packet)
RemoteEventProcessor. The
processor may determine the thread which will handle the event. If the execution is rejected,
the rejection count is increased and a failure is logged. The event processing is not retried.accept in interface Consumer<Packet>packet - the response packet to handlesendEvent(Address, EventEnvelope, int)public Operation getPreJoinOperation()
PreJoinAwareServicePostJoinAwareService.getPostJoinOperation()s, no partition locks, no key-based locks, no service level
locks, no database interaction are allowed. Additionally, a pre-join operation is executed while the cluster
lock is being held on the joining member, so it is important that the operation finishes quickly and does not
interact with other locks.
The Operation.getPartitionId() method should return a negative value.
This means that the operations should not implement PartitionAwareOperation.
Pre join operations should return response, which may also be a null response.
getPreJoinOperation in interface PreJoinAwareServicenull.public Operation getPostJoinOperation()
PostJoinAwareServiceOperation.getPartitionId() method should return a negative value.
This means that the operations should not implement PartitionAwareOperation.
Post join operations should return response, at least a null response.
getPostJoinOperation in interface PostJoinAwareServicenull.public void shutdown()
public void onMemberLeft(MemberImpl member)
Copyright © 2020 Hazelcast, Inc.. All Rights Reserved.