/** * Schedule this task. * @param ses ScheduledExecutorService that will execute the this. * @return A ScheduledFuture, that provides cancellation. */ public ScheduledFuture<?> createTimerTask(ScheduledExecutorService ses) { return ses.scheduleAtFixedRate(this, INITIAL_RUN_DELAY, getIntervalSeconds(), TimeUnit.SECONDS); }
/** * Start the push processor. */ public void start() { start(false, Thread.NORM_PRIORITY); }
/** * Start the push processor, using the supplied ScheduledExecutorService. * @param ses ScheduledExecutorService that will execute this PushProcessor. */ public void start(ScheduledExecutorService ses) { start_(ses, false); }
private synchronized void start_(ScheduledExecutorService ses, boolean own_ses) { stop_(); logger.log(Level.INFO, "Starting thread for push processor"); my_task_ = Optional.of(ses.scheduleAtFixedRate(this, INITIAL_RUN_DELAY, getIntervalSeconds(), TimeUnit.SECONDS)); if (own_ses) owner_executor_ = Optional.of(ses); }
@Override public void close() { logger.log(Level.INFO, "Closing push processor"); stop_(); super.close(); processors_.forEach(p -> { try { p.close(); } catch (Exception ex) { logger.log(Level.SEVERE, "failed to close " + p.getClass().getName(), ex); } }); } }
/** * Run the collection cycle. */ @Override public final void run() { try { registry_.updateCollection(); final long t0 = System.nanoTime(); processors_.forEach(p -> { try { run_implementation_(p); } catch (Exception ex) { logger.log(Level.SEVERE, p.getClass().getName() + " failed to run properly, some or all metrics may be missed this cycle", ex); } }); final long t_processor = System.nanoTime(); registry_.updateProcessorDuration(Duration.millis(TimeUnit.NANOSECONDS.toMillis(t_processor - t0))); } catch (Throwable t) { /* * We catch any and all throwables. * If we don't and let an exception or error escape, * the scheduled executor service will _silently_ drop our task. */ logger.log(Level.SEVERE, "failed to perform collection", t); } }
registry.setHistory(history_); if (api != null) api.start(); return new PushProcessorPipeline(registry, collect_interval_seconds_, processors); } catch (Exception ex) { try {
/** * Start the push processor. * @param daemon If the thread should be a daemon thread. */ public void start(boolean daemon) { start(daemon, Thread.NORM_PRIORITY); }
/** * Start the push processor, using a daemon thread. * @param daemon If the thread should be a daemon thread. * @param thread_priority The priority of the thread running the push processor. */ public void start(boolean daemon, int thread_priority) { if (thread_priority < Thread.MIN_PRIORITY) throw new IllegalArgumentException("thread priority too low"); if (thread_priority > Thread.MAX_PRIORITY) throw new IllegalArgumentException("thread priority too high"); start_(Executors.newSingleThreadScheduledExecutor((Runnable r) -> { logger.entering(getClass().getName(), "start_", r); Thread t = new Thread(r, "monsoon processor"); t.setDaemon(daemon); t.setPriority(thread_priority); return t; }), true); }
/** * Start the push processor. * @param thread_priority The priority of the thread running the push processor. */ public void start(int thread_priority) { start(false, thread_priority); }