aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BasePipelineFactory.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-05 20:35:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-05 20:35:56 +1200
commitc34ab02bb5943ecac8a143127967c29bda45647c (patch)
treedb684ab347eee873849040e2024cdbe260e97b0d /src/org/traccar/BasePipelineFactory.java
parentf0d1a5df7aecf1237609200d3ecb7cdd3d0abcab (diff)
downloadtrackermap-server-c34ab02bb5943ecac8a143127967c29bda45647c.tar.gz
trackermap-server-c34ab02bb5943ecac8a143127967c29bda45647c.tar.bz2
trackermap-server-c34ab02bb5943ecac8a143127967c29bda45647c.zip
Use wrappers for network message handling
Diffstat (limited to 'src/org/traccar/BasePipelineFactory.java')
-rw-r--r--src/org/traccar/BasePipelineFactory.java20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 2cf4333f5..6269fb8cc 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -21,7 +21,9 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.channel.socket.DatagramChannel;
@@ -226,11 +228,11 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
}
}
- protected abstract void addProtocolHandlers(ChannelPipeline pipeline);
+ protected abstract void addProtocolHandlers(PipelineBuilder pipeline);
@Override
protected void initChannel(Channel channel) throws Exception {
- ChannelPipeline pipeline = channel.pipeline();
+ final ChannelPipeline pipeline = channel.pipeline();
if (timeout > 0 && !server.isDatagram()) {
pipeline.addLast("idleHandler", new IdleStateHandler(timeout, 0, 0));
}
@@ -240,7 +242,19 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
pipeline.addLast("logger", new StandardLoggingHandler());
}
- addProtocolHandlers(pipeline);
+ addProtocolHandlers(new PipelineBuilder() {
+ @Override
+ public void addLast(String name, ChannelHandler handler) {
+ if (!(handler instanceof BaseProtocolDecoder || handler instanceof BaseProtocolEncoder)) {
+ if (handler instanceof ChannelInboundHandler) {
+ handler = new WrapperInboundHandler((ChannelInboundHandler) handler);
+ } else {
+ handler = new WrapperOutboundHandler((ChannelOutboundHandler) handler);
+ }
+ }
+ pipeline.addLast(name, handler);
+ }
+ });
if (geolocationHandler != null) {
pipeline.addLast("location", geolocationHandler);