@Test public void testCallReturnValueFailureRetry() { final Object expected = new Object(); final AbstractBackgroundAction<Object> action = new AbstractBackgroundAction<Object>() { final AtomicBoolean exception = new AtomicBoolean(); @Override public Object run() throws BackgroundException { try { if(!exception.get()) { throw new BackgroundException(); } } finally { exception.set(true); } return expected; } @Override public boolean alert(final BackgroundException e) { return true; } }; final BackgroundCallable<Object> c = new BackgroundCallable<>(action, new AbstractController() { @Override public void invoke(final MainAction runnable, final boolean wait) { } }); assertSame(expected, c.call()); assertFalse(action.isRunning()); assertFalse(action.isCanceled()); }
@Override public T call() { if(log.isDebugEnabled()) { log.debug(String.format("Running background action %s", action)); } final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); if(action.isCanceled()) { return null; } if(log.isDebugEnabled()) { log.debug(String.format("Prepare background action %s", action)); } action.prepare(); try { final T result = this.run(); if(log.isDebugEnabled()) { log.debug(String.format("Return result %s from background action %s", result, action)); } return result; } finally { action.finish(); if(log.isDebugEnabled()) { log.debug(String.format("Invoke cleanup for background action %s", action)); } controller.invoke(new ControllerMainAction(controller) { @Override public void run() { try { action.cleanup(); } catch(Exception e) { log.error(String.format("Exception %s running cleanup task", e), e); } } }); if(log.isDebugEnabled()) { log.debug(String.format("Releasing lock for background runnable %s", action)); } autorelease.operate(); } }
BackgroundCallable implements Callable<T> { @Override public T call() { if(log.isDebugEnabled()) { log.debug(String.format("Running background action %s", action)); } final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); if(action.isCanceled()) { return null; } if(log.isDebugEnabled()) { log.debug(String.format("Prepare background action %s", action)); } action.prepare(); try { final T result = this.run(); if(log.isDebugEnabled()) { log.debug(String.format("Return result %s from background action %s", result, action)); } return result; } finally { action.finish(); if(log.isDebugEnabled()) { log.debug(String.format("Invoke cleanup for background action %s", action)); } controller.invoke(new ControllerMainAction(controller) { @Override public void run() { try { action.cleanup(); } catch(Exception e) { log.error(String.format("Exception %s running cleanup task", e), e); } } }); if(log.isDebugEnabled()) { log.debug(String.format("Releasing lock for background runnable %s", action)); } autorelease.operate(); } } }
BackgroundCallable implements Callable<T> { @Override public T call() { if(log.isDebugEnabled()) { log.debug(String.format("Running background action %s", action)); } final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); if(action.isCanceled()) { return null; } if(log.isDebugEnabled()) { log.debug(String.format("Prepare background action %s", action)); } action.prepare(); try { final T result = this.run(); if(log.isDebugEnabled()) { log.debug(String.format("Return result %s from background action %s", result, action)); } return result; } finally { action.finish(); if(log.isDebugEnabled()) { log.debug(String.format("Invoke cleanup for background action %s", action)); } controller.invoke(new ControllerMainAction(controller) { @Override public void run() { try { action.cleanup(); } catch(Exception e) { log.error(String.format("Exception %s running cleanup task", e), e); } } }); if(log.isDebugEnabled()) { log.debug(String.format("Releasing lock for background runnable %s", action)); } autorelease.operate(); } } BackgroundCallable(final BackgroundAction<T> action, final Controller controller); }
BackgroundCallable implements Callable<T> { @Override public T call() { if(log.isDebugEnabled()) { log.debug(String.format("Running background action %s", action)); } final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); if(action.isCanceled()) { return null; } if(log.isDebugEnabled()) { log.debug(String.format("Prepare background action %s", action)); } action.prepare(); try { final T result = this.run(); if(log.isDebugEnabled()) { log.debug(String.format("Return result %s from background action %s", result, action)); } return result; } finally { action.finish(); if(log.isDebugEnabled()) { log.debug(String.format("Invoke cleanup for background action %s", action)); } controller.invoke(new ControllerMainAction(controller) { @Override public void run() { try { action.cleanup(); } catch(Exception e) { log.error(String.format("Exception %s running cleanup task", e), e); } } }); if(log.isDebugEnabled()) { log.debug(String.format("Releasing lock for background runnable %s", action)); } autorelease.operate(); } } BackgroundCallable(final BackgroundAction<T> action, final Controller controller); @Override T call(); }
BackgroundCallable implements Callable<T> { @Override public T call() { if(log.isDebugEnabled()) { log.debug(String.format("Running background action %s", action)); } final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); if(action.isCanceled()) { return null; } if(log.isDebugEnabled()) { log.debug(String.format("Prepare background action %s", action)); } action.prepare(); try { final T result = this.run(); if(log.isDebugEnabled()) { log.debug(String.format("Return result %s from background action %s", result, action)); } return result; } finally { action.finish(); if(log.isDebugEnabled()) { log.debug(String.format("Invoke cleanup for background action %s", action)); } controller.invoke(new ControllerMainAction(controller) { @Override public void run() { try { action.cleanup(); } catch(Exception e) { log.error(String.format("Exception %s running cleanup task", e), e); } } }); if(log.isDebugEnabled()) { log.debug(String.format("Releasing lock for background runnable %s", action)); } autorelease.operate(); } } BackgroundCallable(final BackgroundAction<T> action, final Controller controller); @Override T call();  }