@Test(expected = IllegalStateException.class) public void shouldFailToCreateTimeoutIfTimerNotRunning() throws Exception { timer.newTimeout(new Timer.TimeoutTask() { @Override public void run(Timer.TimeoutHandle timeoutHandle) { } }, 5, TimeUnit.SECONDS); }
@Override public synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit) { checkArgument(timeout >= 0, "negative timeout:%s", timeout); WrappedTimeoutHandle timeoutHandle = new WrappedTimeoutHandle(task); checkState(running, "timer not running"); timer.schedule(timeoutHandle.getTimerTask(), timeUnit.toMillis(timeout)); return timeoutHandle; }
WrappedTimer implements Timer { @Override public synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit) { checkArgument(timeout >= 0, "negative timeout:%s", timeout); WrappedTimeoutHandle timeoutHandle = new WrappedTimeoutHandle(task); checkState(running, "timer not running"); timer.schedule(timeoutHandle.getTimerTask(), timeUnit.toMillis(timeout)); return timeoutHandle; } }
WrappedTimer implements Timer { @Override public synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit) { checkArgument(timeout >= 0, "negative timeout:%s", timeout); WrappedTimeoutHandle timeoutHandle = new WrappedTimeoutHandle(task); checkState(running, "timer not running"); timer.schedule(timeoutHandle.getTimerTask(), timeUnit.toMillis(timeout)); return timeoutHandle; }  }
WrappedTimer implements Timer { @Override public synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit) { checkArgument(timeout >= 0, "negative timeout:%s", timeout); WrappedTimeoutHandle timeoutHandle = new WrappedTimeoutHandle(task); checkState(running, "timer not running"); timer.schedule(timeoutHandle.getTimerTask(), timeUnit.toMillis(timeout)); return timeoutHandle; }  synchronized void start(); synchronized void stop(); @Override synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit); }
WrappedTimer implements Timer { @Override public synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit) { checkArgument(timeout >= 0, "negative timeout:%s", timeout); WrappedTimeoutHandle timeoutHandle = new WrappedTimeoutHandle(task); checkState(running, "timer not running"); timer.schedule(timeoutHandle.getTimerTask(), timeUnit.toMillis(timeout)); return timeoutHandle; }  synchronized void start(); synchronized void stop(); @Override synchronized TimeoutHandle newTimeout(final TimeoutTask task, long timeout, TimeUnit timeUnit);  }