/** * Ensure that {@link GridComputeJobMasterLeaveAware} callback is invoked on job which is * initiated by master and is currently running on it. * * @throws Exception If failed. */ public void testLocalJobOnMaster() throws Exception { invokeLatch = new CountDownLatch(1); jobLatch = new CountDownLatch(1); Grid g = startGrid(0); g.compute().execute(new TestTask(1), null); jobLatch.await(); // Count down the latch in a separate thread. new Thread( new Runnable() { @Override public void run() { try { U.sleep(500); } catch (GridInterruptedException ignore) { // No-op. } latch.countDown(); } }) .start(); stopGrid(0, true); latch.countDown(); assert invokeLatch.await(5000, MILLISECONDS); }
/** * Listen to events that happen only on local node. * * @throws GridException If failed. */ private static void localListen() throws GridException { Grid g = GridGain.grid(); // Register event listener for all local task execution events. g.events() .localListen( new GridPredicate<GridEvent>() { @Override public boolean apply(GridEvent evt) { GridTaskEvent taskEvt = (GridTaskEvent) evt; System.out.println(); System.out.println( "Git event notification [evt=" + evt.name() + ", taskName=" + taskEvt.taskName() + ']'); return true; } }, EVTS_TASK_EXECUTION); // Generate task events. g.compute() .withName("example-event-task") .run( new GridRunnable() { @Override public void run() { System.out.println(); System.out.println("Executing sample job."); } }) .get(); }