void execute(Runnable command, boolean can_block);
Future<?> schedule(Runnable command, long delay, TimeUnit unit, boolean can_block);
@Override public void stop() { if (!getTimer().isShutdown()) { getTimer().stop(); } super.stop(); }
public Responses findMembers(final List<Address> members, final boolean initial_discovery, boolean async, long timeout) { num_discovery_requests++; int num_expected=members != null? members.size() : 0; int capacity=members != null? members.size() : 16; Responses rsps=new Responses(num_expected, initial_discovery && break_on_coord_rsp, capacity); addResponse(rsps); if(async || async_discovery || (num_discovery_runs > 1) && initial_discovery) { timer.execute(() -> invokeFindMembers(members, initial_discovery, rsps, async)); if(num_discovery_runs > 1 && initial_discovery) { int num_reqs_to_send=num_discovery_runs-1; long last_send=timeout - (timeout/num_discovery_runs); long interval=last_send/num_reqs_to_send; for(long i=0,delay=interval; i < num_reqs_to_send; i++,delay+=interval) { Future<?> future=timer.schedule(() -> invokeFindMembers(members, initial_discovery, rsps, async), delay, TimeUnit.MILLISECONDS); this.discovery_req_futures.add(future); num_discovery_requests++; } } } else invokeFindMembers(members, initial_discovery, rsps, async); weedOutCompletedDiscoveryResponses(); return rsps; }
Future<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit, boolean can_block);
Future<?> scheduleWithDynamicInterval(Task task, boolean can_block);
public void destroy() { super.destroy(); if(logical_addr_cache_reaper != null) { logical_addr_cache_reaper.cancel(false); logical_addr_cache_reaper=null; } if(time_service != null) time_service.stop(); // Stop the thread pool if(thread_pool instanceof ExecutorService) shutdownThreadPool(thread_pool); if(internal_pool instanceof ExecutorService) shutdownThreadPool(internal_pool); if(timer != null) timer.stop(); }
timer.setNonBlockingTaskHandling(timer_handle_non_blocking_tasks); logical_addr_cache_reaper=timer.scheduleWithFixedDelay(new Runnable() { public void run() { evictLogicalAddressCache();
@ManagedAttribute(name="timer_tasks",description="Number of timer tasks queued up for execution") public int getNumTimerTasks() { return timer != null? timer.size() : -1; }
/** * Schedule a task for execution at varying intervals. After execution, the task will get rescheduled after * {@link org.jgroups.util.TimeScheduler.Task#nextInterval()} milliseconds. The task is neve done until nextInterval() * return a value <= 0 or the task is cancelled. * @param task the task to execute * @param relative scheduling scheme: <tt>true</tt>:<br> * Task is rescheduled relative to the last time it <i>actually</i> started execution<p/> * <tt>false</tt>:<br> Task is scheduled relative to its <i>last</i> execution schedule. This has the effect * that the time between two consecutive executions of the task remains the same.<p/> * Note that relative is always true; we always schedule the next execution relative to the last *actual* * (not scheduled) execution */ public ScheduledFuture<?> scheduleWithDynamicInterval(Task task, boolean relative) { if(task == null) throw new NullPointerException(); if (isShutdown()) return null; TaskWrapper task_wrapper=new TaskWrapper(task); task_wrapper.doSchedule(); // calls schedule() in ScheduledThreadPoolExecutor return task_wrapper; }
@ManagedAttribute(description="Number of threads currently in the pool") public int getTimerThreads() { return timer.getCurrentThreads(); }
@ManagedOperation public String dumpTimerTasks() { return timer.dumpTimerTasks(); }
protected synchronized void startReconnector() { if(reconnector_task == null || reconnector_task.isDone()) reconnector_task=timer.scheduleWithFixedDelay(this, interval, interval, TimeUnit.MILLISECONDS); }
protected synchronized void startInfoSender() { if(info_sender_future == null || info_sender_future.isDone()) info_sender_future=timer.scheduleWithDynamicInterval(info_sender, getTransport() instanceof TCP); }
public void destroy() { if(top_prot != null) { Configurator.destroyProtocolStack(top_prot); // destroys msg queues and threads top_prot=null; } try { timer.stop(); } catch(Exception ex) { } }
public int getNumberOfTasksInTimer() {return prot_stack != null ? prot_stack.timer.size() : -1;}
@ManagedAttribute(description="Number of threads currently in the pool") public int getTimerThreads() { return timer.getCurrentThreads(); }
@ManagedOperation public String dumpTimerTasks() { return timer.dumpTimerTasks(); }
protected synchronized void startCacheDissemination(List<Address> curr_mbrs, List<Address> left_mbrs, List<Address> new_mbrs) { timer.execute(new DiscoveryCacheDisseminationTask(curr_mbrs,left_mbrs,new_mbrs), sends_can_block); }
protected void scheduleBarrierOpener() { if(barrier_opener_future == null || barrier_opener_future.isDone()) { barrier_opener_future=timer.schedule(this::openBarrier, max_close_time, TimeUnit.MILLISECONDS, false); } }