package org.xnio;
import java.util.concurrent.TimeUnit;
import java.io.IOException;
public abstract class AbstractConvertingIoFuture<T, D> implements IoFuture<T> {
protected final IoFuture<? extends D> delegate;
protected AbstractConvertingIoFuture(final IoFuture<? extends D> delegate) {
this.delegate = delegate;
}
protected IoFuture<? extends D> getDelegate() {
return delegate;
}
public IoFuture<T> cancel() {
delegate.cancel();
return this;
}
public Status getStatus() {
return delegate.getStatus();
}
public Status await() {
return delegate.await();
}
public Status await(final long time, final TimeUnit timeUnit) {
return delegate.await(time, timeUnit);
}
public Status awaitInterruptibly() throws InterruptedException {
return delegate.awaitInterruptibly();
}
public Status awaitInterruptibly(final long time, final TimeUnit timeUnit) throws InterruptedException {
return delegate.awaitInterruptibly(time, timeUnit);
}
public IOException getException() throws IllegalStateException {
return delegate.getException();
}
public T get() throws IOException {
return convert(delegate.get());
}
public T getInterruptibly() throws IOException, InterruptedException {
return convert(delegate.getInterruptibly());
}
abstract protected T convert(D arg) throws IOException;
public <A> IoFuture<T> addNotifier(final Notifier<? super T, A> notifier, A attachment) {
delegate.addNotifier(new Notifier<D, A>() {
public void notify(final IoFuture<? extends D> future, A attachment) {
notifier.notify(AbstractConvertingIoFuture.this, attachment);
}
}, attachment);
return this;
}
}