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 static org.jboss.netty.channel.Channels.*;
    19
    20  /**
    21   * The default {@link WriteCompletionEvent} implementation.
    22   *
    23   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    24   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    25   *
    26   * @version $Rev: 2210 $, $Date: 2010-03-04 08:11:39 +0900 (Thu, 04 Mar 2010) $
    27   */
    28  public class DefaultWriteCompletionEvent implements WriteCompletionEvent {
    29
    30      private final Channel channel;
    31      private final long writtenAmount;
    32
    33      /**
    34       * Creates a new instance.
    35       */
    36      public DefaultWriteCompletionEvent(Channel channel, long writtenAmount) {
    37          if (channel == null) {
    38              throw new NullPointerException("channel");
    39          }
    40          if (writtenAmount <= 0) {
    41              throw new IllegalArgumentException(
    42                      "writtenAmount must be a positive integer: " + writtenAmount);
    43          }
    44
    45          this.channel = channel;
    46          this.writtenAmount = writtenAmount;
    47      }
    48
    49      public Channel getChannel() {
    50          return channel;
    51      }
    52
    53      public ChannelFuture getFuture() {
    54          return succeededFuture(getChannel());
    55      }
    56
    57      public long getWrittenAmount() {
    58          return writtenAmount;
    59      }
    60
    61      @Override
    62      public String toString() {
    63          String channelString = getChannel().toString();
    64          StringBuilder buf = new StringBuilder(channelString.length() + 32);
    65          buf.append(channelString);
    66          buf.append(" WRITTEN_AMOUNT: ");
    67          buf.append(getWrittenAmount());
    68          return buf.toString();
    69      }
    70  }