use of org.apache.ignite.spi.systemview.view.ContinuousQueryView in project ignite by apache.
the class SystemViewSelfTest method checkContinuousQueryView.
/**
*/
private void checkContinuousQueryView(IgniteEx g, SystemView<ContinuousQueryView> qrys, boolean loc) {
assertEquals(1, qrys.size());
for (ContinuousQueryView cq : qrys) {
assertEquals("cache-1", cq.cacheName());
assertEquals(100, cq.bufferSize());
assertEquals(1000, cq.interval());
assertEquals(g.localNode().id(), cq.nodeId());
if (loc)
assertTrue(cq.localListener().startsWith(getClass().getName()));
else
assertNull(cq.localListener());
assertTrue(cq.remoteFilter().startsWith(getClass().getName()));
assertNull(cq.localTransformedListener());
assertNull(cq.remoteTransformer());
}
}
use of org.apache.ignite.spi.systemview.view.ContinuousQueryView in project ignite by apache.
the class GridContinuousProcessor method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
ctx.systemView().registerView(CQ_SYS_VIEW, CQ_SYS_VIEW_DESC, new ContinuousQueryViewWalker(), new ReadOnlyCollectionView2X<>(rmtInfos.entrySet(), locInfos.entrySet()), e -> new ContinuousQueryView(e.getKey(), e.getValue()));
discoProtoVer = ctx.discovery().mutableCustomMessages() ? 1 : 2;
if (discoProtoVer == 2)
routinesInfo = new ContinuousRoutinesInfo();
if (ctx.config().isDaemon())
return;
retryDelay = ctx.config().getNetworkSendRetryDelay();
retryCnt = ctx.config().getNetworkSendRetryCount();
marsh = ctx.config().getMarshaller();
ctx.event().addLocalEventListener(new DiscoveryListener(), EVT_NODE_LEFT, EVT_NODE_FAILED);
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
cancelFutures(new IgniteCheckedException("Topology segmented"));
}
}, EVT_NODE_SEGMENTED);
ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessage.class, new CustomEventListener<StartRoutineDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessage msg) {
assert discoProtoVer == 1 : discoProtoVer;
if (ctx.isStopping())
return;
processStartRequest(snd, msg);
}
});
ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessageV2.class, new CustomEventListener<StartRoutineDiscoveryMessageV2>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessageV2 msg) {
assert discoProtoVer == 2 : discoProtoVer;
if (ctx.isStopping())
return;
processStartRequestV2(topVer, snd, msg);
}
});
ctx.discovery().setCustomEventListener(StartRoutineAckDiscoveryMessage.class, new CustomEventListener<StartRoutineAckDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineAckDiscoveryMessage msg) {
if (ctx.isStopping())
return;
processStartAckRequest(topVer, msg);
}
});
ctx.discovery().setCustomEventListener(StopRoutineDiscoveryMessage.class, new CustomEventListener<StopRoutineDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineDiscoveryMessage msg) {
if (discoProtoVer == 2)
routinesInfo.removeRoutine(msg.routineId);
if (ctx.isStopping())
return;
processStopRequest(snd, msg);
}
});
ctx.discovery().setCustomEventListener(StopRoutineAckDiscoveryMessage.class, new CustomEventListener<StopRoutineAckDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineAckDiscoveryMessage msg) {
if (ctx.isStopping())
return;
processStopAckRequest(msg);
}
});
ctx.io().addMessageListener(TOPIC_CONTINUOUS, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object obj, byte plc) {
if (obj instanceof ContinuousRoutineStartResultMessage)
processRoutineStartResultMessage(nodeId, (ContinuousRoutineStartResultMessage) obj);
else {
GridContinuousMessage msg = (GridContinuousMessage) obj;
if (msg.data() == null && msg.dataBytes() != null) {
try {
msg.data(U.unmarshal(marsh, msg.dataBytes(), U.resolveClassLoader(ctx.config())));
} catch (IgniteCheckedException e) {
U.error(log, "Failed to process message (ignoring): " + msg, e);
return;
}
}
switch(msg.type()) {
case MSG_EVT_NOTIFICATION:
processNotification(nodeId, msg);
break;
case MSG_EVT_ACK:
processMessageAck(msg);
break;
default:
assert false : "Unexpected message received: " + msg.type();
}
}
}
});
ctx.cacheObjects().onContinuousProcessorStarted(ctx);
if (log.isDebugEnabled())
log.debug("Continuous processor started.");
}
use of org.apache.ignite.spi.systemview.view.ContinuousQueryView in project ignite by apache.
the class SystemViewSelfTest method testContinuousQuery.
/**
*/
@Test
public void testContinuousQuery() throws Exception {
try (IgniteEx originNode = startGrid(0);
IgniteEx remoteNode = startGrid(1)) {
IgniteCache<Integer, Integer> cache = originNode.createCache("cache-1");
SystemView<ContinuousQueryView> origQrys = originNode.context().systemView().view(CQ_SYS_VIEW);
SystemView<ContinuousQueryView> remoteQrys = remoteNode.context().systemView().view(CQ_SYS_VIEW);
assertEquals(0, origQrys.size());
assertEquals(0, remoteQrys.size());
try (QueryCursor qry = cache.query(new ContinuousQuery<>().setInitialQuery(new ScanQuery<>()).setPageSize(100).setTimeInterval(1000).setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory(() -> evt -> true))) {
for (int i = 0; i < 100; i++) cache.put(i, i);
checkContinuousQueryView(originNode, origQrys, true);
checkContinuousQueryView(originNode, remoteQrys, false);
}
assertEquals(0, origQrys.size());
assertTrue(waitForCondition(() -> remoteQrys.size() == 0, getTestTimeout()));
}
}
use of org.apache.ignite.spi.systemview.view.ContinuousQueryView in project ignite by apache.
the class CacheContinuousQueryBufferLimitTest method getContinuousQueryPendingBuffer.
/**
* @param ignite Ignite remote instance.
* @param cacheId Cache id.
* @param partId Partition id.
* @return Map of pending entries.
*/
private static ConcurrentMap<Long, CacheContinuousQueryEntry> getContinuousQueryPendingBuffer(IgniteEx ignite, int cacheId, int partId) {
SystemView<ContinuousQueryView> rmtQryView = ignite.context().systemView().view(CQ_SYS_VIEW);
assertEquals(1, rmtQryView.size());
UUID routineId = rmtQryView.iterator().next().routineId();
CacheContinuousQueryHandler<?, ?> hnd = getRemoteContinuousQueryHandler(ignite, routineId);
GridCacheContext<?, ?> cctx = ignite.context().cache().context().cacheContext(cacheId);
CacheContinuousQueryEventBuffer buff = hnd.partitionBuffer(cctx, partId);
return getFieldValue(buff, CacheContinuousQueryEventBuffer.class, "pending");
}
Aggregations