@Test public void testCancel() { BackgroundActionRegistry r = new BackgroundActionRegistry(); final AbstractBackgroundAction action = new AbstractBackgroundAction() { @Override public Object run() { return null; } }; assertTrue(r.add(action)); action.cancel(); r.remove(action); assertFalse(r.contains(action)); assertNull(r.getCurrent()); }
@Override public synchronized void cancel(final BackgroundAction action) { if(action.isRunning()) { log.debug(String.format("Skip removing action %s currently running", action)); } else { this.remove(action); } }
BackgroundActionRegistry extends Collection<BackgroundAction> implements BackgroundActionListener { @Override public synchronized void cancel(final BackgroundAction action) { if(action.isRunning()) { log.debug(String.format("Skip removing action %s currently running", action)); } else { this.remove(action); } } }
BackgroundActionRegistry extends Collection<BackgroundAction> implements BackgroundActionListener { @Override public synchronized void cancel(final BackgroundAction action) { if(action.isRunning()) { log.debug(String.format("Skip removing action %s currently running", action)); } else { this.remove(action); } } BackgroundActionRegistry(); }
BackgroundActionRegistry extends Collection<BackgroundAction> implements BackgroundActionListener { @Override public synchronized void cancel(final BackgroundAction action) { if(action.isRunning()) { log.debug(String.format("Skip removing action %s currently running", action)); } else { this.remove(action); } } BackgroundActionRegistry(); static BackgroundActionRegistry global(); synchronized BackgroundAction getCurrent(); @Override synchronized void start(final BackgroundAction action); @Override synchronized void stop(final BackgroundAction action); @Override synchronized void cancel(final BackgroundAction action); @Override synchronized boolean add(final BackgroundAction action); @Override synchronized boolean remove(final Object action); @Override boolean equals(final Object o); @Override int hashCode(); }
BackgroundActionRegistry extends Collection<BackgroundAction> implements BackgroundActionListener { @Override public synchronized void cancel(final BackgroundAction action) { if(action.isRunning()) { log.debug(String.format("Skip removing action %s currently running", action)); } else { this.remove(action); } } BackgroundActionRegistry(); static BackgroundActionRegistry global(); synchronized BackgroundAction getCurrent(); @Override synchronized void start(final BackgroundAction action); @Override synchronized void stop(final BackgroundAction action); @Override synchronized void cancel(final BackgroundAction action); @Override synchronized boolean add(final BackgroundAction action); @Override synchronized boolean remove(final Object action); @Override boolean equals(final Object o); @Override int hashCode();  }