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.handler.execution;
    17
    18  import java.util.concurrent.Executor;
    19
    20  import org.jboss.netty.channel.ChannelEvent;
    21  import org.jboss.netty.channel.ChannelHandlerContext;
    22  import org.jboss.netty.util.EstimatableObjectWrapper;
    23
    24  /**
    25   * a {@link Runnable} which sends the specified {@link ChannelEvent} upstream.
    26   * Most users will not see this type at all because it is used by
    27   * {@link Executor} implementors only
    28   *
    29   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    30   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    31   *
    32   * @version $Rev: 2187 $, $Date: 2010-02-19 17:43:13 +0900 (Fri, 19 Feb 2010) $
    33   *
    34   */
    35  public class ChannelEventRunnable implements Runnable, EstimatableObjectWrapper {
    36
    37      private final ChannelHandlerContext ctx;
    38      private final ChannelEvent e;
    39      int estimatedSize;
    40
    41      /**
    42       * Creates a {@link Runnable} which sends the specified {@link ChannelEvent}
    43       * upstream via the specified {@link ChannelHandlerContext}.
    44       */
    45      public ChannelEventRunnable(ChannelHandlerContext ctx, ChannelEvent e) {
    46          this.ctx = ctx;
    47          this.e = e;
    48      }
    49
    50      /**
    51       * Returns the {@link ChannelHandlerContext} which will be used to
    52       * send the {@link ChannelEvent} upstream.
    53       */
    54      public ChannelHandlerContext getContext() {
    55          return ctx;
    56      }
    57
    58      /**
    59       * Returns the {@link ChannelEvent} which will be sent upstream.
    60       */
    61      public ChannelEvent getEvent() {
    62          return e;
    63      }
    64
    65      /**
    66       * Sends the event upstream.
    67       */
    68      public void run() {
    69          ctx.sendUpstream(e);
    70      }
    71
    72      public Object unwrap() {
    73          return e;
    74      }
    75  }