@Test public void testStart() throws Exception { ScheduledExecutorService s = Executors.newScheduledThreadPool(2); PollScheduler.getInstance().start(s); assertTrue(PollScheduler.getInstance().isStarted()); //PollScheduler.getInstance().addPoller( ,60, TimeUnit.SECONDS); PollScheduler.getInstance().stop(); }
@Test public void testStop() throws Exception { ScheduledExecutorService s = Executors.newScheduledThreadPool(2); PollScheduler.getInstance().start(s); assertTrue(PollScheduler.getInstance().isStarted()); PollScheduler.getInstance().stop(); assertTrue(!PollScheduler.getInstance().isStarted()); assertTrue(s.isShutdown()); } }
@Test public void testStartNoArg() throws Exception { PollScheduler.getInstance().start(); assertTrue(PollScheduler.getInstance().isStarted()); PollScheduler.getInstance().stop(); }
private static void initHttpServer() throws Exception { // Setup default endpoints final HttpServer server = HttpServer.create(); server.createContext("/echo", new EchoHandler()); // Hook to allow for graceful exit final Closeable c = () -> { PollScheduler.getInstance().stop(); server.stop(5); }; server.createContext("/exit", new ExitHandler(c)); // Bind and start server server.bind(new InetSocketAddress(Config.getPort()), 0); server.start(); }
/** * Stops the polling that publishes metrics; for maximum safety, call this method before calling System.exit(). */ public void stop() { // Log4j2 start-up calls start() twice for a particular appender, and therefore calls stop() twice, but (as it // turns out) calls start() twice before the first call to stop()! As a result we have to count the number of // times that start() was called and not actually stop until the last call. The <code><= 0</code> check in this // method allows the unit test to execute the <code>catch(IllegalStateException e)</code> by calling stop() // before ever calling start(). try { if(POLL_SCHEDULER_START_COUNT.decrementAndGet() <= 0) { POLL_SCHEDULER.stop(); } } catch(IllegalStateException e) { // The poller wasn't started; just ignore this error } }
private static void doStop() { if (!initialized) { return; } PollScheduler.getInstance().stop(); }
private static void doStop() { if (!initialized) { return; } PollScheduler.getInstance().stop(); LOGGER.debug("PollScheduler.getInstance().stop() completed"); initialized = false; LOGGER.debug("doStop() complete, initialized = " + initialized); }
/** * Call this method to stop collecting all metrics. */ @Override public void stop() { final PollScheduler scheduler = PollScheduler.getInstance(); if (monitoringEnabled && scheduler.isStarted()) { synchronized (scheduler) { if (scheduler.isStarted()) { scheduler.stop(); unregisterCustomMonitors(); LOG.info("monitoring stopped."); } } } }