@Test(expected = TaskExistsException.class) public void schedule_twice() throws Exception { SimpleTaskScheduler scheduler = new SimpleTaskScheduler(); String name = "hello"; Runnable task = mock(Runnable.class); scheduler.schedule(name, task, 10); scheduler.schedule(name, task, 10); }
@Override public Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit) { Assertion.notNullOrEmpty(name, "name"); Assertion.notNull(task, "task"); if (tasks.containsKey(name)) { throw new TaskExistsException(name); } TaskProxy proxy = new TaskProxy(name, task); ScheduledFuture<?> future = executor.schedule(proxy, delay, unit); tasks.put(name, future); return future; }
SimpleTaskScheduler implements TinyScheduler { @Override public Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit) { Assertion.notNullOrEmpty(name, "name"); Assertion.notNull(task, "task"); if (tasks.containsKey(name)) { throw new TaskExistsException(name); } TaskProxy proxy = new TaskProxy(name, task); ScheduledFuture<?> future = executor.schedule(proxy, delay, unit); tasks.put(name, future); return future; } }
SimpleTaskScheduler implements TinyScheduler { @Override public Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit) { Assertion.notNullOrEmpty(name, "name"); Assertion.notNull(task, "task"); if (tasks.containsKey(name)) { throw new TaskExistsException(name); } TaskProxy proxy = new TaskProxy(name, task); ScheduledFuture<?> future = executor.schedule(proxy, delay, unit); tasks.put(name, future); return future; } SimpleTaskScheduler();  SimpleTaskScheduler(ScheduledExecutorService executor); }
SimpleTaskScheduler implements TinyScheduler { @Override public Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit) { Assertion.notNullOrEmpty(name, "name"); Assertion.notNull(task, "task"); if (tasks.containsKey(name)) { throw new TaskExistsException(name); } TaskProxy proxy = new TaskProxy(name, task); ScheduledFuture<?> future = executor.schedule(proxy, delay, unit); tasks.put(name, future); return future; } SimpleTaskScheduler();  SimpleTaskScheduler(ScheduledExecutorService executor); @Override Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit); @Override void cancel(String name); boolean has(String name); }
SimpleTaskScheduler implements TinyScheduler { @Override public Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit) { Assertion.notNullOrEmpty(name, "name"); Assertion.notNull(task, "task"); if (tasks.containsKey(name)) { throw new TaskExistsException(name); } TaskProxy proxy = new TaskProxy(name, task); ScheduledFuture<?> future = executor.schedule(proxy, delay, unit); tasks.put(name, future); return future; } SimpleTaskScheduler();  SimpleTaskScheduler(ScheduledExecutorService executor); @Override Future<?> schedule(String name, Runnable task, long delay, TimeUnit unit); @Override void cancel(String name); boolean has(String name);  }