/** */ private EventCounter(int cnt) { this.cnt = new AtomicInteger(cnt); this.execLatch = new CountDownLatch(NODE_COUNT); for (int i = 0; i < NODE_COUNT; i++) grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED); }
/** * * @param ignite Grid. * @param lsnr Listener. * @param type Event types. */ private void addListener(Ignite ignite, CacheEventListener lsnr, int... type) { if (!lsnrs.contains(lsnr)) lsnrs.add(lsnr); ignite.events().localListen(lsnr, type.length == 0 ? EVTS_CACHE : type); }
/** * @param ignite Grid * @param lsnr Listener. */ void addListener(Ignite ignite, IgnitePredicate<Event> lsnr) { if (!lsnrs.contains(lsnr)) lsnrs.add(lsnr); ignite.events().localListen(lsnr, EVTS_CACHE); }
/** {@inheritDoc} */ @Override public void run() { ignite.events().localListen(lsnr, types); } }
/** * @param ignite Client node. * @return Client reconnect state. */ private AtomicBoolean getClientReconnectState(Ignite ignite) { final AtomicBoolean reconnectState = new AtomicBoolean(false); ignite.events().localListen( new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { if (evt.type() == EventType.EVT_CLIENT_NODE_RECONNECTED) reconnectState.set(true); return true; } }, EventType.EVT_CLIENT_NODE_RECONNECTED ); return reconnectState; } }
/** * @throws Exception Thrown in case of any errors. */ @Test public void testAddEventLocalListener() throws Exception { try { ignite.events().localListen(null, EVTS_ALL); assert false : "Null listener can't be added."; } catch (NullPointerException ignored) { // No-op. } }
/** * @throws Exception Thrown in case of any errors. */ @Test public void testAddDiscoveryListener() throws Exception { try { ignite.events().localListen(null, EVTS_ALL); assert false : "Null listener can't be added."; } catch (NullPointerException ignored) { // No-op. } }
@Nullable @Override public Object call() throws Exception { Ignite g = startGrid("first"); g.events().localListen( new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { stopLatch.countDown(); return true; } }, EventType.EVT_NODE_JOINED); startLatch.countDown(); stopLatch.await(); G.stop(g.name(), false); return null; } },
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { for (int i = 0; i < PERM_NODES_CNT; i++) { Ignite g = startGrid(gridCntr++); g.events().localListen(lsnr, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED); alive.add(g); } for (int i = 0; i < PERM_NODES_CNT + TMP_NODES_CNT; i++) F.rand(alive).cache(DEFAULT_CACHE_NAME).put(i, String.valueOf(i)); }
/** * */ public void register() { ignite().events().localListen(this.delegate, this.causes); sync(); }
/** * Apply given task on disconnected client node. * * @param task Task. * @throws InterruptedException If interrupted. */ private void runTaskWhenDisconnected(final Runnable task) throws InterruptedException { Ignite client = client(); CountDownLatch latch = new CountDownLatch(1); client.events().localListen((IgnitePredicate<Event>)evt -> { latch.countDown(); return false; }, EVT_CLIENT_NODE_DISCONNECTED); server().close(); assertTrue(latch.await(CLIENT_FAILURE_DETECTION_TIMEOUT * 2, TimeUnit.MILLISECONDS)); task.run(); }
/** * Starts temporary nodes. * * @throws Exception If failed. */ private void startTempNodes() throws Exception { for (int j = 0; j < TMP_NODES_CNT; j++) { Ignite newNode = startGrid(gridCntr++); info("New node started: " + newNode.name()); alive.add(newNode); newNode.events().localListen(lsnr, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED); } }
/** * */ @Test public void testConcurrentAccess() { for (int i = 0; i < GRIDS; i++) { grid(i).events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return true; } }, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_NODE_JOINED); } } }
/** * @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); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); gridCnt = gridCount(); evtLsnr = createEventListener(); for (int i = 0; i < gridCnt; i++) grid(i).events().localListen(evtLsnr, EVTS_CACHE); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { Ignite g = startGrid(); g.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof TaskEvent; evts.add((TaskEvent)evt); latch.countDown(); return true; } }, EVTS_TASK_EXECUTION); nodeId = g.cluster().localNode().id(); GridClientConfiguration cfg = new GridClientConfiguration(); cfg.setServers(Collections.singleton("127.0.0.1:11211")); client = GridClientFactory.start(cfg); }
/** * @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); }
/** * @throws Exception If failed. */ @Test public void testReconnect() throws Exception { Ignite srv = startGrid("server"); IgniteEvents evts = srv.events(); evts.enableLocal(EventType.EVTS_DISCOVERY_ALL); evts.localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { ClusterNode node = ((DiscoveryEvent)evt).eventNode(); rejoinAttr = node.attribute("test"); return true; } }, EventType.EVT_NODE_JOINED); Ignite client = startGrid("client"); reconnectClientNode(log, client, srv, null); assertEquals("2", rejoinAttr); } }
/** * Test job subject ID propagation. * * @throws Exception If failed. */ @Test public void testJobSubjectId() throws Exception { node2.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { JobEvent evt0 = (JobEvent)evt; assert evtSubjId == null; evtSubjId = evt0.taskSubjectId(); return false; } }, EventType.EVT_JOB_STARTED); node1.compute().execute(new Task(node2.cluster().localNode().id()), null); assertEquals(taskSubjId, jobSubjId); assertEquals(taskSubjId, evtSubjId); }
/** * Test job subject ID propagation in case if was changed. * * @throws Exception If failed. */ @Test public void testModifiedSubjectId() throws Exception { node1.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { JobEvent evt0 = (JobEvent)evt; assert evtSubjId == null; evtSubjId = evt0.taskSubjectId(); return false; } }, EventType.EVT_JOB_STARTED); UUID uuid = new UUID(100, 100); ((IgniteEx) node1).context().task().setThreadContextIfNotNull(TC_SUBJ_ID, uuid); ((IgniteEx) node1).context().task().execute(new Task(node1.cluster().localNode().id()), null).get(); assertEquals(uuid, jobSubjId); assertEquals(uuid, evtSubjId); }