Search in sources :

Example 1 with Periodicals

use of org.graylog2.periodical.Periodicals in project graylog2-server by Graylog2.

the class SchedulerBindings method configure.

@Override
protected void configure() {
    // TODO Add instrumentation to ExecutorService and ThreadFactory
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE, new ThreadFactoryBuilder().setNameFormat("scheduled-%d").setDaemon(false).setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LOG)).build());
    bind(ScheduledExecutorService.class).annotatedWith(Names.named("scheduler")).toInstance(scheduler);
    // TODO Add instrumentation to ExecutorService and ThreadFactory
    final ScheduledExecutorService daemonScheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE, new ThreadFactoryBuilder().setNameFormat("scheduled-daemon-%d").setDaemon(true).setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LOG)).build());
    bind(ScheduledExecutorService.class).annotatedWith(Names.named("daemonScheduler")).toInstance(daemonScheduler);
    bind(Periodicals.class).toInstance(new Periodicals(scheduler, daemonScheduler));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Tools(org.graylog2.plugin.Tools) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Periodicals(org.graylog2.periodical.Periodicals)

Example 2 with Periodicals

use of org.graylog2.periodical.Periodicals in project graylog2-server by Graylog2.

the class PeriodicalsService method startUp.

@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 Graylog 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);
        }
    }
}
Also used : Periodical(org.graylog2.plugin.periodical.Periodical)

Example 3 with Periodicals

use of org.graylog2.periodical.Periodicals in project graylog2-server by Graylog2.

the class PeriodicalsTest method testGetAllStoppedOnGracefulShutdown.

@Test
public void testGetAllStoppedOnGracefulShutdown() throws Exception {
    final Periodical periodical2 = mock(Periodical.class);
    when(periodical2.stopOnGracefulShutdown()).thenReturn(true);
    periodicals.registerAndStart(periodical);
    periodicals.registerAndStart(periodical2);
    List<Periodical> allStoppedOnGracefulShutdown = periodicals.getAllStoppedOnGracefulShutdown();
    assertFalse("periodical without graceful shutdown is in the list", allStoppedOnGracefulShutdown.contains(periodical));
    assertTrue("graceful shutdown periodical is not in the list", allStoppedOnGracefulShutdown.contains(periodical2));
    assertEquals("more graceful shutdown periodicals in the list", allStoppedOnGracefulShutdown.size(), 1);
}
Also used : Periodical(org.graylog2.plugin.periodical.Periodical) Test(org.junit.Test)

Aggregations

Periodical (org.graylog2.plugin.periodical.Periodical)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Periodicals (org.graylog2.periodical.Periodicals)1 Tools (org.graylog2.plugin.Tools)1 Test (org.junit.Test)1