Skip to content

Commit

Permalink
Remove TaskScheduler and ImmediateEventExecutor that requires TaskSch…
Browse files Browse the repository at this point in the history
…eduler

- Related issue: netty#817
  • Loading branch information
trustin committed Mar 22, 2013
1 parent 6869a2b commit fa02ffd
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 719 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,80 @@
*/
package io.netty.util.concurrent;

import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.TimeUnit;


/**
* Abstract base class for {@link EventExecutor} implementations that use a {@link TaskScheduler} to support
* scheduling tasks.
* Abstract base class for {@link EventExecutor} implementations.
*/
public abstract class AbstractEventExecutor extends AbstractEventExecutorWithoutScheduler {
private final TaskScheduler scheduler;
public abstract class AbstractEventExecutor extends AbstractExecutorService implements EventExecutor {

@Override
public EventExecutor next() {
return this;
}

@Override
public <V> Promise<V> newPromise() {
return new DefaultPromise<V>(this);
}

protected AbstractEventExecutor(TaskScheduler scheduler) {
if (scheduler == null) {
throw new NullPointerException("scheduler");
}
this.scheduler = scheduler;
@Override
public <V> Future<V> newSucceededFuture(V result) {
return new SucceededFuture<V>(this, result);
}

@Override
public <V> Future<V> newFailedFuture(Throwable cause) {
return new FailedFuture<V>(this, cause);
}

@Override
public Future<?> submit(Runnable task) {
return (Future<?>) super.submit(task);
}

@Override
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
return scheduler.schedule(this, command, delay, unit);
public <T> Future<T> submit(Runnable task, T result) {
return (Future<T>) super.submit(task, result);
}

@Override
public <T> Future<T> submit(Callable<T> task) {
return (Future<T>) super.submit(task);
}

@Override
protected final <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
return new PromiseTask<T>(this, runnable, value);
}

@Override
protected final <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
return new PromiseTask<T>(this, callable);
}

@Override
public ScheduledFuture<?> schedule(Runnable command, long delay,
TimeUnit unit) {
throw new UnsupportedOperationException();
}

@Override
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
return scheduler.schedule(this, callable, delay, unit);
throw new UnsupportedOperationException();
}

@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
return scheduler.scheduleAtFixedRate(this, command, initialDelay, period, unit);
throw new UnsupportedOperationException();
}

@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
return scheduler.scheduleWithFixedDelay(this, command, initialDelay, delay, unit);
throw new UnsupportedOperationException();
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* Abstract base class for {@link EventExecutor}'s that execute all its submitted tasks in a single thread.
*
*/
public abstract class SingleThreadEventExecutor extends AbstractEventExecutorWithoutScheduler {
public abstract class SingleThreadEventExecutor extends AbstractEventExecutor {

private static final InternalLogger logger =
InternalLoggerFactory.getInstance(SingleThreadEventExecutor.class);
Expand Down
Loading

0 comments on commit fa02ffd

Please sign in to comment.