@Override protected void startUp() throws Exception { LOG.info("Starting {} periodicals ...", periodicalSet.size()); for (Periodical periodical : periodicalSet) { try { periodical.initialize(); if (periodical.masterOnly() && !serverStatus.hasCapability(ServerStatus.Capability.MASTER)) { LOG.info( "Not starting [{}] periodical. Only started on graylog2-server master nodes.", periodical.getClass().getCanonicalName()); continue; } if (!periodical.startOnThisNode()) { LOG.info( "Not starting [{}] periodical. Not configured to run on this node.", periodical.getClass().getCanonicalName()); continue; } // Register and start. periodicals.registerAndStart(periodical); } catch (Exception e) { LOG.error("Could not initialize periodical.", e); } } }
@Override protected void shutDown() throws Exception { for (Periodical periodical : periodicals.getAllStoppedOnGracefulShutdown()) { LOG.info("Shutting down periodical [{}].", periodical.getClass().getCanonicalName()); Stopwatch s = Stopwatch.createStarted(); // Cancel future executions. Map<Periodical, ScheduledFuture> futures = periodicals.getFutures(); if (futures.containsKey(periodical)) { futures.get(periodical).cancel(false); s.stop(); LOG.info( "Shutdown of periodical [{}] complete, took <{}ms>.", periodical.getClass().getCanonicalName(), s.elapsed(TimeUnit.MILLISECONDS)); } else { LOG.error( "Could not find periodical [{}] in futures list. Not stopping execution.", periodical.getClass().getCanonicalName()); } } }