aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-02 22:12:44 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-02 22:12:44 +1200
commit06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07 (patch)
tree8f5d7b71ca3fa39448e93b3d0652a7fa8d496932
parent5a9811c3771d92832c9bba718b5ec935844978e8 (diff)
downloadtrackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.tar.gz
trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.tar.bz2
trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.zip
Start Netty 4 migration
-rw-r--r--pom.xml6
-rw-r--r--src/org/traccar/BaseDataHandler.java18
-rw-r--r--src/org/traccar/BaseHttpProtocolDecoder.java13
-rw-r--r--src/org/traccar/BasePipelineFactory.java102
-rw-r--r--src/org/traccar/BaseProtocol.java10
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java8
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java20
-rw-r--r--src/org/traccar/CharacterDelimiterFrameDecoder.java20
-rw-r--r--src/org/traccar/DistanceHandler.java2
-rw-r--r--src/org/traccar/EngineHoursHandler.java2
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java45
-rw-r--r--src/org/traccar/FilterHandler.java2
-rw-r--r--src/org/traccar/GeocoderHandler.java32
-rw-r--r--src/org/traccar/GeolocationHandler.java30
-rw-r--r--src/org/traccar/GlobalChannelFactory.java40
-rw-r--r--src/org/traccar/GlobalTimer.java4
-rw-r--r--src/org/traccar/HemisphereHandler.java7
-rw-r--r--src/org/traccar/MainEventHandler.java58
-rw-r--r--src/org/traccar/MotionHandler.java2
-rw-r--r--src/org/traccar/RemoteAddressHandler.java9
-rw-r--r--src/org/traccar/ServerManager.java5
-rw-r--r--src/org/traccar/TrackerServer.java93
-rw-r--r--src/org/traccar/api/CorsResponseFilter.java24
-rw-r--r--src/org/traccar/database/ActiveDevice.java6
-rw-r--r--src/org/traccar/database/ConnectionManager.java8
-rw-r--r--src/org/traccar/database/MediaManager.java6
-rw-r--r--src/org/traccar/events/AlertEventHandler.java2
-rw-r--r--src/org/traccar/events/CommandResultEventHandler.java2
-rw-r--r--src/org/traccar/events/DriverEventHandler.java2
-rw-r--r--src/org/traccar/events/FuelDropEventHandler.java2
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java2
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java2
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java2
-rw-r--r--src/org/traccar/events/MotionEventHandler.java2
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java2
-rw-r--r--src/org/traccar/helper/BcdUtil.java8
-rw-r--r--src/org/traccar/helper/BitBuffer.java12
-rw-r--r--src/org/traccar/helper/Log.java78
-rw-r--r--src/org/traccar/helper/StringFinder.java9
-rw-r--r--src/org/traccar/processing/ComputedAttributesHandler.java2
-rw-r--r--src/org/traccar/processing/CopyAttributesHandler.java2
-rw-r--r--src/org/traccar/protocol/Ardi01Protocol.java11
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gps103Protocol.java12
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java8
-rw-r--r--src/org/traccar/protocol/Gt02Protocol.java7
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java13
-rw-r--r--src/org/traccar/smpp/SmppClient.java2
-rw-r--r--test/org/traccar/FilterHandlerTest.java14
-rw-r--r--test/org/traccar/ProtocolTest.java37
-rw-r--r--test/org/traccar/helper/BcdUtilTest.java8
-rw-r--r--test/org/traccar/helper/ChecksumTest.java26
-rw-r--r--test/org/traccar/helper/StringFinderTest.java11
53 files changed, 362 insertions, 490 deletions
diff --git a/pom.xml b/pom.xml
index c9c1b9bd6..bf2aac74a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,8 +70,8 @@
</dependency>
<dependency>
<groupId>io.netty</groupId>
- <artifactId>netty</artifactId>
- <version>3.10.6.Final</version>
+ <artifactId>netty-all</artifactId>
+ <version>4.1.25.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -171,7 +171,7 @@
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>ch-smpp</artifactId>
- <version>5.0.9</version>
+ <version>6.0.0-netty4-beta-3</version>
</dependency>
</dependencies>
diff --git a/src/org/traccar/BaseDataHandler.java b/src/org/traccar/BaseDataHandler.java
index 0c71a6a4d..8a461cc19 100644
--- a/src/org/traccar/BaseDataHandler.java
+++ b/src/org/traccar/BaseDataHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,21 +15,19 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
import org.traccar.model.Position;
-public abstract class BaseDataHandler extends OneToOneDecoder {
+public abstract class BaseDataHandler extends ChannelInboundHandlerAdapter {
@Override
- protected final Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
-
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Position) {
- return handlePosition((Position) msg);
+ ctx.fireChannelRead(handlePosition((Position) msg));
+ } else {
+ super.channelRead(ctx, msg);
}
-
- return msg;
}
protected abstract Position handlePosition(Position position);
diff --git a/src/org/traccar/BaseHttpProtocolDecoder.java b/src/org/traccar/BaseHttpProtocolDecoder.java
index 934a1b81e..dbc6b087b 100644
--- a/src/org/traccar/BaseHttpProtocolDecoder.java
+++ b/src/org/traccar/BaseHttpProtocolDecoder.java
@@ -15,16 +15,9 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpHeaders;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
+public abstract class BaseHttpProtocolDecoder /*extends BaseProtocolDecoder*/ { // TODO implement later
-public abstract class BaseHttpProtocolDecoder extends BaseProtocolDecoder {
-
- public BaseHttpProtocolDecoder(Protocol protocol) {
+ /*public BaseHttpProtocolDecoder(Protocol protocol) {
super(protocol);
}
@@ -34,6 +27,6 @@ public abstract class BaseHttpProtocolDecoder extends BaseProtocolDecoder {
response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
channel.write(response);
}
- }
+ }*/
}
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index b0de67a15..0b076a834 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,20 +15,16 @@
*/
package org.traccar;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandler;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.DownstreamMessageEvent;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelHandler;
-import org.jboss.netty.handler.logging.LoggingHandler;
-import org.jboss.netty.handler.timeout.IdleStateHandler;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.ChannelPromise;
+import io.netty.handler.timeout.IdleStateHandler;
import org.traccar.events.CommandResultEventHandler;
import org.traccar.events.DriverEventHandler;
import org.traccar.events.FuelDropEventHandler;
@@ -44,7 +40,7 @@ import org.traccar.processing.CopyAttributesHandler;
import java.net.InetSocketAddress;
-public abstract class BasePipelineFactory implements ChannelPipelineFactory {
+public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private final TrackerServer server;
private int timeout;
@@ -70,7 +66,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private MaintenanceEventHandler maintenanceEventHandler;
private DriverEventHandler driverEventHandler;
- private static final class OpenChannelHandler extends SimpleChannelHandler {
+ private static final class OpenChannelHandler extends ChannelDuplexHandler {
private final TrackerServer server;
@@ -79,41 +75,51 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
}
@Override
- public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
- server.getChannelGroup().add(e.getChannel());
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ super.channelActive(ctx);
+ server.getChannelGroup().add(ctx.channel());
}
+
}
- private static class StandardLoggingHandler extends LoggingHandler {
+ private static class StandardLoggingHandler extends ChannelDuplexHandler {
@Override
- public void log(ChannelEvent e) {
- if (e instanceof MessageEvent) {
- MessageEvent event = (MessageEvent) e;
- StringBuilder msg = new StringBuilder();
-
- msg.append("[").append(String.format("%08X", e.getChannel().getId())).append(": ");
- msg.append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort());
- if (e instanceof DownstreamMessageEvent) {
- msg.append(" > ");
- } else {
- msg.append(" < ");
- }
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ log(ctx, false, msg);
+ super.channelRead(ctx, msg);
+ }
- if (event.getRemoteAddress() != null) {
- msg.append(((InetSocketAddress) event.getRemoteAddress()).getHostString());
- } else {
- msg.append("null");
- }
- msg.append("]");
+ @Override
+ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
+ log(ctx, true, msg);
+ super.write(ctx, msg, promise);
+ }
- if (event.getMessage() instanceof ChannelBuffer) {
- msg.append(" HEX: ");
- msg.append(ChannelBuffers.hexDump((ChannelBuffer) event.getMessage()));
- }
+ public void log(ChannelHandlerContext ctx, boolean downstream, Object o) {
+ StringBuilder message = new StringBuilder();
- Log.debug(msg.toString());
+ message.append("[").append(ctx.channel().id().asShortText()).append(": ");
+ message.append(((InetSocketAddress) ctx.channel().localAddress()).getPort());
+ if (downstream) {
+ message.append(" > ");
+ } else {
+ message.append(" < ");
}
+
+ if (ctx.channel().remoteAddress() != null) {
+ message.append(((InetSocketAddress) ctx.channel().remoteAddress()).getHostString());
+ } else {
+ message.append("null");
+ }
+ message.append("]");
+
+ if (o instanceof ByteBuf) {
+ message.append(" HEX: ");
+ message.append(ByteBufUtil.hexDump((ByteBuf) o));
+ }
+
+ Log.debug(message.toString());
}
}
@@ -189,10 +195,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
@Override
- public ChannelPipeline getPipeline() {
- ChannelPipeline pipeline = Channels.pipeline();
- if (timeout > 0 && !server.isConnectionless()) {
- pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), timeout, 0, 0));
+ protected void initChannel(Channel channel) throws Exception {
+ ChannelPipeline pipeline = channel.pipeline();
+ if (timeout > 0 && !server.isDatagram()) {
+ pipeline.addLast("idleHandler", new IdleStateHandler(timeout, 0, 0));
}
pipeline.addLast("openHandler", new OpenChannelHandler(server));
if (Context.isLoggerEnabled()) {
@@ -288,7 +294,6 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
}
pipeline.addLast("mainHandler", new MainEventHandler());
- return pipeline;
}
private void addDynamicHandlers(ChannelPipeline pipeline) {
@@ -303,4 +308,5 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
}
}
}
+
}
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index 07adbea5e..8dbec362f 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,8 +15,8 @@
*/
package org.traccar;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.buffer.Unpooled;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.database.ActiveDevice;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
@@ -76,10 +76,10 @@ 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().getPipeline().get(StringEncoder.class) != null) {
+ if (activeDevice.getChannel().pipeline().get(StringEncoder.class) != null) {
activeDevice.write(data);
} else {
- activeDevice.write(ChannelBuffers.wrappedBuffer(DataConverter.parseHex(data)));
+ activeDevice.write(Unpooled.wrappedBuffer(DataConverter.parseHex(data)));
}
} else {
throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName());
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 3ea1208ca..de6c00d7c 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -15,9 +15,8 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.socket.DatagramChannel;
-import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
+import io.netty.channel.Channel;
+import io.netty.handler.codec.http.HttpRequestDecoder;
import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Device;
@@ -25,6 +24,7 @@ import org.traccar.model.Position;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.nio.channels.DatagramChannel;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -145,7 +145,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) {
- if (channel != null && channel.getPipeline().get(HttpRequestDecoder.class) != null
+ if (channel != null && channel.pipeline().get(HttpRequestDecoder.class) != null
|| Context.getConfig().getBoolean("decoder.ignoreSessionCache")) {
long deviceId = findDeviceId(remoteAddress, uniqueIds);
if (deviceId != 0) {
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
index 18544fd28..db4f2cbbf 100644
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ b/src/org/traccar/BaseProtocolEncoder.java
@@ -15,14 +15,15 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelOutboundHandlerAdapter;
+import io.netty.channel.ChannelPromise;
import org.traccar.helper.Log;
import org.traccar.model.Command;
import org.traccar.model.Device;
-public abstract class BaseProtocolEncoder extends OneToOneEncoder {
+public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter {
protected String getUniqueId(long deviceId) {
return Context.getIdentityManager().getById(deviceId).getUniqueId();
@@ -41,15 +42,14 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
}
@Override
- protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
+ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof Command) {
Command command = (Command) msg;
- Object encodedCommand = encodeCommand(channel, command);
+ Object encodedCommand = encodeCommand(ctx.channel(), command);
- // Log command
StringBuilder s = new StringBuilder();
- s.append(String.format("[%08X] ", channel.getId()));
+ s.append("[").append(ctx.channel().id().asShortText()).append("] ");
s.append("id: ").append(getUniqueId(command.getDeviceId())).append(", ");
s.append("command type: ").append(command.getType()).append(" ");
if (encodedCommand != null) {
@@ -59,10 +59,10 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
}
Log.info(s.toString());
- return encodedCommand;
+ super.write(ctx, encodedCommand, promise);
}
- return msg;
+ super.write(ctx, msg, promise);
}
protected Object encodeCommand(Channel channel, Command command) {
diff --git a/src/org/traccar/CharacterDelimiterFrameDecoder.java b/src/org/traccar/CharacterDelimiterFrameDecoder.java
index d71974e78..5175f9b37 100644
--- a/src/org/traccar/CharacterDelimiterFrameDecoder.java
+++ b/src/org/traccar/CharacterDelimiterFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,27 +15,27 @@
*/
package org.traccar;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.handler.codec.DelimiterBasedFrameDecoder;
public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder {
- private static ChannelBuffer createDelimiter(char delimiter) {
+ private static ByteBuf createDelimiter(char delimiter) {
byte[] buf = {(byte) delimiter};
- return ChannelBuffers.wrappedBuffer(buf);
+ return Unpooled.wrappedBuffer(buf);
}
- private static ChannelBuffer createDelimiter(String delimiter) {
+ private static ByteBuf createDelimiter(String delimiter) {
byte[] buf = new byte[delimiter.length()];
for (int i = 0; i < delimiter.length(); i++) {
buf[i] = (byte) delimiter.charAt(i);
}
- return ChannelBuffers.wrappedBuffer(buf);
+ return Unpooled.wrappedBuffer(buf);
}
- private static ChannelBuffer[] convertDelimiters(String[] delimiters) {
- ChannelBuffer[] result = new ChannelBuffer[delimiters.length];
+ private static ByteBuf[] convertDelimiters(String[] delimiters) {
+ ByteBuf[] result = new ByteBuf[delimiters.length];
for (int i = 0; i < delimiters.length; i++) {
result[i] = createDelimiter(delimiters[i]);
}
diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java
index 295bc3b29..657f74edf 100644
--- a/src/org/traccar/DistanceHandler.java
+++ b/src/org/traccar/DistanceHandler.java
@@ -16,12 +16,14 @@
*/
package org.traccar;
+import io.netty.channel.ChannelHandler;
import org.traccar.helper.DistanceCalculator;
import org.traccar.model.Position;
import java.math.BigDecimal;
import java.math.RoundingMode;
+@ChannelHandler.Sharable
public class DistanceHandler extends BaseDataHandler {
private final boolean filter;
diff --git a/src/org/traccar/EngineHoursHandler.java b/src/org/traccar/EngineHoursHandler.java
index 41e4dd116..c9fbc186c 100644
--- a/src/org/traccar/EngineHoursHandler.java
+++ b/src/org/traccar/EngineHoursHandler.java
@@ -16,8 +16,10 @@
*/
package org.traccar;
+import io.netty.channel.ChannelHandler;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class EngineHoursHandler extends BaseDataHandler {
@Override
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index 75a24212f..6a6a0fc4d 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,11 @@
*/
package org.traccar;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
import org.traccar.helper.DataConverter;
import org.traccar.model.Position;
@@ -30,14 +27,14 @@ import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
-public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
+public abstract class ExtendedObjectDecoder extends ChannelInboundHandlerAdapter {
private void saveOriginal(Object decodedMessage, Object originalMessage) {
if (Context.getConfig().getBoolean("database.saveOriginal") && decodedMessage instanceof Position) {
Position position = (Position) decodedMessage;
- if (originalMessage instanceof ChannelBuffer) {
- ChannelBuffer buf = (ChannelBuffer) originalMessage;
- position.set(Position.KEY_ORIGINAL, ChannelBuffers.hexDump(buf, 0, buf.writerIndex()));
+ if (originalMessage instanceof ByteBuf) {
+ ByteBuf buf = (ByteBuf) originalMessage;
+ position.set(Position.KEY_ORIGINAL, ByteBufUtil.hexDump(buf));
} else if (originalMessage instanceof String) {
position.set(Position.KEY_ORIGINAL, DataConverter.printHex(
((String) originalMessage).getBytes(StandardCharsets.US_ASCII)));
@@ -46,32 +43,24 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
}
@Override
- public void handleUpstream(
- ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
- if (!(evt instanceof MessageEvent)) {
- ctx.sendUpstream(evt);
- return;
- }
-
- MessageEvent e = (MessageEvent) evt;
- Object originalMessage = e.getMessage();
- Object decodedMessage = decode(e.getChannel(), e.getRemoteAddress(), originalMessage);
- onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage, decodedMessage);
+ public void channelRead(ChannelHandlerContext ctx, Object originalMessage) throws Exception {
+ Object decodedMessage = decode(ctx.channel(), ctx.channel().remoteAddress(), originalMessage);
+ onMessageEvent(ctx.channel(), ctx.channel().remoteAddress(), originalMessage, decodedMessage);
if (originalMessage == decodedMessage) {
- ctx.sendUpstream(evt);
+ ctx.fireChannelRead(originalMessage);
} else {
if (decodedMessage == null) {
- decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
+ decodedMessage = handleEmptyMessage(ctx.channel(), ctx.channel().remoteAddress(), originalMessage);
}
if (decodedMessage != null) {
if (decodedMessage instanceof Collection) {
for (Object o : (Collection) decodedMessage) {
saveOriginal(o, originalMessage);
- Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
+ ctx.fireChannelRead(o);
}
} else {
saveOriginal(decodedMessage, originalMessage);
- Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
+ ctx.fireChannelRead(decodedMessage);
}
}
}
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index c6363813c..7ad68f386 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -15,10 +15,12 @@
*/
package org.traccar;
+import io.netty.channel.ChannelHandler;
import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class FilterHandler extends BaseDataHandler {
private boolean filterInvalid;
diff --git a/src/org/traccar/GeocoderHandler.java b/src/org/traccar/GeocoderHandler.java
index 6b55e8162..0f3ba4731 100644
--- a/src/org/traccar/GeocoderHandler.java
+++ b/src/org/traccar/GeocoderHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,16 +15,15 @@
*/
package org.traccar;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
import org.traccar.model.Position;
-public class GeocoderHandler implements ChannelUpstreamHandler {
+@ChannelHandler.Sharable
+public class GeocoderHandler extends ChannelInboundHandlerAdapter {
private final Geocoder geocoder;
private final boolean processInvalidPositions;
@@ -38,14 +37,7 @@ public class GeocoderHandler implements ChannelUpstreamHandler {
}
@Override
- public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
- if (!(evt instanceof MessageEvent)) {
- ctx.sendUpstream(evt);
- return;
- }
-
- final MessageEvent event = (MessageEvent) evt;
- Object message = event.getMessage();
+ public void channelRead(final ChannelHandlerContext ctx, Object message) throws Exception {
if (message instanceof Position) {
final Position position = (Position) message;
if (processInvalidPositions || position.getValid()) {
@@ -54,7 +46,7 @@ public class GeocoderHandler implements ChannelUpstreamHandler {
if (lastPosition != null && lastPosition.getAddress() != null
&& position.getDouble(Position.KEY_DISTANCE) <= geocoderReuseDistance) {
position.setAddress(lastPosition.getAddress());
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
return;
}
}
@@ -66,20 +58,20 @@ public class GeocoderHandler implements ChannelUpstreamHandler {
@Override
public void onSuccess(String address) {
position.setAddress(address);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
}
@Override
public void onFailure(Throwable e) {
Log.warning("Geocoding failed", e);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
}
});
} else {
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
}
} else {
- Channels.fireMessageReceived(ctx, message, event.getRemoteAddress());
+ ctx.fireChannelRead(message);
}
}
diff --git a/src/org/traccar/GeolocationHandler.java b/src/org/traccar/GeolocationHandler.java
index 346ad5904..0c204dc0b 100644
--- a/src/org/traccar/GeolocationHandler.java
+++ b/src/org/traccar/GeolocationHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,16 +15,15 @@
*/
package org.traccar;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
import org.traccar.helper.Log;
import org.traccar.geolocation.GeolocationProvider;
import org.traccar.model.Position;
-public class GeolocationHandler implements ChannelUpstreamHandler {
+@ChannelHandler.Sharable
+public class GeolocationHandler extends ChannelInboundHandlerAdapter {
private final GeolocationProvider geolocationProvider;
private final boolean processInvalidPositions;
@@ -35,14 +34,7 @@ public class GeolocationHandler implements ChannelUpstreamHandler {
}
@Override
- public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
- if (!(evt instanceof MessageEvent)) {
- ctx.sendUpstream(evt);
- return;
- }
-
- final MessageEvent event = (MessageEvent) evt;
- Object message = event.getMessage();
+ public void channelRead(final ChannelHandlerContext ctx, Object message) throws Exception {
if (message instanceof Position) {
final Position position = (Position) message;
if ((position.getOutdated() || processInvalidPositions && !position.getValid())
@@ -63,20 +55,20 @@ public class GeolocationHandler implements ChannelUpstreamHandler {
position.setSpeed(0);
position.setCourse(0);
position.set(Position.KEY_RSSI, 0);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
}
@Override
public void onFailure(Throwable e) {
Log.warning(e);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
}
});
} else {
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ ctx.fireChannelRead(position);
}
} else {
- Channels.fireMessageReceived(ctx, message, event.getRemoteAddress());
+ ctx.fireChannelRead(message);
}
}
diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java
index c5cd1a697..7bc0f4f03 100644
--- a/src/org/traccar/GlobalChannelFactory.java
+++ b/src/org/traccar/GlobalChannelFactory.java
@@ -15,42 +15,20 @@
*/
package org.traccar;
-import org.jboss.netty.channel.ChannelFactory;
-import org.jboss.netty.channel.socket.DatagramChannelFactory;
-import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
-import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
-public final class GlobalChannelFactory {
+public final class GlobalChannelFactory { // TODO rename class
- private static ChannelFactory channelFactory = null;
- private static DatagramChannelFactory datagramChannelFactory = null;
+ private static EventLoopGroup bossGroup = new NioEventLoopGroup();
+ private static EventLoopGroup workerGroup = new NioEventLoopGroup();
- private GlobalChannelFactory() {
+ public static EventLoopGroup getBossGroup() {
+ return bossGroup;
}
- public static void release() {
- if (channelFactory != null) {
- channelFactory.releaseExternalResources();
- }
- if (datagramChannelFactory != null) {
- datagramChannelFactory.releaseExternalResources();
- }
- channelFactory = null;
- datagramChannelFactory = null;
- }
-
- public static ChannelFactory getFactory() {
- if (channelFactory == null) {
- channelFactory = new NioServerSocketChannelFactory();
- }
- return channelFactory;
- }
-
- public static DatagramChannelFactory getDatagramFactory() {
- if (datagramChannelFactory == null) {
- datagramChannelFactory = new NioDatagramChannelFactory();
- }
- return datagramChannelFactory;
+ public static EventLoopGroup getWorkerGroup() {
+ return workerGroup;
}
}
diff --git a/src/org/traccar/GlobalTimer.java b/src/org/traccar/GlobalTimer.java
index 70e6e2e45..a97321ba2 100644
--- a/src/org/traccar/GlobalTimer.java
+++ b/src/org/traccar/GlobalTimer.java
@@ -15,8 +15,8 @@
*/
package org.traccar;
-import org.jboss.netty.util.HashedWheelTimer;
-import org.jboss.netty.util.Timer;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timer;
public final class GlobalTimer {
diff --git a/src/org/traccar/HemisphereHandler.java b/src/org/traccar/HemisphereHandler.java
index b1e7d3fb2..669ffd36e 100644
--- a/src/org/traccar/HemisphereHandler.java
+++ b/src/org/traccar/HemisphereHandler.java
@@ -15,11 +15,13 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandler;
import org.traccar.model.Position;
import java.net.SocketAddress;
+@ChannelHandler.Sharable
public class HemisphereHandler extends ExtendedObjectDecoder {
private int latitudeFactor;
@@ -45,8 +47,7 @@ public class HemisphereHandler extends ExtendedObjectDecoder {
}
@Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
if (msg instanceof Position) {
Position position = (Position) msg;
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 6228f3709..21b917a2d 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,24 +15,21 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.ExceptionEvent;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.socket.DatagramChannel;
-import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
-import org.jboss.netty.handler.timeout.IdleStateEvent;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.timeout.IdleStateEvent;
import org.traccar.helper.Log;
import org.traccar.model.Position;
+import java.nio.channels.DatagramChannel;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-public class MainEventHandler extends IdleStateAwareChannelHandler {
+public class MainEventHandler extends ChannelInboundHandlerAdapter {
private final Set<String> connectionlessProtocols = new HashSet<>();
@@ -44,11 +41,10 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
}
@Override
- public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ if (msg instanceof Position) {
- if (e.getMessage() != null && e.getMessage() instanceof Position) {
-
- Position position = (Position) e.getMessage();
+ Position position = (Position) msg;
try {
Context.getDeviceManager().updateLatestPosition(position);
} catch (SQLException error) {
@@ -59,7 +55,7 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
// Log position
StringBuilder s = new StringBuilder();
- s.append(formatChannel(e.getChannel())).append(" ");
+ s.append(formatChannel(ctx.channel())).append(" ");
s.append("id: ").append(uniqueId);
s.append(", time: ").append(
new SimpleDateFormat(Log.DATE_FORMAT).format(position.getFixTime()));
@@ -83,36 +79,38 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
}
private static String formatChannel(Channel channel) {
- return String.format("[%08X]", channel.getId());
+ return String.format("[%s]", channel.id().asShortText());
}
@Override
- public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
- Log.info(formatChannel(e.getChannel()) + " connected");
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ Log.info(formatChannel(ctx.channel()) + " connected");
}
@Override
- public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
- Log.info(formatChannel(e.getChannel()) + " disconnected");
- closeChannel(e.getChannel());
+ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+ Log.info(formatChannel(ctx.channel()) + " disconnected");
+ closeChannel(ctx.channel());
- BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) ctx.getPipeline().get("objectDecoder");
- if (ctx.getPipeline().get("httpDecoder") == null
+ BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) ctx.pipeline().get("objectDecoder");
+ if (ctx.pipeline().get("httpDecoder") == null
&& !connectionlessProtocols.contains(protocolDecoder.getProtocolName())) {
- Context.getConnectionManager().removeActiveDevice(e.getChannel());
+ Context.getConnectionManager().removeActiveDevice(ctx.channel());
}
}
@Override
- public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
- Log.warning(formatChannel(e.getChannel()) + " error", e.getCause());
- closeChannel(e.getChannel());
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ Log.warning(formatChannel(ctx.channel()) + " error", cause.getCause());
+ closeChannel(ctx.channel());
}
@Override
- public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
- Log.info(formatChannel(e.getChannel()) + " timed out");
- closeChannel(e.getChannel());
+ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
+ if (evt instanceof IdleStateEvent) {
+ Log.info(formatChannel(ctx.channel()) + " timed out");
+ closeChannel(ctx.channel());
+ }
}
private void closeChannel(Channel channel) {
diff --git a/src/org/traccar/MotionHandler.java b/src/org/traccar/MotionHandler.java
index 901965dd5..ec9a5ffd7 100644
--- a/src/org/traccar/MotionHandler.java
+++ b/src/org/traccar/MotionHandler.java
@@ -16,8 +16,10 @@
*/
package org.traccar;
+import io.netty.channel.ChannelHandler;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class MotionHandler extends BaseDataHandler {
private double speedThreshold;
diff --git a/src/org/traccar/RemoteAddressHandler.java b/src/org/traccar/RemoteAddressHandler.java
index 188bbcab9..5555413cf 100644
--- a/src/org/traccar/RemoteAddressHandler.java
+++ b/src/org/traccar/RemoteAddressHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,17 +15,18 @@
*/
package org.traccar;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandler;
import org.traccar.model.Position;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+@ChannelHandler.Sharable
public class RemoteAddressHandler extends ExtendedObjectDecoder {
@Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String hostAddress = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress();
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 45503b717..9cd5aed79 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -15,7 +15,7 @@
*/
package org.traccar;
-import org.jboss.netty.channel.ChannelException;
+import io.netty.channel.ChannelException;
import org.traccar.helper.Log;
import java.io.File;
@@ -86,7 +86,7 @@ public class ServerManager {
server.start();
} catch (ChannelException e) {
if (e.getCause() instanceof BindException) {
- Log.warning("One of the protocols is disabled due to port conflict");
+ Log.warning("One of the protocols is disabled due to port conflict"); // TODO test this
}
}
}
@@ -96,7 +96,6 @@ public class ServerManager {
for (TrackerServer server: serverList) {
server.stop();
}
- GlobalChannelFactory.release();
GlobalTimer.release();
}
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
index 7e0a6f0c6..cce3261b9 100644
--- a/src/org/traccar/TrackerServer.java
+++ b/src/org/traccar/TrackerServer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,52 +15,56 @@
*/
package org.traccar;
-import org.jboss.netty.bootstrap.Bootstrap;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.buffer.HeapChannelBufferFactory;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.group.ChannelGroup;
-import org.jboss.netty.channel.group.ChannelGroupFuture;
-import org.jboss.netty.channel.group.DefaultChannelGroup;
+import io.netty.bootstrap.AbstractBootstrap;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.group.ChannelGroup;
+import io.netty.channel.group.DefaultChannelGroup;
+import io.netty.channel.socket.nio.NioDatagramChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.util.concurrent.GlobalEventExecutor;
import java.net.InetSocketAddress;
-import java.nio.ByteOrder;
public abstract class TrackerServer {
- private final Bootstrap bootstrap;
- private final String protocol;
+ private final boolean datagram;
+ private final AbstractBootstrap bootstrap;
- public boolean isConnectionless() {
- return bootstrap instanceof ConnectionlessBootstrap;
+ public boolean isDatagram() {
+ return datagram;
}
- public String getProtocol() {
- return protocol;
- }
-
- public TrackerServer(Bootstrap bootstrap, String protocol) {
- this.bootstrap = bootstrap;
- this.protocol = protocol;
-
- if (bootstrap instanceof ServerBootstrap) {
- bootstrap.setFactory(GlobalChannelFactory.getFactory());
- } else if (bootstrap instanceof ConnectionlessBootstrap) {
- bootstrap.setFactory(GlobalChannelFactory.getDatagramFactory());
- }
+ public TrackerServer(boolean datagram, String protocol) {
+ this.datagram = datagram;
address = Context.getConfig().getString(protocol + ".address");
port = Context.getConfig().getInteger(protocol + ".port");
- bootstrap.setPipelineFactory(new BasePipelineFactory(this, protocol) {
+ BasePipelineFactory pipelineFactory = new BasePipelineFactory(this, protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
TrackerServer.this.addSpecificHandlers(pipeline);
}
- });
+ };
+
+ if (datagram) {
+
+ this.bootstrap = new Bootstrap()
+ .group(GlobalChannelFactory.getWorkerGroup())
+ .channel(NioDatagramChannel.class)
+ .handler(pipelineFactory);
+
+ } else {
+
+ this.bootstrap = new ServerBootstrap()
+ .group(GlobalChannelFactory.getBossGroup(), GlobalChannelFactory.getWorkerGroup())
+ .channel(NioServerSocketChannel.class)
+ .childHandler(pipelineFactory);
+
+ }
}
protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
@@ -85,23 +89,10 @@ public abstract class TrackerServer {
this.address = address;
}
- public void setEndianness(ByteOrder byteOrder) {
- bootstrap.setOption("bufferFactory", new HeapChannelBufferFactory(byteOrder));
- bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder));
- }
-
- private final ChannelGroup allChannels = new DefaultChannelGroup();
+ private final ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
public ChannelGroup getChannelGroup() {
- return allChannels;
- }
-
- public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
- bootstrap.setPipelineFactory(pipelineFactory);
- }
-
- public ChannelPipelineFactory getPipelineFactory() {
- return bootstrap.getPipelineFactory();
+ return channelGroup;
}
public void start() {
@@ -112,12 +103,7 @@ public abstract class TrackerServer {
endpoint = new InetSocketAddress(address, port);
}
- Channel channel = null;
- if (bootstrap instanceof ServerBootstrap) {
- channel = ((ServerBootstrap) bootstrap).bind(endpoint);
- } else if (bootstrap instanceof ConnectionlessBootstrap) {
- channel = ((ConnectionlessBootstrap) bootstrap).bind(endpoint);
- }
+ Channel channel = bootstrap.bind(endpoint).channel();
if (channel != null) {
getChannelGroup().add(channel);
@@ -125,8 +111,7 @@ public abstract class TrackerServer {
}
public void stop() {
- ChannelGroupFuture future = getChannelGroup().close();
- future.awaitUninterruptibly();
+ channelGroup.close().awaitUninterruptibly();
}
}
diff --git a/src/org/traccar/api/CorsResponseFilter.java b/src/org/traccar/api/CorsResponseFilter.java
index 70ea7e3e1..227f80609 100644
--- a/src/org/traccar/api/CorsResponseFilter.java
+++ b/src/org/traccar/api/CorsResponseFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.api;
-import org.jboss.netty.handler.codec.http.HttpHeaders;
+import io.netty.handler.codec.http.HttpHeaderNames;
import org.traccar.Context;
import javax.ws.rs.container.ContainerRequestContext;
@@ -31,26 +31,26 @@ public class CorsResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException {
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS, HEADERS_ALL);
+ if (!response.getHeaders().containsKey(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString())) {
+ response.getHeaders().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString(), HEADERS_ALL);
}
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS, true);
+ if (!response.getHeaders().containsKey(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString())) {
+ response.getHeaders().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString(), true);
}
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_METHODS)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_METHODS, METHODS_ALL);
+ if (!response.getHeaders().containsKey(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString())) {
+ response.getHeaders().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString(), METHODS_ALL);
}
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)) {
- String origin = request.getHeaderString(HttpHeaders.Names.ORIGIN);
+ if (!response.getHeaders().containsKey(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString())) {
+ String origin = request.getHeaderString(HttpHeaderNames.ORIGIN.toString());
String allowed = Context.getConfig().getString("web.origin");
if (origin == null) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN, ORIGIN_ALL);
+ response.getHeaders().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), ORIGIN_ALL);
} else if (allowed == null || allowed.equals(ORIGIN_ALL) || allowed.contains(origin)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
+ response.getHeaders().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), origin);
}
}
}
diff --git a/src/org/traccar/database/ActiveDevice.java b/src/org/traccar/database/ActiveDevice.java
index f491111e1..e58c05e19 100644
--- a/src/org/traccar/database/ActiveDevice.java
+++ b/src/org/traccar/database/ActiveDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.database;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.Protocol;
import org.traccar.model.Command;
@@ -48,7 +48,7 @@ public class ActiveDevice {
}
public void write(Object message) {
- getChannel().write(message, remoteAddress);
+ channel.write(message); // TODO handle UDP connection
}
}
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index e5a7a272f..657c0e6e8 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,9 @@
*/
package org.traccar.database;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.util.Timeout;
-import org.jboss.netty.util.TimerTask;
+import io.netty.channel.Channel;
+import io.netty.util.Timeout;
+import io.netty.util.TimerTask;
import org.traccar.Context;
import org.traccar.GlobalTimer;
import org.traccar.Protocol;
diff --git a/src/org/traccar/database/MediaManager.java b/src/org/traccar/database/MediaManager.java
index 482442735..0bb6afac7 100644
--- a/src/org/traccar/database/MediaManager.java
+++ b/src/org/traccar/database/MediaManager.java
@@ -15,7 +15,7 @@
*/
package org.traccar.database;
-import org.jboss.netty.buffer.ChannelBuffer;
+import io.netty.buffer.ByteBuf;
import org.traccar.helper.Log;
import java.io.File;
@@ -46,13 +46,13 @@ public class MediaManager {
return filePath.toFile();
}
- public String writeFile(String uniqueId, ChannelBuffer buf, String extension) {
+ public String writeFile(String uniqueId, ByteBuf buf, String extension) {
if (path != null) {
int size = buf.readableBytes();
String name = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + "." + extension;
try (FileOutputStream output = new FileOutputStream(createFile(uniqueId, name));
FileChannel fileChannel = output.getChannel()) {
- ByteBuffer byteBuffer = buf.toByteBuffer();
+ ByteBuffer byteBuffer = buf.nioBuffer();
int written = 0;
while (written < size) {
written += fileChannel.write(byteBuffer);
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
index 7db371c70..b14869e72 100644
--- a/src/org/traccar/events/AlertEventHandler.java
+++ b/src/org/traccar/events/AlertEventHandler.java
@@ -18,11 +18,13 @@ package org.traccar.events;
import java.util.Collections;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class AlertEventHandler extends BaseEventHandler {
private final boolean ignoreDuplicateAlerts;
diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java
index 775aa903f..89ec44190 100644
--- a/src/org/traccar/events/CommandResultEventHandler.java
+++ b/src/org/traccar/events/CommandResultEventHandler.java
@@ -18,10 +18,12 @@ package org.traccar.events;
import java.util.Collections;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.model.Event;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class CommandResultEventHandler extends BaseEventHandler {
@Override
diff --git a/src/org/traccar/events/DriverEventHandler.java b/src/org/traccar/events/DriverEventHandler.java
index 39b8eb9c0..c8efd0576 100644
--- a/src/org/traccar/events/DriverEventHandler.java
+++ b/src/org/traccar/events/DriverEventHandler.java
@@ -19,11 +19,13 @@ package org.traccar.events;
import java.util.Collections;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class DriverEventHandler extends BaseEventHandler {
@Override
diff --git a/src/org/traccar/events/FuelDropEventHandler.java b/src/org/traccar/events/FuelDropEventHandler.java
index 2ee3e1a58..31b17d500 100644
--- a/src/org/traccar/events/FuelDropEventHandler.java
+++ b/src/org/traccar/events/FuelDropEventHandler.java
@@ -15,6 +15,7 @@
*/
package org.traccar.events;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Device;
@@ -24,6 +25,7 @@ import org.traccar.model.Position;
import java.util.Collections;
import java.util.Map;
+@ChannelHandler.Sharable
public class FuelDropEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold";
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
index 31d82a81e..ea379dbdb 100644
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ b/src/org/traccar/events/GeofenceEventHandler.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.database.GeofenceManager;
@@ -28,6 +29,7 @@ import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class GeofenceEventHandler extends BaseEventHandler {
private GeofenceManager geofenceManager;
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
index cc53b216c..a17f15318 100644
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ b/src/org/traccar/events/IgnitionEventHandler.java
@@ -19,12 +19,14 @@ package org.traccar.events;
import java.util.Collections;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class IgnitionEventHandler extends BaseEventHandler {
@Override
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
index 4a6122826..5bebb1baf 100644
--- a/src/org/traccar/events/MaintenanceEventHandler.java
+++ b/src/org/traccar/events/MaintenanceEventHandler.java
@@ -19,12 +19,14 @@ package org.traccar.events;
import java.util.HashMap;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Maintenance;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class MaintenanceEventHandler extends BaseEventHandler {
@Override
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index 0c1c4848f..4047b83a4 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -19,6 +19,7 @@ package org.traccar.events;
import java.util.Collections;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Device;
@@ -28,6 +29,7 @@ import org.traccar.model.Position;
import org.traccar.reports.ReportUtils;
import org.traccar.reports.model.TripsConfig;
+@ChannelHandler.Sharable
public class MotionEventHandler extends BaseEventHandler {
private TripsConfig tripsConfig;
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 4ebe43fda..aed79a2f5 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -19,6 +19,7 @@ package org.traccar.events;
import java.util.Collections;
import java.util.Map;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Device;
@@ -27,6 +28,7 @@ import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class OverspeedEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit";
diff --git a/src/org/traccar/helper/BcdUtil.java b/src/org/traccar/helper/BcdUtil.java
index 495f94104..c87529e32 100644
--- a/src/org/traccar/helper/BcdUtil.java
+++ b/src/org/traccar/helper/BcdUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,14 @@
*/
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffer;
+import io.netty.buffer.ByteBuf;
public final class BcdUtil {
private BcdUtil() {
}
- public static int readInteger(ChannelBuffer buf, int digits) {
+ public static int readInteger(ByteBuf buf, int digits) {
int result = 0;
for (int i = 0; i < digits / 2; i++) {
@@ -42,7 +42,7 @@ public final class BcdUtil {
return result;
}
- public static double readCoordinate(ChannelBuffer buf) {
+ public static double readCoordinate(ByteBuf buf) {
int b1 = buf.readUnsignedByte();
int b2 = buf.readUnsignedByte();
int b3 = buf.readUnsignedByte();
diff --git a/src/org/traccar/helper/BitBuffer.java b/src/org/traccar/helper/BitBuffer.java
index ac307efdf..f30a4557b 100644
--- a/src/org/traccar/helper/BitBuffer.java
+++ b/src/org/traccar/helper/BitBuffer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,12 @@
*/
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
public class BitBuffer {
- private final ChannelBuffer buffer;
+ private final ByteBuf buffer;
private int writeByte;
private int writeCount;
@@ -29,10 +29,10 @@ public class BitBuffer {
private int readCount;
public BitBuffer() {
- buffer = ChannelBuffers.dynamicBuffer();
+ buffer = Unpooled.buffer();
}
- public BitBuffer(ChannelBuffer buffer) {
+ public BitBuffer(ByteBuf buffer) {
this.buffer = buffer;
}
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index d74246a64..a22e4bde2 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,6 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.varia.NullAppender;
-import org.jboss.netty.logging.AbstractInternalLogger;
-import org.jboss.netty.logging.InternalLogger;
-import org.jboss.netty.logging.InternalLoggerFactory;
import org.traccar.Config;
import java.io.IOException;
@@ -67,14 +64,6 @@ public final class Log {
logger.addAppender(appender);
logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
- // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
- InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
- @Override
- public InternalLogger newInstance(String string) {
- return new NettyInternalLogger();
- }
- });
-
Log.logSystemInfo();
Log.info("Version: " + getAppVersion());
}
@@ -200,69 +189,4 @@ public final class Log {
return s.toString();
}
- /**
- * Netty logger implementation
- */
- private static class NettyInternalLogger extends AbstractInternalLogger {
-
- @Override
- public boolean isDebugEnabled() {
- return false;
- }
-
- @Override
- public boolean isInfoEnabled() {
- return false;
- }
-
- @Override
- public boolean isWarnEnabled() {
- return true;
- }
-
- @Override
- public boolean isErrorEnabled() {
- return true;
- }
-
- @Override
- public void debug(String string) {
- debug(string, null);
- }
-
- @Override
- public void debug(String string, Throwable thrwbl) {
- }
-
- @Override
- public void info(String string) {
- info(string, null);
- }
-
- @Override
- public void info(String string, Throwable thrwbl) {
- }
-
- @Override
- public void warn(String string) {
- warn(string, null);
- }
-
- @Override
- public void warn(String string, Throwable thrwbl) {
- getLogger().warn("netty warning: " + string);
- }
-
- @Override
- public void error(String string) {
- error(string, null);
- }
-
- @Override
- public void error(String string, Throwable thrwbl) {
- getLogger().error("netty error: " + string);
- }
-
- }
-
}
diff --git a/src/org/traccar/helper/StringFinder.java b/src/org/traccar/helper/StringFinder.java
index 2fa0aa9a4..53e9bd68a 100644
--- a/src/org/traccar/helper/StringFinder.java
+++ b/src/org/traccar/helper/StringFinder.java
@@ -15,14 +15,11 @@
*/
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferIndexFinder;
-
import java.nio.charset.StandardCharsets;
-public class StringFinder implements ChannelBufferIndexFinder {
+public class StringFinder /*implements ChannelBufferIndexFinder*/ { // TODO handle this
- private String string;
+ /*private String string;
public StringFinder(String string) {
this.string = string;
@@ -36,6 +33,6 @@ public class StringFinder implements ChannelBufferIndexFinder {
}
return string.equals(buffer.toString(guessedIndex, string.length(), StandardCharsets.US_ASCII));
- }
+ }*/
}
diff --git a/src/org/traccar/processing/ComputedAttributesHandler.java b/src/org/traccar/processing/ComputedAttributesHandler.java
index b37db05bf..a4edcc460 100644
--- a/src/org/traccar/processing/ComputedAttributesHandler.java
+++ b/src/org/traccar/processing/ComputedAttributesHandler.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import io.netty.channel.ChannelHandler;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.JexlException;
import org.apache.commons.jexl2.MapContext;
@@ -35,6 +36,7 @@ import org.traccar.model.Attribute;
import org.traccar.model.Device;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class ComputedAttributesHandler extends BaseDataHandler {
private JexlEngine engine;
diff --git a/src/org/traccar/processing/CopyAttributesHandler.java b/src/org/traccar/processing/CopyAttributesHandler.java
index 9fbcfa73f..bdd73b141 100644
--- a/src/org/traccar/processing/CopyAttributesHandler.java
+++ b/src/org/traccar/processing/CopyAttributesHandler.java
@@ -16,10 +16,12 @@
*/
package org.traccar.processing;
+import io.netty.channel.ChannelHandler;
import org.traccar.BaseDataHandler;
import org.traccar.Context;
import org.traccar.model.Position;
+@ChannelHandler.Sharable
public class CopyAttributesHandler extends BaseDataHandler {
private Position getLastPosition(long deviceId) {
diff --git a/src/org/traccar/protocol/Ardi01Protocol.java b/src/org/traccar/protocol/Ardi01Protocol.java
index 446592bd0..3bcff8608 100644
--- a/src/org/traccar/protocol/Ardi01Protocol.java
+++ b/src/org/traccar/protocol/Ardi01Protocol.java
@@ -15,11 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.channel.ChannelPipeline;
+import io.netty.handler.codec.LineBasedFrameDecoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
@@ -33,7 +32,7 @@ public class Ardi01Protocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
index dea9e3483..9ae50df86 100644
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.Parser;
diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java
index a5bd32261..aa96215da 100644
--- a/src/org/traccar/protocol/Gps103Protocol.java
+++ b/src/org/traccar/protocol/Gps103Protocol.java
@@ -15,11 +15,9 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.channel.ChannelPipeline;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
import org.traccar.TrackerServer;
@@ -45,7 +43,7 @@ public class Gps103Protocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(2048, "\r\n", "\n", ";"));
@@ -55,7 +53,7 @@ public class Gps103Protocol extends BaseProtocol {
pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(Gps103Protocol.this));
}
});
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ serverList.add(new TrackerServer(true, getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("stringEncoder", new StringEncoder());
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 9883079d1..4e39b32b3 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
@@ -160,7 +160,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (alarm.equals("help me")) {
if (channel != null) {
- channel.write("**,imei:" + imei + ",E;", remoteAddress);
+ channel.write("**,imei:" + imei + ",E;");
}
} else if (alarm.equals("acc on")) {
position.set(Position.KEY_IGNITION, true);
@@ -276,7 +276,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
if (sentence.contains("##")) {
if (channel != null) {
- channel.write("LOAD", remoteAddress);
+ channel.write("LOAD");
Matcher matcher = Pattern.compile("##,imei:(\\d+),A").matcher(sentence);
if (matcher.matches()) {
getDeviceSession(channel, remoteAddress, matcher.group(1));
@@ -287,7 +287,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
if (!sentence.isEmpty() && Character.isDigit(sentence.charAt(0))) {
if (channel != null) {
- channel.write("ON", remoteAddress);
+ channel.write("ON");
}
int start = sentence.indexOf("imei:");
if (start >= 0) {
diff --git a/src/org/traccar/protocol/Gt02Protocol.java b/src/org/traccar/protocol/Gt02Protocol.java
index e484b66cd..0abd4021b 100644
--- a/src/org/traccar/protocol/Gt02Protocol.java
+++ b/src/org/traccar/protocol/Gt02Protocol.java
@@ -15,9 +15,8 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import io.netty.channel.ChannelPipeline;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
@@ -31,7 +30,7 @@ public class Gt02Protocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0));
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index a4f1a4161..3eb3e193a 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -15,9 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
@@ -42,7 +43,7 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.skipBytes(2); // header
buf.readByte(); // size
@@ -53,7 +54,7 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
int power = buf.readUnsignedByte();
int gsm = buf.readUnsignedByte();
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
+ String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
@@ -73,7 +74,7 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A};
- channel.write(ChannelBuffers.wrappedBuffer(response));
+ channel.write(Unpooled.wrappedBuffer(response));
}
} else if (type == MSG_DATA) {
diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java
index bf395f90e..967eed82c 100644
--- a/src/org/traccar/smpp/SmppClient.java
+++ b/src/org/traccar/smpp/SmppClient.java
@@ -48,7 +48,7 @@ public class SmppClient {
private SmppSession smppSession;
private DefaultSmppSessionHandler sessionHandler = new ClientSmppSessionHandler(this);
private ExecutorService executorService = Executors.newCachedThreadPool();
- private DefaultSmppClient clientBootstrap = new DefaultSmppClient(executorService, 1);
+ private DefaultSmppClient clientBootstrap = new DefaultSmppClient();
private ScheduledExecutorService enquireLinkExecutor;
private ScheduledFuture<?> enquireLinkTask;
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java
index 8b1ba3b1f..a8fa14fac 100644
--- a/test/org/traccar/FilterHandlerTest.java
+++ b/test/org/traccar/FilterHandlerTest.java
@@ -67,22 +67,22 @@ public class FilterHandlerTest {
Position position = createPosition(0, new Date(), true, 10, 10, 10, 10, 10);
- assertNotNull(filtingHandler.decode(null, null, position));
- assertNotNull(passingHandler.decode(null, null, position));
+ assertNotNull(filtingHandler.handlePosition(position));
+ assertNotNull(passingHandler.handlePosition(position));
position = createPosition(0, new Date(Long.MAX_VALUE), true, 10, 10, 10, 10, 10);
- assertNull(filtingHandler.decode(null, null, position));
- assertNotNull(passingHandler.decode(null, null, position));
+ assertNull(filtingHandler.handlePosition(position));
+ assertNotNull(passingHandler.handlePosition(position));
position = createPosition(0, new Date(), false, 10, 10, 10, 10, 10);
- assertNull(filtingHandler.decode(null, null, position));
- assertNotNull(passingHandler.decode(null, null, position));
+ assertNull(filtingHandler.handlePosition(position));
+ assertNotNull(passingHandler.handlePosition(position));
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
filtingHandler.setSkipAttributes(true);
- assertNotNull(filtingHandler.decode(null, null, position));
+ assertNotNull(filtingHandler.handlePosition(position));
}
}
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 47c620d13..831a10c51 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -1,16 +1,13 @@
package org.traccar;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
-import org.jboss.netty.handler.codec.http.HttpMethod;
-import org.jboss.netty.handler.codec.http.HttpVersion;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
import org.traccar.helper.DataConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Command;
import org.traccar.model.Position;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
@@ -50,24 +47,20 @@ public class ProtocolTest extends BaseTest {
return builder.toString();
}
- protected ChannelBuffer binary(String... data) {
- return binary(ByteOrder.BIG_ENDIAN, data);
- }
-
- protected ChannelBuffer binary(ByteOrder endianness, String... data) {
- return ChannelBuffers.wrappedBuffer(
- endianness, DataConverter.parseHex(concatenateStrings(data)));
+ protected ByteBuf binary(String... data) {
+ return Unpooled.wrappedBuffer(DataConverter.parseHex(concatenateStrings(data)));
}
protected String text(String... data) {
return concatenateStrings(data);
}
- protected ChannelBuffer buffer(String... data) {
- return ChannelBuffers.copiedBuffer(concatenateStrings(data), StandardCharsets.ISO_8859_1);
+ protected ByteBuf buffer(String... data) {
+ return Unpooled.copiedBuffer(concatenateStrings(data), StandardCharsets.ISO_8859_1);
}
- protected DefaultHttpRequest request(String url) {
+ // TODO handle HTTP methods
+ /*protected DefaultHttpRequest request(String url) {
return request(HttpMethod.GET, url);
}
@@ -75,11 +68,11 @@ public class ProtocolTest extends BaseTest {
return new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, url);
}
- protected DefaultHttpRequest request(HttpMethod method, String url, ChannelBuffer data) {
+ protected DefaultHttpRequest request(HttpMethod method, String url, ByteBuf data) {
DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, url);
request.setContent(data);
return request;
- }
+ }*/
protected void verifyNotNull(BaseProtocolDecoder decoder, Object object) throws Exception {
assertNotNull(decoder.decode(null, null, object));
@@ -292,14 +285,14 @@ public class ProtocolTest extends BaseTest {
}
protected void verifyCommand(
- BaseProtocolEncoder encoder, Command command, ChannelBuffer expected) throws Exception {
+ BaseProtocolEncoder encoder, Command command, ByteBuf expected) throws Exception {
verifyFrame(expected, encoder.encodeCommand(command));
}
- protected void verifyFrame(ChannelBuffer expected, Object object) {
+ protected void verifyFrame(ByteBuf expected, Object object) {
assertNotNull("buffer is null", object);
- assertTrue("not a buffer", object instanceof ChannelBuffer);
- assertEquals(ChannelBuffers.hexDump(expected), ChannelBuffers.hexDump((ChannelBuffer) object));
+ assertTrue("not a buffer", object instanceof ByteBuf);
+ assertEquals(ByteBufUtil.hexDump(expected), ByteBufUtil.hexDump((ByteBuf) object));
}
}
diff --git a/test/org/traccar/helper/BcdUtilTest.java b/test/org/traccar/helper/BcdUtilTest.java
index e97aad09f..86a32f725 100644
--- a/test/org/traccar/helper/BcdUtilTest.java
+++ b/test/org/traccar/helper/BcdUtilTest.java
@@ -1,6 +1,6 @@
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.Unpooled;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -10,16 +10,14 @@ public class BcdUtilTest {
@Test
public void testReadInteger() {
byte[] buf = {0x01, (byte) 0x90, 0x34};
- int result = BcdUtil.readInteger(
- ChannelBuffers.wrappedBuffer(buf), 5);
+ int result = BcdUtil.readInteger(Unpooled.wrappedBuffer(buf), 5);
assertEquals(1903, result);
}
@Test
public void testReadCoordinate() {
byte[] buf = {0x03, (byte) 0x85, 0x22, 0x59, 0x34};
- double result = BcdUtil.readCoordinate(
- ChannelBuffers.wrappedBuffer(buf));
+ double result = BcdUtil.readCoordinate(Unpooled.wrappedBuffer(buf));
assertEquals(38.870989, result, 0.00001);
}
diff --git a/test/org/traccar/helper/ChecksumTest.java b/test/org/traccar/helper/ChecksumTest.java
index 3bd51448d..5737b9ff5 100644
--- a/test/org/traccar/helper/ChecksumTest.java
+++ b/test/org/traccar/helper/ChecksumTest.java
@@ -1,7 +1,7 @@
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
@@ -12,22 +12,22 @@ public class ChecksumTest {
@Test
public void testCrc8() {
- ChannelBuffer buf = ChannelBuffers.copiedBuffer("123456789", StandardCharsets.US_ASCII);
+ ByteBuf buf = Unpooled.copiedBuffer("123456789", StandardCharsets.US_ASCII);
- assertEquals(0xF7, Checksum.crc8(Checksum.CRC8_EGTS, buf.toByteBuffer()));
- assertEquals(0xD0, Checksum.crc8(Checksum.CRC8_ROHC, buf.toByteBuffer()));
+ assertEquals(0xF7, Checksum.crc8(Checksum.CRC8_EGTS, buf.nioBuffer()));
+ assertEquals(0xD0, Checksum.crc8(Checksum.CRC8_ROHC, buf.nioBuffer()));
}
@Test
public void testCrc16() {
- ChannelBuffer buf = ChannelBuffers.copiedBuffer("123456789", StandardCharsets.US_ASCII);
-
- assertEquals(0xBB3D, Checksum.crc16(Checksum.CRC16_IBM, buf.toByteBuffer()));
- assertEquals(0x4B37, Checksum.crc16(Checksum.CRC16_MODBUS, buf.toByteBuffer()));
- assertEquals(0x906e, Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
- assertEquals(0x29b1, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
- assertEquals(0x2189, Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
- assertEquals(0x31c3, Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer()));
+ ByteBuf buf = Unpooled.copiedBuffer("123456789", StandardCharsets.US_ASCII);
+
+ assertEquals(0xBB3D, Checksum.crc16(Checksum.CRC16_IBM, buf.nioBuffer()));
+ assertEquals(0x4B37, Checksum.crc16(Checksum.CRC16_MODBUS, buf.nioBuffer()));
+ assertEquals(0x906e, Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer()));
+ assertEquals(0x29b1, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.nioBuffer()));
+ assertEquals(0x2189, Checksum.crc16(Checksum.CRC16_KERMIT, buf.nioBuffer()));
+ assertEquals(0x31c3, Checksum.crc16(Checksum.CRC16_XMODEM, buf.nioBuffer()));
}
@Test
diff --git a/test/org/traccar/helper/StringFinderTest.java b/test/org/traccar/helper/StringFinderTest.java
index f35f9a759..b8ac6d761 100644
--- a/test/org/traccar/helper/StringFinderTest.java
+++ b/test/org/traccar/helper/StringFinderTest.java
@@ -1,7 +1,7 @@
package org.traccar.helper;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
@@ -13,12 +13,13 @@ public class StringFinderTest {
@Test
public void testFind() {
- ChannelBuffer buf = ChannelBuffers.copiedBuffer("hello world", StandardCharsets.US_ASCII);
+ ByteBuf buf = Unpooled.copiedBuffer("hello world", StandardCharsets.US_ASCII);
- assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("bar")));
+ // TODO update test
+ /*assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("bar")));
assertEquals(6, buf.indexOf(0, buf.writerIndex(), new StringFinder("world")));
assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("worlds")));
- assertEquals(0, buf.indexOf(0, buf.writerIndex(), new StringFinder("hell")));
+ assertEquals(0, buf.indexOf(0, buf.writerIndex(), new StringFinder("hell")));*/
}