@Test public void testBackground() throws Exception { final AbstractController controller = new AbstractController() { @Override public void invoke(final MainAction runnable, final boolean wait) { runnable.run(); } }; final AbstractBackgroundAction<Object> action = new RegistryBackgroundAction<Object>(controller, SessionPool.DISCONNECTED) { @Override public void init() { assertEquals("main", Thread.currentThread().getName()); } @Override public Object run(final Session<?> session) { return null; } @Override public void cleanup() { super.cleanup(); assertFalse(controller.getRegistry().contains(this)); } }; controller.background(action).get(); }
@Override public <T> Future<T> background(final BackgroundAction<T> action) { if(registry.contains(action)) { log.warn(String.format("Skip duplicate background action %s found in registry", action)); return ConcurrentUtils.constantFuture(null); } return DefaultBackgroundExecutor.get().execute(this, registry, action); }
AbstractController implements Controller { @Override public <T> Future<T> background(final BackgroundAction<T> action) { if(registry.contains(action)) { log.warn(String.format("Skip duplicate background action %s found in registry", action)); return ConcurrentUtils.constantFuture(null); } return DefaultBackgroundExecutor.get().execute(this, registry, action); } }
AbstractController implements Controller { @Override public <T> Future<T> background(final BackgroundAction<T> action) { if(registry.contains(action)) { log.warn(String.format("Skip duplicate background action %s found in registry", action)); return ConcurrentUtils.constantFuture(null); } return DefaultBackgroundExecutor.get().execute(this, registry, action); }  }
AbstractController implements Controller { @Override public <T> Future<T> background(final BackgroundAction<T> action) { if(registry.contains(action)) { log.warn(String.format("Skip duplicate background action %s found in registry", action)); return ConcurrentUtils.constantFuture(null); } return DefaultBackgroundExecutor.get().execute(this, registry, action); }  @Override void invoke(final MainAction runnable); @Override BackgroundActionRegistry getRegistry(); @Override Future<T> background(final BackgroundAction<T> action); @Override void start(final BackgroundAction action); @Override void cancel(final BackgroundAction action); @Override void stop(final BackgroundAction action); @Override void message(final String message); @Override void log(final Type request, final String message); }
AbstractController implements Controller { @Override public <T> Future<T> background(final BackgroundAction<T> action) { if(registry.contains(action)) { log.warn(String.format("Skip duplicate background action %s found in registry", action)); return ConcurrentUtils.constantFuture(null); } return DefaultBackgroundExecutor.get().execute(this, registry, action); }  @Override void invoke(final MainAction runnable); @Override BackgroundActionRegistry getRegistry(); @Override Future<T> background(final BackgroundAction<T> action); @Override void start(final BackgroundAction action); @Override void cancel(final BackgroundAction action); @Override void stop(final BackgroundAction action); @Override void message(final String message); @Override void log(final Type request, final String message);  }