View Javadoc

    1   /*
    2    * Copyright 2009 Red Hat, Inc.
    3    *
    4    * Red Hat licenses this file to you under the Apache License, version 2.0
    5    * (the "License"); you may not use this file except in compliance with the
    6    * License.  You may obtain a copy of the License at:
    7    *
    8    *    http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    13   * License for the specific language governing permissions and limitations
    14   * under the License.
    15   */
    16  package org.jboss.netty.channel;
    17
    18  import java.util.concurrent.TimeUnit;
    19
    20  import org.jboss.netty.logging.InternalLogger;
    21  import org.jboss.netty.logging.InternalLoggerFactory;
    22
    23  /**
    24   * A skeletal {@link ChannelFuture} implementation which represents a
    25   * {@link ChannelFuture} which has been completed already.
    26   *
    27   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    28   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    29   *
    30   * @version $Rev: 2192 $, $Date: 2010-02-19 18:58:38 +0900 (Fri, 19 Feb 2010) $
    31   */
    32  public abstract class CompleteChannelFuture implements ChannelFuture {
    33
    34      private static final InternalLogger logger =
    35          InternalLoggerFactory.getInstance(CompleteChannelFuture.class);
    36
    37      private final Channel channel;
    38
    39      /**
    40       * Creates a new instance.
    41       *
    42       * @param channel the {@link Channel} associated with this future
    43       */
    44      protected CompleteChannelFuture(Channel channel) {
    45          if (channel == null) {
    46              throw new NullPointerException("channel");
    47          }
    48          this.channel = channel;
    49      }
    50
    51      public void addListener(ChannelFutureListener listener) {
    52          try {
    53              listener.operationComplete(this);
    54          } catch (Throwable t) {
    55              logger.warn(
    56                      "An exception was thrown by " +
    57                      ChannelFutureListener.class.getSimpleName() + ".", t);
    58          }
    59      }
    60
    61      public void removeListener(ChannelFutureListener listener) {
    62          // NOOP
    63      }
    64
    65      public ChannelFuture await() throws InterruptedException {
    66          if (Thread.interrupted()) {
    67              throw new InterruptedException();
    68          }
    69          return this;
    70      }
    71
    72      public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
    73          if (Thread.interrupted()) {
    74              throw new InterruptedException();
    75          }
    76          return true;
    77      }
    78
    79      public boolean await(long timeoutMillis) throws InterruptedException {
    80          if (Thread.interrupted()) {
    81              throw new InterruptedException();
    82          }
    83          return true;
    84      }
    85
    86      public ChannelFuture awaitUninterruptibly() {
    87          return this;
    88      }
    89
    90      public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
    91          return true;
    92      }
    93
    94      public boolean awaitUninterruptibly(long timeoutMillis) {
    95          return true;
    96      }
    97
    98      public Channel getChannel() {
    99          return channel;
    100     }
    101
    102     public boolean isDone() {
    103         return true;
    104     }
    105
    106     public boolean setProgress(long amount, long current, long total) {
    107         return false;
    108     }
    109
    110     public boolean setFailure(Throwable cause) {
    111         return false;
    112     }
    113
    114     public boolean setSuccess() {
    115         return false;
    116     }
    117
    118     public boolean cancel() {
    119         return false;
    120     }
    121
    122     public boolean isCancelled() {
    123         return false;
    124     }
    125 }