public void stopButtonClicked(final ID sender) { task.cancel(); }
@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); } }
@Action public void disconnectButtonClicked(final ID sender) { // Remove all pending actions for(BackgroundAction action : registry.toArray( new BackgroundAction[registry.size()])) { action.cancel(); } this.disconnect(new Runnable() { @Override public void run() { if(preferences.getBoolean("browser.disconnect.bookmarks.show")) { selectBookmarks(BookmarkSwitchSegement.bookmarks); } else { selectBrowser(BrowserSwitchSegement.byPosition(preferences.getInteger("browser.view"))); } } }); }
@Override public void callback(int returncode) { if(returncode == DEFAULT_OPTION) { //Quit final BackgroundActionRegistry registry = shared.getRegistry(); for(BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { action.cancel(); } app.replyToApplicationShouldTerminate(true); } if(returncode == CANCEL_OPTION) { //Cancel app.replyToApplicationShouldTerminate(false); } } });