diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-02 22:12:44 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-02 22:12:44 +1200 |
commit | 06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07 (patch) | |
tree | 8f5d7b71ca3fa39448e93b3d0652a7fa8d496932 /src | |
parent | 5a9811c3771d92832c9bba718b5ec935844978e8 (diff) | |
download | trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.tar.gz trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.tar.bz2 trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.zip |
Start Netty 4 migration
Diffstat (limited to 'src')
47 files changed, 315 insertions, 435 deletions
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; |