Interface IgniteEvents
-
- All Superinterfaces:
IgniteAsyncSupport
public interface IgniteEvents extends IgniteAsyncSupport
Provides functionality for local and remote event notifications on nodes defined byclusterGroup(). There are2ways to subscribe to event listening,localandremote.Instance of
IgniteEventsis obtained fromIgniteas follows:Ignite ignite = Ignition.ignite(); IgniteEvents evts = ignite.events();
You can also obtain an instance of the events facade over a specific cluster group:// Cluster group over remote nodes (excluding the local node). ClusterGroup remoteNodes = ignite.cluster().forRemotes(); // Events instance spanning all remote cluster nodes. IgniteEvents evts = ignite.events(remoteNodes);
Local subscription, defined by
localListen(IgnitePredicate, int...)method, will add a listener for specified events on local node only. This listener will be notified whenever any of subscribed events happen on local node regardless of whether local node belongs to underlying cluster group or not.Remote subscription, defined by
remoteListen(IgniteBiPredicate, IgnitePredicate, int...), will add an event listener for specified events on all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well). All cluster group nodes will then be notified of the subscribed events. If the events pass the remote event filter, the events will be sent to local node for local listener notification.Note that by default, all events in Ignite are disabled for performance reasons. You must only enable events that you need within your logic. You can enable/disable events either by calling
enableLocal(int...)ordisableLocal(int...)methods, or from XML configuration. For example, you can enable all cache events as follows:<property name="includeEventTypes"> <util:constant static-field="org.apache.ignite.events.IgniteEventType.EVTS_CACHE"/> </property>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description ClusterGroupclusterGroup()Gets cluster group to which thisIgniteEventsinstance belongs.voiddisableLocal(int... types)Disables provided events.int[]enabledEvents()Gets types of enabled events.voidenableLocal(int... types)Enables provided events.booleanisEnabled(int type)Check if event is enabled.voidlocalListen(IgnitePredicate<? extends Event> lsnr, int... types)Adds an event listener for local events.<T extends Event>
Collection<T>localQuery(IgnitePredicate<T> p, @org.jetbrains.annotations.Nullable int... types)Queries local node for events using passed-in predicate filter for event selection.voidrecordLocal(Event evt)Records customer user generated event.<T extends Event>
UUIDremoteListen(int bufSize, long interval, boolean autoUnsubscribe, @Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable IgnitePredicate<T> rmtFilter, @org.jetbrains.annotations.Nullable int... types)Adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well).<T extends Event>
UUIDremoteListen(@Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable IgnitePredicate<T> rmtFilter, @org.jetbrains.annotations.Nullable int... types)Adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well).<T extends Event>
IgniteFuture<UUID>remoteListenAsync(int bufSize, long interval, boolean autoUnsubscribe, @Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable IgnitePredicate<T> rmtFilter, @org.jetbrains.annotations.Nullable int... types)Asynchronously adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well).<T extends Event>
IgniteFuture<UUID>remoteListenAsync(@Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable IgnitePredicate<T> rmtFilter, @org.jetbrains.annotations.Nullable int... types)Asynchronously adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well).<T extends Event>
List<T>remoteQuery(IgnitePredicate<T> p, long timeout, @org.jetbrains.annotations.Nullable int... types)Queries nodes in this cluster group for events using passed in predicate filter for event selection.<T extends Event>
IgniteFuture<List<T>>remoteQueryAsync(IgnitePredicate<T> p, long timeout, @org.jetbrains.annotations.Nullable int... types)Asynchronously queries nodes in this cluster group for events using passed in predicate filter for event selection.booleanstopLocalListen(IgnitePredicate<? extends Event> lsnr, @org.jetbrains.annotations.Nullable int... types)Removes local event listener.voidstopRemoteListen(UUID opId)Stops listening to remote events.IgniteFuture<Void>stopRemoteListenAsync(UUID opId)Asynchronously stops listening to remote events.<T extends Event>
TwaitForLocal(@Nullable IgnitePredicate<T> filter, @org.jetbrains.annotations.Nullable int... types)Waits for the specified events.<T extends Event>
IgniteFuture<T>waitForLocalAsync(@Nullable IgnitePredicate<T> filter, @org.jetbrains.annotations.Nullable int... types)Create future to wait for the specified events.IgniteEventswithAsync()Deprecated.-
Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport
future, isAsync
-
-
-
-
Method Detail
-
clusterGroup
ClusterGroup clusterGroup()
Gets cluster group to which thisIgniteEventsinstance belongs.- Returns:
- Cluster group to which this
IgniteEventsinstance belongs.
-
remoteQuery
@IgniteAsyncSupported <T extends Event> List<T> remoteQuery(IgnitePredicate<T> p, long timeout, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Queries nodes in this cluster group for events using passed in predicate filter for event selection.- Type Parameters:
T- Type of the result events.- Parameters:
p- Predicate filter used to query events on remote nodes.timeout- Maximum time to wait for result,0to wait forever.types- Event types to be queried.- Returns:
- Collection of grid events returned from specified nodes.
- Throws:
IgniteException- If query failed.
-
remoteQueryAsync
<T extends Event> IgniteFuture<List<T>> remoteQueryAsync(IgnitePredicate<T> p, long timeout, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Asynchronously queries nodes in this cluster group for events using passed in predicate filter for event selection.- Type Parameters:
T- Type of the result events.- Parameters:
p- Predicate filter used to query events on remote nodes.timeout- Maximum time to wait for result,0to wait forever.types- Event types to be queried.- Returns:
- a Future representing pending completion of the query. The completed future contains collection of grid events returned from specified nodes.
- Throws:
IgniteException- If query failed.
-
remoteListen
@IgniteAsyncSupported <T extends Event> UUID remoteListen(@Nullable @Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable @Nullable IgnitePredicate<T> rmtFilter, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well). This means that all events occurring on any node within this cluster group that pass remote filter will be sent to local node for local listener notifications.The listener can be unsubscribed automatically if local node stops, if
locLsnrcallback returnsfalseor ifstopRemoteListen(UUID)orstopRemoteListenAsync(UUID)are called.- Type Parameters:
T- Type of the event.- Parameters:
locLsnr- Listener callback that is called on local node. Ifnull, this events will be handled on remote nodes by passed inrmtFilter.rmtFilter- Filter callback that is called on remote node. Only events that pass the remote filter will be sent to local node. Ifnull, all events of specified types will be sent to local node. This remote filter can be used to pre-handle events remotely, before they are passed in to local callback. It will be auto-unsubsribed on the node where event occurred in case if it returnsfalse.types- Types of events to listen for. If not provided, all events that pass the provided remote filter will be sent to local node.- Returns:
Operation IDthat can be passed tostopRemoteListen(UUID)orstopRemoteListenAsync(UUID)methods to stop listening.- Throws:
IgniteException- If failed to add listener.
-
remoteListenAsync
<T extends Event> IgniteFuture<UUID> remoteListenAsync(@Nullable @Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable @Nullable IgnitePredicate<T> rmtFilter, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Asynchronously adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well). This means that all events occurring on any node within this cluster group that pass remote filter will be sent to local node for local listener notifications.The listener can be unsubscribed automatically if local node stops, if
locLsnrcallback returnsfalseor ifstopRemoteListen(UUID)orstopRemoteListenAsync(UUID)are called.- Type Parameters:
T- Type of the event.- Parameters:
locLsnr- Listener callback that is called on local node. Ifnull, this events will be handled on remote nodes by passed inrmtFilter.rmtFilter- Filter callback that is called on remote node. Only events that pass the remote filter will be sent to local node. Ifnull, all events of specified types will be sent to local node. This remote filter can be used to pre-handle events remotely, before they are passed in to local callback. It will be auto-unsubsribed on the node where event occurred in case if it returnsfalse.types- Types of events to listen for. If not provided, all events that pass the provided remote filter will be sent to local node.- Returns:
- a Future representing pending completion of the operation. The completed future contains
Operation IDthat can be passed tostopRemoteListen(UUID)orstopRemoteListenAsync(UUID)methods to stop listening. - Throws:
IgniteException- If failed to add listener.
-
remoteListen
@IgniteAsyncSupported <T extends Event> UUID remoteListen(int bufSize, long interval, boolean autoUnsubscribe, @Nullable @Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable @Nullable IgnitePredicate<T> rmtFilter, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well). This means that all events occurring on any node within this cluster group that pass remote filter will be sent to local node for local listener notification.Supports asynchronous execution (see
IgniteAsyncSupport).- Type Parameters:
T- Type of the event.- Parameters:
bufSize- Remote events buffer size. Events from remote nodes won't be sent until buffer is full or time interval is exceeded.interval- Maximum time interval after which events from remote node will be sent. Events from remote nodes won't be sent until buffer is full or time interval is exceeded.autoUnsubscribe- Flag indicating that event listeners on remote nodes should be automatically unregistered if master node (node that initiated event listening) leaves topology. If this flag isfalse, listeners will be unregistered only whenstopRemoteListen(UUID)method is called, or the'callback (locLsnr)'passed in returnsfalse.locLsnr- Callback that is called on local node. If this predicate returnstrue, the implementation will continue listening to events. Otherwise, events listening will be stopped and listeners will be unregistered on all nodes in the cluster group. Ifnull, this events will be handled on remote nodes by passed inrmtFilteruntil local node stops (if'autoUnsubscribe'istrue) or untilstopRemoteListen(UUID)is called.rmtFilter- Filter callback that is called on remote node. Only events that pass the remote filter will be sent to local node. Ifnull, all events of specified types will be sent to local node. This remote filter can be used to pre-handle events remotely, before they are passed in to local callback. It will be auto-unsubsribed on the node where event occurred in case if it returnsfalse.types- Types of events to listen for. If not provided, all events that pass the provided remote filter will be sent to local node.- Returns:
Operation IDthat can be passed tostopRemoteListen(UUID)orstopRemoteListen(UUID)methods to stop listening.- Throws:
IgniteException- If failed to add listener.- See Also:
stopRemoteListen(UUID),stopRemoteListenAsync(UUID)
-
remoteListenAsync
<T extends Event> IgniteFuture<UUID> remoteListenAsync(int bufSize, long interval, boolean autoUnsubscribe, @Nullable @Nullable IgniteBiPredicate<UUID,T> locLsnr, @Nullable @Nullable IgnitePredicate<T> rmtFilter, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Asynchronously adds event listener for specified events to all nodes in the cluster group (possibly including local node if it belongs to the cluster group as well). This means that all events occurring on any node within this cluster group that pass remote filter will be sent to local node for local listener notification.- Type Parameters:
T- Type of the event.- Parameters:
bufSize- Remote events buffer size. Events from remote nodes won't be sent until buffer is full or time interval is exceeded.interval- Maximum time interval after which events from remote node will be sent. Events from remote nodes won't be sent until buffer is full or time interval is exceeded.autoUnsubscribe- Flag indicating that event listeners on remote nodes should be automatically unregistered if master node (node that initiated event listening) leaves topology. If this flag isfalse, listeners will be unregistered only whenstopRemoteListen(UUID)method is called, or the'callback (locLsnr)'passed in returnsfalse.locLsnr- Callback that is called on local node. If this predicate returnstrue, the implementation will continue listening to events. Otherwise, events listening will be stopped and listeners will be unregistered on all nodes in the cluster group. Ifnull, this events will be handled on remote nodes by passed inrmtFilteruntil local node stops (if'autoUnsubscribe'istrue) or untilstopRemoteListen(UUID)is called.rmtFilter- Filter callback that is called on remote node. Only events that pass the remote filter will be sent to local node. Ifnull, all events of specified types will be sent to local node. This remote filter can be used to pre-handle events remotely, before they are passed in to local callback. It will be auto-unsubsribed on the node where event occurred in case if it returnsfalse.types- Types of events to listen for. If not provided, all events that pass the provided remote filter will be sent to local node.- Returns:
- a Future representing pending completion of the operation. The completed future contains
Operation IDthat can be passed tostopRemoteListen(UUID)orstopRemoteListen(UUID)methods to stop listening. - Throws:
IgniteException- If failed to add listener.- See Also:
stopRemoteListen(UUID),stopRemoteListenAsync(UUID)
-
stopRemoteListen
@IgniteAsyncSupported void stopRemoteListen(UUID opId) throws IgniteException
Stops listening to remote events. This will unregister all listeners identified with provided operation ID on all nodes defined byclusterGroup().Supports asynchronous execution (see
IgniteAsyncSupport).- Parameters:
opId- Operation ID that was returned fromremoteListen(IgniteBiPredicate, IgnitePredicate, int...)method.- Throws:
IgniteException- If failed to stop listeners.- See Also:
remoteListen(IgniteBiPredicate, IgnitePredicate, int...),remoteListenAsync(int, long, boolean, IgniteBiPredicate, IgnitePredicate, int...)
-
stopRemoteListenAsync
IgniteFuture<Void> stopRemoteListenAsync(UUID opId) throws IgniteException
Asynchronously stops listening to remote events. This will unregister all listeners identified with provided operation ID on all nodes defined byclusterGroup().- Parameters:
opId- Operation ID that was returned fromremoteListen(IgniteBiPredicate, IgnitePredicate, int...)method.- Returns:
- a Future representing pending completion of the operation.
- Throws:
IgniteException- If failed to stop listeners.- See Also:
remoteListen(IgniteBiPredicate, IgnitePredicate, int...),remoteListenAsync(int, long, boolean, IgniteBiPredicate, IgnitePredicate, int...)
-
waitForLocal
@IgniteAsyncSupported <T extends Event> T waitForLocal(@Nullable @Nullable IgnitePredicate<T> filter, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Waits for the specified events.Supports asynchronous execution (see
IgniteAsyncSupport).- Type Parameters:
T- Type of the result event instance.- Parameters:
filter- Optional filtering predicate. Only if predicates evaluates totruewill the event end the wait.types- Types of the events to wait for. If not provided, all events will be passed to the filter.- Returns:
- Grid event.
- Throws:
IgniteException- If wait was interrupted.
-
waitForLocalAsync
<T extends Event> IgniteFuture<T> waitForLocalAsync(@Nullable @Nullable IgnitePredicate<T> filter, @Nullable @org.jetbrains.annotations.Nullable int... types) throws IgniteException
Create future to wait for the specified events.- Type Parameters:
T- type of the result event instance.- Parameters:
filter- Optional filtering predicate. Only if predicates evaluates totruewill the event end the wait.types- Types of the events to wait for. If not provided, all events will be passed to the filter.- Returns:
- a Future representing pending completion of the operation. The completed future contains grid event.
- Throws:
IgniteException- If wait was interrupted.
-
localQuery
<T extends Event> Collection<T> localQuery(IgnitePredicate<T> p, @Nullable @org.jetbrains.annotations.Nullable int... types)
Queries local node for events using passed-in predicate filter for event selection.- Type Parameters:
T- Type of the result events.- Parameters:
p- Predicate to filter events. All predicates must be satisfied for the event to be returned.types- Event types to be queried.- Returns:
- Collection of grid events found on local node.
-
recordLocal
void recordLocal(Event evt)
Records customer user generated event. All registered local listeners will be notified.NOTE: all types in range from 1 to 1000 are reserved for internal Ignite events and should not be used by user-defined events. Attempt to record internal event with this method will cause
IllegalArgumentExceptionto be thrown.- Parameters:
evt- Locally generated event.- Throws:
IllegalArgumentException- If event type is within Ignite reserved range between1and1000.
-
localListen
void localListen(IgnitePredicate<? extends Event> lsnr, int... types)
Adds an event listener for local events. Note that listener will be added regardless of whether local node is in this cluster group or not.- Parameters:
lsnr- Predicate that is called on each received event. If predicate returnsfalse, it will be unregistered and will stop receiving events.types- Event types for which this listener will be notified.- Throws:
IllegalArgumentException- Thrown in case when passed in array of event types is empty.
-
stopLocalListen
boolean stopLocalListen(IgnitePredicate<? extends Event> lsnr, @Nullable @org.jetbrains.annotations.Nullable int... types)
Removes local event listener.- Parameters:
lsnr- Local event listener to remove.types- Types of events for which to remove listener. If not specified, then listener will be removed for all types it was registered for.- Returns:
trueif listener was removed,falseotherwise.
-
enableLocal
void enableLocal(int... types)
Enables provided events. Allows to start recording events that were disabled before. Note that specified events will be enabled regardless of whether local node is in this cluster group or not.- Parameters:
types- Events to enable.
-
disableLocal
void disableLocal(int... types)
Disables provided events. Allows to stop recording events that were enabled before. Note that specified events will be disabled regardless of whether local node is in this cluster group or not.- Parameters:
types- Events to disable.
-
enabledEvents
int[] enabledEvents()
Gets types of enabled events.- Returns:
- Types of enabled events.
-
isEnabled
boolean isEnabled(int type)
Check if event is enabled.- Parameters:
type- Event type.- Returns:
Trueif event of passed in type is enabled.
-
withAsync
@Deprecated IgniteEvents withAsync()
Deprecated.Gets instance of this component with asynchronous mode enabled.- Specified by:
withAsyncin interfaceIgniteAsyncSupport- Returns:
- Instance of this component with asynchronous mode enabled.
-
-