public interface IgniteEvents extends IgniteAsyncSupport
clusterGroup()
.
There are 2
ways to subscribe to event listening, local
and remote
.
Instance of IgniteEvents
is obtained from Ignite
as 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...)
or disableLocal(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>
Modifier and Type | Method and Description |
---|---|
ClusterGroup |
clusterGroup()
Gets cluster group to which this
IgniteEvents instance belongs. |
void |
disableLocal(int... types)
Disables provided events.
|
int[] |
enabledEvents()
Gets types of enabled events.
|
void |
enableLocal(int... types)
Enables provided events.
|
boolean |
isEnabled(int type)
Check if event is enabled.
|
void |
localListen(IgnitePredicate<? extends Event> lsnr,
int... types)
Adds an event listener for local events.
|
<T extends Event> |
localQuery(IgnitePredicate<T> p,
int... types)
Queries local node for events using passed-in predicate filter for event selection.
|
void |
recordLocal(Event evt)
Records customer user generated event.
|
<T extends Event> |
remoteListen(IgniteBiPredicate<UUID,T> locLsnr,
IgnitePredicate<T> rmtFilter,
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> |
remoteListen(int bufSize,
long interval,
boolean autoUnsubscribe,
IgniteBiPredicate<UUID,T> locLsnr,
IgnitePredicate<T> rmtFilter,
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> |
remoteListenAsync(IgniteBiPredicate<UUID,T> locLsnr,
IgnitePredicate<T> rmtFilter,
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> |
remoteListenAsync(int bufSize,
long interval,
boolean autoUnsubscribe,
IgniteBiPredicate<UUID,T> locLsnr,
IgnitePredicate<T> rmtFilter,
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> |
remoteQuery(IgnitePredicate<T> p,
long timeout,
int... types)
Queries nodes in this cluster group for events using passed in predicate filter for event
selection.
|
<T extends Event> |
remoteQueryAsync(IgnitePredicate<T> p,
long timeout,
int... types)
Asynchronously queries nodes in this cluster group for events using passed in predicate filter for event
selection.
|
boolean |
stopLocalListen(IgnitePredicate<? extends Event> lsnr,
int... types)
Removes local event listener.
|
void |
stopRemoteListen(UUID opId)
Stops listening to remote events.
|
IgniteFuture<Void> |
stopRemoteListenAsync(UUID opId)
Asynchronously stops listening to remote events.
|
<T extends Event> |
waitForLocal(IgnitePredicate<T> filter,
int... types)
Waits for the specified events.
|
<T extends Event> |
waitForLocalAsync(IgnitePredicate<T> filter,
int... types)
Create future to wait for the specified events.
|
IgniteEvents |
withAsync()
Deprecated.
|
future, isAsync
ClusterGroup clusterGroup()
IgniteEvents
instance belongs.IgniteEvents
instance belongs.<T extends Event> List<T> remoteQuery(IgnitePredicate<T> p, long timeout, int... types) throws IgniteException
p
- Predicate filter used to query events on remote nodes.timeout
- Maximum time to wait for result, 0
to wait forever.types
- Event types to be queried. If not provided, all events will be passed to the filter.IgniteException
- If query failed.<T extends Event> IgniteFuture<List<T>> remoteQueryAsync(IgnitePredicate<T> p, long timeout, int... types) throws IgniteException
p
- Predicate filter used to query events on remote nodes.timeout
- Maximum time to wait for result, 0
to wait forever.types
- Event types to be queried. If not provided, all events will be passed to the filter.IgniteException
- If query failed.<T extends Event> UUID remoteListen(IgniteBiPredicate<UUID,T> locLsnr, IgnitePredicate<T> rmtFilter, int... types) throws IgniteException
The listener can be unsubscribed automatically if local node stops, if locLsnr
callback
returns false
or if stopRemoteListen(UUID)
or stopRemoteListenAsync(UUID)
are called.
T
- Type of the event.locLsnr
- Listener callback that is called on local node. If null
, this events will be handled
on remote nodes by passed in rmtFilter
.rmtFilter
- Filter callback that is called on remote node. Only events that pass the remote filter
will be sent to local node. If null
, 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 returns false
.types
- Types of events to listen for. If not provided, all events that pass the
provided remote filter will be sent to local node.Operation ID
that can be passed to stopRemoteListen(UUID)
or
stopRemoteListenAsync(UUID)
methods to stop listening.IgniteException
- If failed to add listener.<T extends Event> IgniteFuture<UUID> remoteListenAsync(IgniteBiPredicate<UUID,T> locLsnr, IgnitePredicate<T> rmtFilter, int... types) throws IgniteException
The listener can be unsubscribed automatically if local node stops, if locLsnr
callback
returns false
or if stopRemoteListen(UUID)
or stopRemoteListenAsync(UUID)
are called.
T
- Type of the event.locLsnr
- Listener callback that is called on local node. If null
, this events will be handled
on remote nodes by passed in rmtFilter
.rmtFilter
- Filter callback that is called on remote node. Only events that pass the remote filter
will be sent to local node. If null
, 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 returns false
.types
- Types of events to listen for. If not provided, all events that pass the
provided remote filter will be sent to local node.Operation ID
that can be passed to stopRemoteListen(UUID)
or
stopRemoteListenAsync(UUID)
methods to stop listening.IgniteException
- If failed to add listener.<T extends Event> UUID remoteListen(int bufSize, long interval, boolean autoUnsubscribe, IgniteBiPredicate<UUID,T> locLsnr, IgnitePredicate<T> rmtFilter, int... types) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
T
- Type of the event.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 is false
, listeners will be unregistered only when
stopRemoteListen(UUID)
method is called, or the 'callback (locLsnr)'
passed in returns false
.locLsnr
- Callback that is called on local node. If this predicate returns true
,
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. If null
, this events will be handled on remote nodes by
passed in rmtFilter
until local node stops (if 'autoUnsubscribe'
is true
)
or until stopRemoteListen(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. If null
, 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 returns false
.types
- Types of events to listen for. If not provided, all events that pass the
provided remote filter will be sent to local node.Operation ID
that can be passed to stopRemoteListen(UUID)
or
stopRemoteListen(UUID)
methods to stop listening.IgniteException
- If failed to add listener.stopRemoteListen(UUID)
,
stopRemoteListenAsync(UUID)
<T extends Event> IgniteFuture<UUID> remoteListenAsync(int bufSize, long interval, boolean autoUnsubscribe, IgniteBiPredicate<UUID,T> locLsnr, IgnitePredicate<T> rmtFilter, int... types) throws IgniteException
T
- Type of the event.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 is false
, listeners will be unregistered only when
stopRemoteListen(UUID)
method is called, or the 'callback (locLsnr)'
passed in returns false
.locLsnr
- Callback that is called on local node. If this predicate returns true
,
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. If null
, this events will be handled on remote nodes by
passed in rmtFilter
until local node stops (if 'autoUnsubscribe'
is true
)
or until stopRemoteListen(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. If null
, 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 returns false
.types
- Types of events to listen for. If not provided, all events that pass the
provided remote filter will be sent to local node.Operation ID
that can be passed to stopRemoteListen(UUID)
or stopRemoteListen(UUID)
methods to stop listening.IgniteException
- If failed to add listener.stopRemoteListen(UUID)
,
stopRemoteListenAsync(UUID)
void stopRemoteListen(UUID opId) throws IgniteException
clusterGroup()
.
Supports asynchronous execution (see IgniteAsyncSupport
).
opId
- Operation ID that was returned from
remoteListen(IgniteBiPredicate, IgnitePredicate, int...)
method.IgniteException
- If failed to stop listeners.remoteListen(IgniteBiPredicate, IgnitePredicate, int...)
,
remoteListenAsync(int, long, boolean, IgniteBiPredicate, IgnitePredicate, int...)
IgniteFuture<Void> stopRemoteListenAsync(UUID opId) throws IgniteException
clusterGroup()
.opId
- Operation ID that was returned from
remoteListen(IgniteBiPredicate, IgnitePredicate, int...)
method.IgniteException
- If failed to stop listeners.remoteListen(IgniteBiPredicate, IgnitePredicate, int...)
,
remoteListenAsync(int, long, boolean, IgniteBiPredicate, IgnitePredicate, int...)
<T extends Event> T waitForLocal(IgnitePredicate<T> filter, int... types) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
filter
- Optional filtering predicate. Only if predicates evaluates to true
will the event
end the wait.types
- Types of the events to wait for. If not provided, all events will be passed to the filter.IgniteException
- If wait was interrupted.<T extends Event> IgniteFuture<T> waitForLocalAsync(IgnitePredicate<T> filter, int... types) throws IgniteException
filter
- Optional filtering predicate. Only if predicates evaluates to true
will the event
end the wait.types
- Types of the events to wait for. If not provided, all events will be passed to the filter.IgniteException
- If wait was interrupted.<T extends Event> Collection<T> localQuery(IgnitePredicate<T> p, int... types)
p
- Predicate to filter events. All predicates must be satisfied for the
event to be returned.types
- Event types to be queried. If not provided, all events will be passed to the predicate.void recordLocal(Event evt)
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 IllegalArgumentException
to be thrown.
evt
- Locally generated event.IllegalArgumentException
- If event type is within Ignite reserved range between 1
and
1000
.void localListen(IgnitePredicate<? extends Event> lsnr, int... types)
lsnr
- Predicate that is called on each received event. If predicate returns false
,
it will be unregistered and will stop receiving events.types
- Event types for which this listener will be notified.IllegalArgumentException
- Thrown in case when passed in array of event types is empty.boolean stopLocalListen(IgnitePredicate<? extends Event> lsnr, int... types)
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.true
if listener was removed, false
otherwise.void enableLocal(int... types)
types
- Events to enable.void disableLocal(int... types)
types
- Events to disable.int[] enabledEvents()
boolean isEnabled(int type)
type
- Event type.True
if event of passed in type is enabled.@Deprecated IgniteEvents withAsync()
withAsync
in interface IgniteAsyncSupport
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024