protected <T> ScheduledTask<T> schedule( String name, String type, Callable<T> callable, Schedule schedule ) { return schedule( generateId(), name, type, callable, schedule, true ); }
public void shutdown() { getLogger().info( "Shutting down Scheduler..." ); getScheduledExecutorService().shutdown(); try { boolean stopped = getScheduledExecutorService().awaitTermination( 1, TimeUnit.SECONDS ); if ( !stopped ) { final Map<String, List<ScheduledTask<?>>> runningTasks = getRunningTasks(); if ( !runningTasks.isEmpty() ) { getScheduledExecutorService().shutdownNow(); getLogger().warn( "Scheduler shut down forcibly with tasks running." ); } else { getLogger().info( "Scheduler shut down cleanly with tasks scheduled." ); } } } catch ( InterruptedException e ) { getLogger().info( "Termination interrupted", e ); } }
public void shutdown() { getLogger().info("Shutting down Scheduler..."); try { scheduledExecutorService.shutdown(); boolean stopped = scheduledExecutorService.awaitTermination(3L, TimeUnit.SECONDS); if (!stopped) { final Map<String, List<ScheduledTask<?>>> runningTasks = getRunningTasks(); if (!runningTasks.isEmpty()) { scheduledExecutorService.shutdownNow(); getLogger().warn("Scheduler shut down forcibly with tasks running."); } else { getLogger().info("Scheduler shut down cleanly with tasks scheduled."); } } } catch (InterruptedException e) { getLogger().info("Termination interrupted", e); } }
if (!((SchedulerTask<?>) getCallable()).allowConcurrentExecution(getScheduler().getActiveTasks())) { if (nextRun != null) { setFuture(getScheduler().getScheduledExecutorService().schedule(this, 10000, TimeUnit.MILLISECONDS)); getScheduler().removeFromTasksMap(this); getScheduler().removeFromTasksMap(this);
public <T> ScheduledTask<T> initialize(String id, String name, String type, Callable<T> callable, Schedule schedule, boolean enabled) { return schedule(id, name, type, callable, schedule, enabled, false); }
public ScheduledTask<?> getTaskById(String id) throws NoSuchTaskException { if (StringUtils_isEmpty(id)) { throw new IllegalArgumentException("The Tasks cannot have null IDs!"); } final Collection<List<ScheduledTask<?>>> activeTasks = getAllTasks().values(); for (List<ScheduledTask<?>> tasks : activeTasks) { for (ScheduledTask<?> task : tasks) { if (task.getId().equals(id)) { return task; } } } throw new NoSuchTaskException(id); }
public void initializeTasks() { getLogger().info("Initializing Scheduler..."); // this call delegates to task config manager that loads up the persisted tasks (if any) // and performs a series of callbacks to this to make them "alive" taskConfig.initializeTasks(this); // wind up the "idGen" source, to the max ID we got loaded up from config (the generated IDs are persisted) int maxId = 0; for (Map.Entry<String, List<ScheduledTask<?>>> entry : getAllTasks().entrySet()) { for (ScheduledTask<?> task : entry.getValue()) { try { maxId = Math.max(maxId, Integer.parseInt(task.getId())); } catch (NumberFormatException e) { // be forgiving about non number IDs // hint1: sadly, some Nexus ITs does have them // hint2: they will not clash with numbers anyway } } } idGen.set(maxId); }
public Map<String, List<ScheduledTask<?>>> getActiveTasks() { Map<String, List<ScheduledTask<?>>> result = getAllTasks(); List<ScheduledTask<?>> tasks = null; // filter for activeOrSubmitted for (Iterator<String> c = result.keySet().iterator(); c.hasNext(); ) { String cls = c.next(); tasks = result.get(cls); for (Iterator<ScheduledTask<?>> i = tasks.iterator(); i.hasNext(); ) { ScheduledTask<?> task = i.next(); if (!task.getTaskState().isActiveOrSubmitted()) { i.remove(); } } if (tasks.isEmpty()) { c.remove(); } } return result; }
protected <T> ScheduledTask<T> schedule( String id, String name, String type, Callable<T> callable, Schedule schedule, boolean enabled, boolean store ) { DefaultScheduledTask<T> dct = new DefaultScheduledTask<T>( id, name, type, this, callable, schedule ); dct.setEnabled( enabled ); addToTasksMap( dct, store ); dct.start(); return dct; }
private Future<T> doSchedule( long nextTime ) { return getScheduler().getScheduledExecutorService().schedule( this, Math.max( 0, nextTime - System.currentTimeMillis() ), TimeUnit.MILLISECONDS ); }
getScheduler().removeFromTasksMap(this);
if ( !( (SchedulerTask<?>) getCallable() ).allowConcurrentExecution( getScheduler().getActiveTasks() ) ) setFuture( getScheduler().getScheduledExecutorService().schedule( this, 10000, TimeUnit.MILLISECONDS ) ); getScheduler().removeFromTasksMap( this ); getScheduler().removeFromTasksMap( this );
protected <T> ScheduledTask<T> schedule( String id, String name, String type, Callable<T> callable, Schedule schedule, boolean store ) { return schedule( id, name, type, callable, schedule, true, store ); }
public ScheduledTask<?> getTaskById( String id ) throws NoSuchTaskException { if ( StringUtils_isEmpty(id) ) { throw new IllegalArgumentException( "The Tasks cannot have null IDs!" ); } final Collection<List<ScheduledTask<?>>> activeTasks = getAllTasks().values(); for ( List<ScheduledTask<?>> tasks : activeTasks ) { for ( ScheduledTask<?> task : tasks ) { if ( task.getId().equals( id ) ) { return task; } } } throw new NoSuchTaskException( id ); }
public void initializeTasks() { getLogger().info( "Initializing Scheduler..." ); // this call delegates to task config manager that loads up the persisted tasks (if any) // and performs a series of callbacks to this to make them "alive" taskConfig.initializeTasks( this ); // wind up the "idGen" source, to the max ID we got loaded up from config (the generated IDs are persisted) int maxId = 0; for ( Map.Entry<String, List<ScheduledTask<?>>> entry : getAllTasks().entrySet() ) { for ( ScheduledTask<?> task : entry.getValue() ) { try { maxId = Math.max( maxId, Integer.parseInt( task.getId() ) ); } catch ( NumberFormatException e ) { // be forgiving about non number IDs // hint1: sadly, some Nexus ITs does have them // hint2: they will not clash with numbers anyway } } } idGen.set( maxId ); }
public Map<String, List<ScheduledTask<?>>> getRunningTasks() { Map<String, List<ScheduledTask<?>>> result = getAllTasks(); List<ScheduledTask<?>> tasks = null; // filter for RUNNING for (Iterator<String> c = result.keySet().iterator(); c.hasNext(); ) { String cls = c.next(); tasks = result.get(cls); for (Iterator<ScheduledTask<?>> i = tasks.iterator(); i.hasNext(); ) { ScheduledTask<?> task = i.next(); if (!TaskState.RUNNING.equals(task.getTaskState())) { i.remove(); } } if (tasks.isEmpty()) { c.remove(); } } return result; } }
protected <T> ScheduledTask<T> schedule(String id, String name, String type, Callable<T> callable, Schedule schedule, boolean enabled, boolean store) { DefaultScheduledTask<T> dct = new DefaultScheduledTask<T>(id, name, type, this, callable, schedule); dct.setEnabled(enabled); addToTasksMap(dct, store); dct.start(); return dct; }
private Future<T> doSchedule(final long nextTime, final boolean inheritContext) { // FIXME: All this coz MDCUtils are in Core, while // scheduler is a module ahead. If scheduler would // be in core, this would not be needed, but instead // MDCUtils.markCurrentContextNonInheritable() call would do it if (!inheritContext) { MDC.put("non-inheritable", "non-inheritable"); } try { return getScheduler().getScheduledExecutorService().schedule(this, Math.max(0, nextTime - System.currentTimeMillis()), TimeUnit.MILLISECONDS); } finally { if (!inheritContext) { MDC.remove("non-inheritable"); } } }
getScheduler().removeFromTasksMap( this );
public <T> ScheduledTask<T> initialize( String id, String name, String type, Callable<T> callable, Schedule schedule, boolean enabled ) { return schedule( id, name, type, callable, schedule, enabled, false ); }