2013-03-05 21:41:19 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2013 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you 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 io.netty.util.concurrent;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A skeletal {@link Future} implementation which represents a {@link Future} which has been completed already.
|
|
|
|
*/
|
2013-03-18 14:18:31 +01:00
|
|
|
public abstract class CompleteFuture<V> extends AbstractFuture<V> {
|
2013-03-05 21:41:19 +01:00
|
|
|
|
|
|
|
private final EventExecutor executor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*
|
|
|
|
* @param executor the {@link EventExecutor} associated with this future
|
|
|
|
*/
|
|
|
|
protected CompleteFuture(EventExecutor executor) {
|
|
|
|
this.executor = executor;
|
|
|
|
}
|
|
|
|
|
2013-07-14 16:02:03 +02:00
|
|
|
/**
|
|
|
|
* Return the {@link EventExecutor} which is used by this {@link CompleteFuture}.
|
|
|
|
*/
|
2013-03-05 21:41:19 +01:00
|
|
|
protected EventExecutor executor() {
|
|
|
|
return executor;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-12 01:00:54 +02:00
|
|
|
public Future<V> addListener(GenericFutureListener<? extends Future<? super V>> listener) {
|
2013-03-05 21:41:19 +01:00
|
|
|
if (listener == null) {
|
|
|
|
throw new NullPointerException("listener");
|
|
|
|
}
|
|
|
|
DefaultPromise.notifyListener(executor(), this, listener);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-12 01:00:54 +02:00
|
|
|
public Future<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
|
2013-03-05 21:41:19 +01:00
|
|
|
if (listeners == null) {
|
|
|
|
throw new NullPointerException("listeners");
|
|
|
|
}
|
2013-06-12 01:00:54 +02:00
|
|
|
for (GenericFutureListener<? extends Future<? super V>> l: listeners) {
|
2013-03-05 21:41:19 +01:00
|
|
|
if (l == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DefaultPromise.notifyListener(executor(), this, l);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-12 01:00:54 +02:00
|
|
|
public Future<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
|
2013-03-05 21:41:19 +01:00
|
|
|
// NOOP
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-12 01:00:54 +02:00
|
|
|
public Future<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
|
2013-03-05 21:41:19 +01:00
|
|
|
// NOOP
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-03-18 14:18:31 +01:00
|
|
|
public Future<V> await() throws InterruptedException {
|
2013-03-05 21:41:19 +01:00
|
|
|
if (Thread.interrupted()) {
|
|
|
|
throw new InterruptedException();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
|
|
|
|
if (Thread.interrupted()) {
|
|
|
|
throw new InterruptedException();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-03-18 14:18:31 +01:00
|
|
|
public Future<V> sync() throws InterruptedException {
|
2013-03-05 21:41:19 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-03-18 14:18:31 +01:00
|
|
|
public Future<V> syncUninterruptibly() {
|
2013-03-05 21:41:19 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean await(long timeoutMillis) throws InterruptedException {
|
|
|
|
if (Thread.interrupted()) {
|
|
|
|
throw new InterruptedException();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-03-18 14:18:31 +01:00
|
|
|
public Future<V> awaitUninterruptibly() {
|
2013-03-05 21:41:19 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean awaitUninterruptibly(long timeoutMillis) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDone() {
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-11 10:46:21 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCancellable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCancelled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean cancel(boolean mayInterruptIfRunning) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-05 21:41:19 +01:00
|
|
|
}
|