Skip to content

Commit 8f5150d

Browse files
committed
ExecutionHandler added to pipeline to improve client performance.
1 parent 07bcd22 commit 8f5150d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.menacheri.jetclient.handlers.netty;
2+
3+
import org.jboss.netty.handler.execution.ExecutionHandler;
4+
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
5+
6+
/**
7+
* Creates an ExecutionHandler instance as a singleton.
8+
* @author Abraham Menacherry
9+
*
10+
*/
11+
public class ExecutionHandlerSingleton
12+
{
13+
private static ExecutionHandler EXECUTION_HANDLER;
14+
15+
public synchronized static ExecutionHandler getExecutionHandler()
16+
{
17+
if(null == EXECUTION_HANDLER){
18+
EXECUTION_HANDLER = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576));
19+
}
20+
return EXECUTION_HANDLER;
21+
}
22+
23+
}

jetclient/src/main/java/org/menacheri/jetclient/handlers/netty/TCPPipelineFactory.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.jboss.netty.channel.Channels;
66
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
77
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
8+
import org.jboss.netty.handler.execution.ExecutionHandler;
89
import org.menacheri.jetclient.app.ISession;
910
import org.menacheri.jetclient.communication.IMessageBuffer;
1011
import org.menacheri.jetclient.event.IEvent;
@@ -38,20 +39,29 @@ public class TCPPipelineFactory implements ChannelPipelineFactory
3839
* {@link IEvent} instance to the next decoder/handler in the chain.
3940
*/
4041
private static final MessageBufferEventEncoder EVENT_ENCODER = new MessageBufferEventEncoder();
42+
private final ExecutionHandler executionHandler;
4143
/**
4244
* Used to transmit the message to {@link ISession}.
4345
*/
4446
private final DefaultToClientHandler defaultToClientHandler;
4547

4648
public TCPPipelineFactory(ISession session)
4749
{
48-
this(new DefaultToClientHandler(session));
50+
this(new DefaultToClientHandler(session),null);
4951
}
5052

5153
public TCPPipelineFactory(
52-
final DefaultToClientHandler defaultToClientHandler)
54+
final DefaultToClientHandler defaultToClientHandler, final ExecutionHandler executionHandler)
5355
{
5456
this.defaultToClientHandler = defaultToClientHandler;
57+
if(null == executionHandler)
58+
{
59+
this.executionHandler = ExecutionHandlerSingleton.getExecutionHandler();
60+
}
61+
else
62+
{
63+
this.executionHandler = executionHandler;
64+
}
5565
}
5666

5767
@Override
@@ -60,6 +70,7 @@ public ChannelPipeline getPipeline() throws Exception
6070
ChannelPipeline pipeline = Channels.pipeline();
6171
pipeline.addLast("lengthDecoder", new LengthFieldBasedFrameDecoder(
6272
Integer.MAX_VALUE, 0, 2, 0, 2));
73+
pipeline.addLast("executionHandler", executionHandler);
6374
pipeline.addLast("eventDecoder", EVENT_DECODER);
6475
pipeline.addLast(DefaultToClientHandler.getName(),
6576
defaultToClientHandler);

jetclient/src/main/java/org/menacheri/jetclient/handlers/netty/UDPPipelineFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class UDPPipelineFactory implements ChannelPipelineFactory
3030
static ChannelPipeline init()
3131
{
3232
ChannelPipeline pipeline = Channels.pipeline();
33+
pipeline.addLast("executionHandler", ExecutionHandlerSingleton.getExecutionHandler());
3334
pipeline.addLast("eventDecoder", EVENT_DECODER);
3435
pipeline.addLast("eventEncoder", EVENT_ENCODER);
3536
pipeline.addLast("UDPUpstreamHandler",UDP_UPSTREAM_HANDLER);

0 commit comments

Comments
 (0)