aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-10-24 14:10:00 +0400
committerAnton Tananaev <anton.tananaev@gmail.com>2018-10-24 14:10:00 +0400
commitd7f4e49f89a878008101b58eaa207f89068cabba (patch)
tree507c15da107559dea485f8b040ca1ccfce8cab57 /src
parent3a008c877056234e525587dbb339e5c950748b9a (diff)
downloadtraccar-server-d7f4e49f89a878008101b58eaa207f89068cabba.tar.gz
traccar-server-d7f4e49f89a878008101b58eaa207f89068cabba.tar.bz2
traccar-server-d7f4e49f89a878008101b58eaa207f89068cabba.zip
Search unwrapped handlers by class
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java16
-rw-r--r--src/org/traccar/BaseProtocol.java2
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java2
-rw-r--r--src/org/traccar/MainEventHandler.java5
-rw-r--r--src/org/traccar/WrapperInboundHandler.java4
-rw-r--r--src/org/traccar/WrapperOutboundHandler.java4
6 files changed, 28 insertions, 5 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index d511af214..401c42d8b 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -44,6 +44,7 @@ import org.traccar.processing.ComputedAttributesHandler;
import org.traccar.processing.CopyAttributesHandler;
import java.net.InetSocketAddress;
+import java.util.Map;
public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
@@ -241,6 +242,21 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
}
}
+ public static <T extends ChannelHandler> T getHandler(ChannelPipeline pipeline, Class<T> clazz) {
+ for (Map.Entry<String, ChannelHandler> handlerEntry : pipeline) {
+ ChannelHandler handler = handlerEntry.getValue();
+ if (handler instanceof WrapperInboundHandler) {
+ handler = ((WrapperInboundHandler) handler).getWrappedHandler();
+ } else if (handler instanceof WrapperOutboundHandler) {
+ handler = ((WrapperOutboundHandler) handler).getWrappedHandler();
+ }
+ if (clazz.isAssignableFrom(handler.getClass())) {
+ return (T) handler;
+ }
+ }
+ return null;
+ }
+
@Override
protected void initChannel(Channel channel) throws Exception {
final ChannelPipeline pipeline = channel.pipeline();
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index 4ece8f848..c0fd1e27f 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -93,7 +93,7 @@ public abstract class BaseProtocol implements Protocol {
activeDevice.write(command);
} else if (command.getType().equals(Command.TYPE_CUSTOM)) {
String data = command.getString(Command.KEY_DATA);
- if (activeDevice.getChannel().pipeline().get(StringEncoder.class) != null) {
+ if (BasePipelineFactory.getHandler(activeDevice.getChannel().pipeline(), StringEncoder.class) != null) {
activeDevice.write(data);
} else {
activeDevice.write(Unpooled.wrappedBuffer(DataConverter.parseHex(data)));
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 8f495900a..7d840960b 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -141,7 +141,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) {
- if (channel != null && channel.pipeline().get(HttpRequestDecoder.class) != null
+ if (channel != null && BasePipelineFactory.getHandler(channel.pipeline(), HttpRequestDecoder.class) != null
|| config.getBoolean("decoder.ignoreSessionCache")) {
long deviceId = findDeviceId(remoteAddress, uniqueIds);
if (deviceId != 0) {
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 4d54a6fe6..311a41f34 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -98,9 +98,8 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
LOGGER.info(formatChannel(ctx.channel()) + " disconnected");
closeChannel(ctx.channel());
- BaseProtocolDecoder protocolDecoder = ctx.pipeline().get(BaseProtocolDecoder.class);
- if (ctx.pipeline().get(HttpRequestDecoder.class) == null
- && !connectionlessProtocols.contains(protocolDecoder.getProtocolName())) {
+ if (BasePipelineFactory.getHandler(ctx.pipeline(), HttpRequestDecoder.class) == null
+ && !connectionlessProtocols.contains(ctx.pipeline().get(BaseProtocolDecoder.class).getProtocolName())) {
Context.getConnectionManager().removeActiveDevice(ctx.channel());
}
}
diff --git a/src/org/traccar/WrapperInboundHandler.java b/src/org/traccar/WrapperInboundHandler.java
index f81f97108..ca33d021f 100644
--- a/src/org/traccar/WrapperInboundHandler.java
+++ b/src/org/traccar/WrapperInboundHandler.java
@@ -22,6 +22,10 @@ public class WrapperInboundHandler implements ChannelInboundHandler {
private ChannelInboundHandler handler;
+ public ChannelInboundHandler getWrappedHandler() {
+ return handler;
+ }
+
public WrapperInboundHandler(ChannelInboundHandler handler) {
this.handler = handler;
}
diff --git a/src/org/traccar/WrapperOutboundHandler.java b/src/org/traccar/WrapperOutboundHandler.java
index 99afd9774..0136c5b22 100644
--- a/src/org/traccar/WrapperOutboundHandler.java
+++ b/src/org/traccar/WrapperOutboundHandler.java
@@ -25,6 +25,10 @@ public class WrapperOutboundHandler implements ChannelOutboundHandler {
private ChannelOutboundHandler handler;
+ public ChannelOutboundHandler getWrappedHandler() {
+ return handler;
+ }
+
public WrapperOutboundHandler(ChannelOutboundHandler handler) {
this.handler = handler;
}