use of org.apache.ignite.internal.processors.platform.PlatformEventFilterListener in project ignite by apache.
the class GridEventConsumeHandler method register.
/** {@inheritDoc} */
@Override
public RegisterStatus register(final UUID nodeId, final UUID routineId, final GridKernalContext ctx) throws IgniteCheckedException {
assert nodeId != null;
assert routineId != null;
assert ctx != null;
if (cb != null)
ctx.resource().injectGeneric(cb);
if (filter != null)
ctx.resource().injectGeneric(filter);
if (filter instanceof PlatformEventFilterListener)
((PlatformEventFilterListener) filter).initialize(ctx);
final boolean loc = nodeId.equals(ctx.localNodeId());
lsnr = new GridLocalEventListener() {
/** node ID, routine ID, event */
private final Queue<T3<UUID, UUID, Event>> notificationQueue = new LinkedList<>();
private boolean notificationInProgress;
@Override
public void onEvent(Event evt) {
if (filter != null && !filter.apply(evt))
return;
if (loc) {
if (!cb.apply(nodeId, evt))
ctx.continuous().stopRoutine(routineId);
} else {
if (ctx.discovery().node(nodeId) == null)
return;
synchronized (notificationQueue) {
notificationQueue.add(new T3<>(nodeId, routineId, evt));
if (!notificationInProgress) {
ctx.getSystemExecutorService().execute(new Runnable() {
@Override
public void run() {
if (!ctx.continuous().lockStopping())
return;
try {
while (true) {
T3<UUID, UUID, Event> t3;
synchronized (notificationQueue) {
t3 = notificationQueue.poll();
if (t3 == null) {
notificationInProgress = false;
return;
}
}
try {
Event evt = t3.get3();
EventWrapper wrapper = new EventWrapper(evt);
if (evt instanceof CacheEvent) {
String cacheName = ((CacheEvent) evt).cacheName();
ClusterNode node = ctx.discovery().node(t3.get1());
if (node == null)
continue;
if (ctx.config().isPeerClassLoadingEnabled()) {
GridCacheContext cctx = ctx.cache().internalCache(cacheName).context();
if (cctx.deploymentEnabled() && ctx.discovery().cacheNode(node, cacheName)) {
wrapper.p2pMarshal(ctx.config().getMarshaller());
wrapper.cacheName = cacheName;
cctx.deploy().prepare(wrapper);
}
}
}
ctx.continuous().addNotification(t3.get1(), t3.get2(), wrapper, null, false, false);
} catch (ClusterTopologyCheckedException ignored) {
// No-op.
} catch (Throwable e) {
U.error(ctx.log(GridEventConsumeHandler.class), "Failed to send event notification to node: " + nodeId, e);
}
}
} finally {
ctx.continuous().unlockStopping();
}
}
});
notificationInProgress = true;
}
}
}
}
};
if (F.isEmpty(types))
types = EVTS_ALL;
ctx.event().addLocalEventListener(lsnr, types);
return RegisterStatus.REGISTERED;
}
use of org.apache.ignite.internal.processors.platform.PlatformEventFilterListener in project ignite by apache.
the class PlatformEvents method startRemoteQueryAsync.
/**
* Starts the remote query asynchronously.
*
* @param reader Reader.
* @param events Events.
* @return Result.
*/
private IgniteFuture<List<Event>> startRemoteQueryAsync(BinaryRawReaderEx reader, IgniteEvents events) {
Object pred = reader.readObjectDetached();
long timeout = reader.readLong();
int[] types = readEventTypes(reader);
PlatformEventFilterListener filter = platformCtx.createRemoteEventFilter(pred, types);
return events.remoteQueryAsync(filter, timeout);
}
use of org.apache.ignite.internal.processors.platform.PlatformEventFilterListener in project ignite by apache.
the class GridEventStorageManager method localEvents.
/**
* @param p Grid event predicate.
* @return Collection of grid events.
*/
@SuppressWarnings("unchecked")
public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p) throws IgniteCheckedException {
assert p != null;
if (getSpi() instanceof NoopEventStorageSpi) {
throw new IgniteCheckedException("Failed to query events because default no-op event storage SPI is used. " + "Consider configuring " + MemoryEventStorageSpi.class.getSimpleName() + " or another " + EventStorageSpi.class.getSimpleName() + " implementation via " + "IgniteConfiguration.setEventStorageSpi() configuration property.");
}
if (p instanceof PlatformEventFilterListener) {
PlatformEventFilterListener p0 = (PlatformEventFilterListener) p;
p0.initialize(ctx);
try {
return (Collection<T>) getSpi().localEvents(p0);
} finally {
p0.onClose();
}
} else
return getSpi().localEvents(p);
}
use of org.apache.ignite.internal.processors.platform.PlatformEventFilterListener in project ignite by apache.
the class PlatformEvents method startRemoteQuery.
/**
* Starts the remote query.
*
* @param reader Reader.
* @param events Events.
* @return Result.
*/
private Collection<Event> startRemoteQuery(BinaryRawReaderEx reader, IgniteEvents events) {
Object pred = reader.readObjectDetached();
long timeout = reader.readLong();
int[] types = readEventTypes(reader);
PlatformEventFilterListener filter = platformCtx.createRemoteEventFilter(pred, types);
return events.remoteQuery(filter, timeout);
}
Aggregations