@Override public void run() { try { action.cleanup(); } catch(Exception e) { log.error(String.format("Exception running cleanup task %s", e.getMessage()), e); } } });
@Override public <T> Future<T> execute(final Controller controller, final BackgroundActionRegistry registry, final BackgroundAction<T> action) { if(log.isDebugEnabled()) { log.debug(String.format("Run action %s in background", action)); } // Add action to registry of controller. Will be removed automatically when stopped registry.add(action); action.init(); // Start background task final Callable<T> command = new BackgroundCallable<T>(action, controller); try { final Future<T> task = concurrentExecutor.execute(command); if(log.isInfoEnabled()) { log.info(String.format("Scheduled background runnable %s for execution", action)); } return task; } catch(RejectedExecutionException e) { log.error(String.format("Error scheduling background task %s for execution. %s", action, e.getMessage())); action.cancel(); action.cleanup(); return ConcurrentUtils.constantFuture(null); } }