org.freeswitch.esl.client.internal.debug
Class ExecutionHandler

java.lang.Object
  extended by org.freeswitch.esl.client.internal.debug.ExecutionHandler
All Implemented Interfaces:
ChannelDownstreamHandler, ChannelHandler, ChannelUpstreamHandler, ExternalResourceReleasable

public class ExecutionHandler
extends Object
implements ChannelUpstreamHandler, ChannelDownstreamHandler, ExternalResourceReleasable

Forwards an upstream ChannelEvent to an Executor.

You can implement various thread model by adding this handler to a ChannelPipeline. The most common use case of this handler is to add a ExecutionHandler which was specified with OrderedMemoryAwareThreadPoolExecutor:

 ChannelPipeline pipeline = ...;
 pipeline.addLast("decoder", new MyProtocolDecoder());
 pipeline.addLast("encoder", new MyProtocolEncoder());

 // HERE
 pipeline.addLast("executor", new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)));

 pipeline.addLast("handler", new MyBusinessLogicHandler());
 
to utilize more processors to handle ChannelEvents. You can also use other Executor implementation than the recommended OrderedMemoryAwareThreadPoolExecutor.

Version:
$Rev: 1685 $, $Date: 2009-08-28 16:15:49 +0900 (금, 28 8 2009) $
Author:
The Netty Project (netty-dev@lists.jboss.org), Trustin Lee (tlee@redhat.com)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
 
Constructor Summary
ExecutionHandler(Executor executor)
          Creates a new instance with the specified Executor.
 
Method Summary
 Executor getExecutor()
          Returns the Executor which was specified with the constructor.
 void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
           
 void handleUpstream(ChannelHandlerContext context, ChannelEvent e)
           
 void releaseExternalResources()
          Shuts down the Executor which was specified with the constructor and wait for its termination.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExecutionHandler

public ExecutionHandler(Executor executor)
Creates a new instance with the specified Executor. Specify an OrderedMemoryAwareThreadPoolExecutor if unsure.

Method Detail

getExecutor

public Executor getExecutor()
Returns the Executor which was specified with the constructor.


releaseExternalResources

public void releaseExternalResources()
Shuts down the Executor which was specified with the constructor and wait for its termination.

Specified by:
releaseExternalResources in interface ExternalResourceReleasable

handleUpstream

public void handleUpstream(ChannelHandlerContext context,
                           ChannelEvent e)
                    throws Exception
Specified by:
handleUpstream in interface ChannelUpstreamHandler
Throws:
Exception

handleDownstream

public void handleDownstream(ChannelHandlerContext ctx,
                             ChannelEvent e)
                      throws Exception
Specified by:
handleDownstream in interface ChannelDownstreamHandler
Throws:
Exception


Copyright © 2009-2010 david varnes. All Rights Reserved.