ScheduledTaskImpl implements ScheduledTask { public synchronized boolean cancel(boolean block) { switch (state) { case COMPLETED: case CANCELLED: return false; case RUNNING: if (block) { while (state == State.RUNNING) { try { wait(); } catch (InterruptedException ie) { } } if (!isDone()) { cancel(); return true; } } return false; case RUNNABLE: case INTERRUPTED: cancel(); return true; default: return false; } } private  ScheduledTaskImpl(Builder builder); KernelRunnable getTask(); Identity getOwner(); Priority getPriority(); long getStartTime(); long getPeriod(); int getTryCount(); long getTimeout(); Throwable getLastFailure(); void setPriority(Priority priority); boolean isRecurring(); RecurringTaskHandle getRecurringTaskHandle(); synchronized boolean isCancelled(); synchronized boolean cancel(boolean block); void setTimeout(long timeout); String toString();  }
@Test public void cancelAndDontBlockWhenRunnable() throws Exception { setTaskState("RUNNABLE"); Assert.assertTrue(task.cancel(false)); Assert.assertEquals("CANCELLED", getTaskState()); }
@Test public void cancelAndDontBlockWhenRunning() throws Exception { setTaskState("RUNNING"); Assert.assertFalse(task.cancel(false)); Assert.assertEquals("RUNNING", getTaskState()); }
@Test public void cancelAndDontBlockWhenInterrupted() throws Exception { setTaskState("INTERRUPTED"); Assert.assertTrue(task.cancel(false)); Assert.assertEquals("CANCELLED", getTaskState()); }
@Test public void cancelAndDontBlockWhenCompleted() throws Exception { setTaskState("COMPLETED"); Assert.assertFalse(task.cancel(false)); Assert.assertEquals("COMPLETED", getTaskState()); }
@Test public void cancelAndDontBlockWhenCancelled() throws Exception { setTaskState("CANCELLED"); Assert.assertFalse(task.cancel(false)); Assert.assertEquals("CANCELLED", getTaskState()); }
@Test public void cancelAndBlockWhenRunnable() throws Exception { setTaskState("RUNNABLE"); Assert.assertTrue(task.cancel(true)); Assert.assertEquals("CANCELLED", getTaskState()); }
@Test public void cancelAndBlockWhenInterrupted() throws Exception { setTaskState("INTERRUPTED"); Assert.assertTrue(task.cancel(true)); Assert.assertEquals("CANCELLED", getTaskState()); }
@Test public void cancelAndBlockWhenCompleted() throws Exception { setTaskState("COMPLETED"); Assert.assertFalse(task.cancel(true)); Assert.assertEquals("COMPLETED", getTaskState()); }
@Test public void cancelAndBlockWhenCancelled() throws Exception { setTaskState("CANCELLED"); Assert.assertFalse(task.cancel(true)); Assert.assertEquals("CANCELLED", getTaskState()); }