/** * Starts the host monitor. Does nothing if the monitor is already running. */ void start() { synchronized (this) { if (timeout == null) { timeout = SharedScheduledExecutors.newTimeout(this, 0, TimeUnit.MILLISECONDS); } } }
/** * Executes one-shot timer task on shared thread pool. * * @param task timer task to execute * @param delay before executing the task * @param unit of delay * @return a ScheduledFuture representing pending completion of the task * and whose get() method will return null upon completion */ public static ScheduledFuture<?> newTimeout(Runnable task, long delay, TimeUnit unit) { return SharedScheduledExecutors.getPoolThreadExecutor() .schedule(task, delay, unit); }
@Deactivate protected void deactivate() { cfgService.unregisterProperties(getClass(), false); SharedExecutors.shutdown(); SharedScheduledExecutors.shutdown(); }
@Activate protected void activate() { providerService = providerRegistry.register(this); // listens all OpenFlow device related events controller.addListener(listener); // listens all OpenFlow control message controller.addMessageListener(messageListener); executor = SharedScheduledExecutors.getSingleThreadExecutor(); connectInitialDevices(); log.info("Started"); }
@Override public void run() { monitoredAddresses.forEach(this::probe); synchronized (this) { this.timeout = SharedScheduledExecutors.newTimeout(this, probeRate, TimeUnit.MILLISECONDS); } }