/** {@inheritDoc} */ @Override public long processInLongOutLong(int type, long val) throws IgniteCheckedException { switch (type) { case OP_IS_ENABLED: return events.isEnabled((int)val) ? TRUE : FALSE; case OP_STOP_LOCAL_LISTEN: return events.stopLocalListen(localFilter(val)) ? TRUE : FALSE; } return super.processInLongOutLong(type, val); }
/** * @param ignite Grid to remove listeners from. */ private void removeListeners(Ignite ignite) { if (ignite != null) for (CacheEventListener lsnr : lsnrs) { assert lsnr.latch.getCount() == 0; ignite.events().stopLocalListen(lsnr); } }
/** {@inheritDoc} */ @Override public void close() throws Exception { for (int i = 0; i < NODE_COUNT; i++) grid(i).events().stopLocalListen(pred); } }
/** * @param ignite Grid to remove listeners from. */ private void removeListeners(Ignite ignite) { for (IgnitePredicate<Event> lsnr : lsnrs) ignite.events().stopLocalListen(lsnr); }
/** * @throws Exception Thrown in case of any errors. */ @Test public void testRemoveEventLocalListener() throws Exception { try { ignite.events().stopLocalListen(null); assert false : "Null listener can't be removed."; } catch (NullPointerException ignored) { // No-op. } }
/** * @throws Exception Thrown in case of any errors. */ @Test public void testRemoveDiscoveryListener() throws Exception { try { ignite.events().stopLocalListen(null); assert false : "Null listener can't be removed."; } catch (NullPointerException ignored) { // No-op. } }
/** * Stops listenening. */ private void stopListeners() { for (int i = 0; i < gridCount(); i++) { grid(i).events().stopLocalListen(objReadLsnrs[i]); grid(i).events().stopLocalListen(qryExecLsnrs[i]); } }
/** * @throws Exception In case of error. */ @Test public void testAddRemoveDiscoListener() throws Exception { IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { info("Received local event: " + evt); return true; } }; ignite1.events().localListen(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED); assert ignite1.events().stopLocalListen(lsnr); assert !ignite1.events().stopLocalListen(lsnr); }
g.events().stopLocalListen(lsnr);
/** * @param clients Clients. * @param c Closure to run. * @throws Exception If failed. */ private void reconnectClientNodes(List<Ignite> clients, Callable<Void> c) throws Exception { final CountDownLatch disconnectLatch = new CountDownLatch(clients.size()); final CountDownLatch reconnectLatch = new CountDownLatch(clients.size()); IgnitePredicate<Event> p = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) { log.info("Disconnected: " + evt); disconnectLatch.countDown(); } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) { log.info("Reconnected: " + evt); reconnectLatch.countDown(); } return true; } }; for (Ignite client : clients) client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED); c.call(); ZookeeperDiscoverySpiTestHelper.waitReconnectEvent(log, disconnectLatch); ZookeeperDiscoverySpiTestHelper.waitReconnectEvent(log, reconnectLatch); for (Ignite client : clients) client.events().stopLocalListen(p); }
@Override public boolean apply(Event evt) { assert evt.type() == EVT_NODE_JOINED; info(">>> Node has joined: " + evt.node().id()); joinLatch.countDown(); g0.events().stopLocalListen(this, EVT_NODE_JOINED); return true; } }, EVT_NODE_JOINED);
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { if (lsnr != null) { grid(1).events().stopLocalListen(lsnr, EVTS_IGFS); lsnr = null; } // Clean up file system. if (igfs != null) igfs.clear(); }
@Override public boolean apply(Event evt) { assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED; info(">>> Node has left: " + evt.node().id()); leaveLatch.countDown(); g0.events().stopLocalListen(this, EVT_NODE_LEFT, EVT_NODE_FAILED); return true; } }, EVT_NODE_LEFT, EVT_NODE_FAILED);
/** * Stops temporary nodes. */ private void stopTempNodes() { Collection<Ignite> toRmv = new ArrayList<>(alive.subList(0, TMP_NODES_CNT)); alive.removeAll(toRmv); // Remove listeners to avoid receiving events from stopping nodes. for (Ignite g : toRmv) g.events().stopLocalListen(lsnr, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED); for (Iterator<Ignite> itr = toRmv.iterator(); itr.hasNext(); ) { Ignite g = itr.next(); if (g.cluster().localNode().isClient()) { G.stop(g.name(), false); itr.remove(); } } for (Ignite g : toRmv) { assert !g.cluster().localNode().isClient(); G.stop(g.name(), false); } } }
/** * @throws Exception In case of error. */ @Test public void testAddRemoveGlobalListener() throws Exception { IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { info("Received local event: " + evt); return true; } }; ignite1.events().localListen(lsnr, EVTS_ALL_MINUS_METRIC_UPDATE); assert ignite1.events().stopLocalListen(lsnr); }
/** */ private List<List<?>> runQueryEnsureBroadcast(IgniteCache<?, ?> cache, SqlFieldsQuery qry) throws Exception { final CountDownLatch execLatch = new CountDownLatch(NODE_COUNT); final IgnitePredicate<Event> pred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryExecutedEvent; CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent)evt; assertNotNull(qe.clause()); execLatch.countDown(); return true; } }; for (int i = 0; i < NODE_COUNT; i++) grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED); List<List<?>> result = cache.query(qry).getAll(); assertTrue(execLatch.await(5000, MILLISECONDS)); for (int i = 0; i < NODE_COUNT; i++) grid(i).events().stopLocalListen(pred); return result; }
/** * @throws Exception In case of error. */ @Test public void testGridInternalEvents() throws Exception { IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { checkGridInternalEvent(evt); return true; } }; ignite1.events().localListen(lsnr, EVTS_TASK_EXECUTION); ignite1.events().localListen(lsnr, EVTS_JOB_EXECUTION); ignite2.events().localListen(lsnr, EVTS_TASK_EXECUTION); ignite2.events().localListen(lsnr, EVTS_JOB_EXECUTION); executeGridInternalTask(ignite1); Collection<Event> evts1 = ignite1.events().localQuery(F.<Event>alwaysTrue()); Collection<Event> evts2 = ignite2.events().localQuery(F.<Event>alwaysTrue()); assert evts1 != null; assert evts2 != null; for (Event evt : evts1) checkGridInternalEvent(evt); for (Event evt : evts2) checkGridInternalEvent(evt); assert ignite1.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION); assert ignite1.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION); assert ignite2.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION); assert ignite2.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION); }
/** * * @throws Exception In case of error. */ @Test public void testPutWithExpiration() throws Exception { MvccFeatureChecker.failIfNotSupported(MvccFeatureChecker.Feature.ENTRY_LOCK); MvccFeatureChecker.failIfNotSupported(MvccFeatureChecker.Feature.EXPIRATION); MvccFeatureChecker.failIfNotSupported(MvccFeatureChecker.Feature.CACHE_EVENTS); IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME); CacheEventListener lsnr = new CacheEventListener(new CountDownLatch(1)); ignite.events().localListen(lsnr, EVTS_CACHE); ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, 200L)); try { int key = (int)System.currentTimeMillis(); cache.withExpiryPolicy(expiry).put(key, "val"); assert cache.get(key) != null; cache.withExpiryPolicy(expiry).put(key, "val"); Thread.sleep(500); assert cache.get(key) == null; } finally { ignite.events().stopLocalListen(lsnr, EVTS_CACHE); } }
/** * * @throws Exception if failed. */ @Test public void testEvents() throws Exception { final CountDownLatch latch = new CountDownLatch(NODE_COUNT); final IgnitePredicate<Event> pred = new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof CacheQueryExecutedEvent; CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent)evt; assertNotNull(qe.clause()); latch.countDown(); return true; } }; for (int idx = 0; idx < NODE_COUNT; idx++) grid(idx).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED); IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).cache(CACHE_ORG); for (int i = 0; i < 1024; i++) cache.put(i, new Organization("Acme Inc #" + i, 0)); cache.query(new SqlFieldsQueryEx("UPDATE \"org\".Organization o SET name = UPPER(name)", false) .setSkipReducerOnUpdate(true)).getAll(); assertTrue(latch.await(5000, MILLISECONDS)); for (int idx = 0; idx < NODE_COUNT; idx++) grid(idx).events().stopLocalListen(pred); }
/** * @throws Exception In case of error. */ private void performTaskExecutionTest() throws Exception { Ignite g = grid(0); JobFinishLock jobFinishLock = new JobFinishLock(); MetricsUpdateLock metricsUpdLock = new MetricsUpdateLock(); try { for (Ignite g0 : G.allGrids()) g0.events().localListen(jobFinishLock, EVT_JOB_FINISHED); g.compute().execute(new GridTestTask(), "testArg"); // Wait until all nodes fire JOB FINISH event. jobFinishLock.await(); g.events().localListen(metricsUpdLock, EVT_NODE_METRICS_UPDATED); // Wait until local node will have updated metrics. metricsUpdLock.await(); ClusterMetrics m = g.cluster().metrics(); checkMetrics(m); } finally { for (Ignite g0 : G.allGrids()) g0.events().stopLocalListen(jobFinishLock); g.events().stopLocalListen(metricsUpdLock); } }