Search in sources :

Example 1 with AbstractScheduledService

use of com.google.common.util.concurrent.AbstractScheduledService in project cdap by caskdata.

the class ConcurrentStreamWriter method scheduleWriterRefresh.

private Service scheduleWriterRefresh() {
    AbstractScheduledService scheduledService = new AbstractScheduledService() {

        @Override
        protected void runOneIteration() throws Exception {
            for (EventQueue eventQueue : eventQueues.values()) {
                try {
                    eventQueue.refresh();
                } catch (Throwable t) {
                    LOG.error("Error while refreshing event queue.", t);
                }
            }
        }

        @Override
        protected ScheduledExecutorService executor() {
            return Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory("concurrent-stream-writer"));
        }

        @Override
        protected Scheduler scheduler() {
            return Scheduler.newFixedDelaySchedule(5, 5, TimeUnit.MINUTES);
        }
    };
    scheduledService.startAndWait();
    return scheduledService;
}
Also used : AbstractScheduledService(com.google.common.util.concurrent.AbstractScheduledService)

Aggregations

AbstractScheduledService (com.google.common.util.concurrent.AbstractScheduledService)1