org.xnio.AbstractConvertingIoFuture Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xnio;
import java.util.concurrent.TimeUnit;
import java.io.IOException;
/**
* An {@code IoFuture} implementation that wraps a different type of {@code IoFuture}. Used to create general wrappers
* that convert one channel type to another.
*
* @param the type of this future result
* @param the type of the delegate result
*/
public abstract class AbstractConvertingIoFuture implements IoFuture {
/**
* The delegate future result.
*/
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 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 IoFuture addNotifier(final Notifier super T, A> notifier, A attachment) {
delegate.addNotifier(new Notifier() {
public void notify(final IoFuture extends D> future, A attachment) {
notifier.notify(AbstractConvertingIoFuture.this, attachment);
}
}, attachment);
return this;
}
}