diff options
Diffstat (limited to 'src')
20 files changed, 78 insertions, 39 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 00bf0a5e9..14041a63a 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -64,7 +64,11 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { msg.append("[").append(String.format("%08X", e.getChannel().getId())).append(": "); msg.append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort()); - msg.append(e instanceof DownstreamMessageEvent ? " > " : " < "); + if (e instanceof DownstreamMessageEvent) { + msg.append(" > "); + } else { + msg.append(" < "); + } msg.append(((InetSocketAddress) event.getRemoteAddress()).getAddress().getHostAddress()).append("]"); diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java index 37eecf51b..aa4f855c5 100644 --- a/src/org/traccar/GlobalChannelFactory.java +++ b/src/org/traccar/GlobalChannelFactory.java @@ -20,11 +20,14 @@ import org.jboss.netty.channel.socket.DatagramChannelFactory; import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -public class GlobalChannelFactory { +public final class GlobalChannelFactory { private static ChannelFactory channelFactory = null; private static DatagramChannelFactory datagramChannelFactory = null; + private GlobalChannelFactory() { + } + public static void release() { if (channelFactory != null) { channelFactory.releaseExternalResources(); diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java index b5433b921..a51fa80bf 100644 --- a/src/org/traccar/Main.java +++ b/src/org/traccar/Main.java @@ -18,7 +18,10 @@ package org.traccar; import java.util.Locale; import org.traccar.helper.Log; -public class Main { +public final class Main { + + private Main() { + } public static void main(String[] args) throws Exception { Locale.setDefault(Locale.ENGLISH); diff --git a/src/org/traccar/geocode/BingMapsReverseGeocoder.java b/src/org/traccar/geocode/BingMapsReverseGeocoder.java index 8c47febef..a5ebbd420 100644 --- a/src/org/traccar/geocode/BingMapsReverseGeocoder.java +++ b/src/org/traccar/geocode/BingMapsReverseGeocoder.java @@ -32,7 +32,8 @@ public class BingMapsReverseGeocoder extends JsonReverseGeocoder { public Address parseAddress(JsonObject json) { JsonArray result = json.getJsonArray("resourceSets"); if (result != null) { - JsonObject location = result.getJsonObject(0).getJsonArray("resources").getJsonObject(0).getJsonObject("address"); + JsonObject location = + result.getJsonObject(0).getJsonArray("resources").getJsonObject(0).getJsonObject("address"); if (location != null) { Address address = new Address(); if (location.containsKey("addressLine")) { diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java index ca1d42000..f1c27c5d3 100644 --- a/src/org/traccar/geocode/GoogleReverseGeocoder.java +++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java @@ -67,6 +67,8 @@ public class GoogleReverseGeocoder extends JsonReverseGeocoder { case "postal_code": address.setPostcode(value); break typesLoop; + default: + break; } } } diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java index e42956228..dd63a0c86 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/ChannelBufferTools.java @@ -19,7 +19,10 @@ import org.jboss.netty.buffer.ChannelBuffer; import java.util.Formatter; -public class ChannelBufferTools { +public final class ChannelBufferTools { + + private ChannelBufferTools() { + } public static Integer find(ChannelBuffer buf, int start, String subString) { return find(buf, start, buf.readerIndex() + buf.readableBytes(), subString); diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index 4fa212200..184e6b31b 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -19,7 +19,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -public class PatternUtil { +public final class PatternUtil { + + private PatternUtil() { + } public static String checkPattern(String pattern, String input) { diff --git a/src/org/traccar/helper/UnitsConverter.java b/src/org/traccar/helper/UnitsConverter.java index e490f366c..fe42d9ee2 100644 --- a/src/org/traccar/helper/UnitsConverter.java +++ b/src/org/traccar/helper/UnitsConverter.java @@ -15,7 +15,10 @@ */ package org.traccar.helper; -public class UnitsConverter { +public final class UnitsConverter { + + private UnitsConverter() { + } public static double knotsFromKph(double value) { // km/h return value * 0.539957; diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java index cda1ebb2b..d1010daeb 100644 --- a/src/org/traccar/protocol/AtrackFrameDecoder.java +++ b/src/org/traccar/protocol/AtrackFrameDecoder.java @@ -30,13 +30,11 @@ public class AtrackFrameDecoder extends LengthFieldBasedFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { // Keep alive message - if (buf.readableBytes() >= KEEPALIVE_LENGTH && - buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) { + if (buf.readableBytes() >= KEEPALIVE_LENGTH + && buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) { return buf.readBytes(KEEPALIVE_LENGTH); } diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index daa8d093b..6b959ea82 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -61,7 +61,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { channel.write(response, remoteAddress); } } - + private Position decodePosition(int type, ChannelBuffer buf) { Position position = new Position(); diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index cc05a525b..ea8ac08e7 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -51,7 +51,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { private static final int TAG_REFRIGERATOR = 0x5b; private static final int TAG_PRESSURE = 0x5c; - private static final Map<Integer, Integer> tagLengthMap = new HashMap<>(); + private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>(); static { int[] l1 = { @@ -80,25 +80,25 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { 0xf6, 0xf7, 0xf8 }; for (int i : l1) { - tagLengthMap.put(i, 1); + TAG_LENGTH_MAP.put(i, 1); } for (int i : l2) { - tagLengthMap.put(i, 2); + TAG_LENGTH_MAP.put(i, 2); } for (int i : l3) { - tagLengthMap.put(i, 3); + TAG_LENGTH_MAP.put(i, 3); } for (int i : l4) { - tagLengthMap.put(i, 4); + TAG_LENGTH_MAP.put(i, 4); } - tagLengthMap.put(TAG_COORDINATES, 9); - tagLengthMap.put(TAG_IMEI, 15); - tagLengthMap.put(TAG_REFRIGERATOR, 7); // variable length - tagLengthMap.put(TAG_PRESSURE, 68); + TAG_LENGTH_MAP.put(TAG_COORDINATES, 9); + TAG_LENGTH_MAP.put(TAG_IMEI, 15); + TAG_LENGTH_MAP.put(TAG_REFRIGERATOR, 7); // variable length + TAG_LENGTH_MAP.put(TAG_PRESSURE, 68); } private static int getTagLength(int tag) { - return tagLengthMap.get(tag); + return TAG_LENGTH_MAP.get(tag); } private void sendReply(Channel channel, int checksum) { diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java index b9fb1126e..cb1050be3 100644 --- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolEncoder.java @@ -47,7 +47,8 @@ public class Gps103ProtocolEncoder extends StringProtocolEncoder implements Stri case Command.TYPE_POSITION_SINGLE: return formatCommand(command, "**,imei:{%s},B", Command.KEY_UNIQUE_ID); case Command.TYPE_POSITION_PERIODIC: - return formatCommand(command, "**,imei:{%s},C,{%s}", this, Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY); + return formatCommand( + command, "**,imei:{%s},C,{%s}", this, Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY); case Command.TYPE_ENGINE_STOP: return formatCommand(command, "**,imei:{%s},J", Command.KEY_UNIQUE_ID); case Command.TYPE_ENGINE_RESUME: diff --git a/src/org/traccar/protocol/KhdProtocolEncoder.java b/src/org/traccar/protocol/KhdProtocolEncoder.java index 0caf58eb0..a056fdf05 100644 --- a/src/org/traccar/protocol/KhdProtocolEncoder.java +++ b/src/org/traccar/protocol/KhdProtocolEncoder.java @@ -19,6 +19,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; +import org.traccar.helper.Log; import org.traccar.model.Command; public class KhdProtocolEncoder extends BaseProtocolEncoder { @@ -52,6 +53,9 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder { return encodeCommand(MSG_CUT_OIL); case Command.TYPE_ENGINE_RESUME: return encodeCommand(MSG_RESUME_OIL); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; } return null; diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java index 63b018deb..e96359104 100644 --- a/src/org/traccar/protocol/MeitrackFrameDecoder.java +++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java @@ -36,7 +36,8 @@ public class MeitrackFrameDecoder extends FrameDecoder { Integer index = ChannelBufferTools.find(buf, buf.readerIndex(), buf.writerIndex(), ","); if (index != null) { - int length = index - buf.readerIndex() + Integer.parseInt(buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, Charset.defaultCharset())); + int length = index - buf.readerIndex() + Integer.parseInt( + buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, Charset.defaultCharset())); if (buf.readableBytes() >= length) { return buf.readBytes(length); } diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index e7ee74a30..f128c6414 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -59,7 +59,12 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); // Identification - String id = params.get(params.containsKey("id") ? "id" : "deviceid").get(0); + String id; + if (params.containsKey("id")) { + id = params.get("id").get(0); + } else { + id = params.get("deviceid").get(0); + } if (!identify(id, channel)) { return null; } diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 51cf6951c..9fbd601d5 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -138,7 +138,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_SATELLITES, satellitesNumber); // Validity - position.setValid(satellitesNumber >= 3); // TODO: probably wrong + position.setValid(satellitesNumber >= 3); // Cell signal position.set(Event.KEY_GSM, buf.readUnsignedByte()); diff --git a/src/org/traccar/protocol/SuntechProtocolEncoder.java b/src/org/traccar/protocol/SuntechProtocolEncoder.java index 271718643..d988f97be 100644 --- a/src/org/traccar/protocol/SuntechProtocolEncoder.java +++ b/src/org/traccar/protocol/SuntechProtocolEncoder.java @@ -16,6 +16,7 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; +import org.traccar.helper.Log; import org.traccar.model.Command; public class SuntechProtocolEncoder extends StringProtocolEncoder { @@ -28,6 +29,9 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, "SA200CMD;{%s};02;Enable1\r", Command.KEY_UNIQUE_ID); case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "SA200CMD;{%s};02;Disable1\r", Command.KEY_UNIQUE_ID); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; } return null; diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java index c44d55788..51d6fec1e 100644 --- a/src/org/traccar/protocol/TotemProtocolEncoder.java +++ b/src/org/traccar/protocol/TotemProtocolEncoder.java @@ -17,6 +17,7 @@ package org.traccar.protocol; import org.traccar.StringProtocolEncoder; +import org.traccar.helper.Log; import org.traccar.model.Command; public class TotemProtocolEncoder extends StringProtocolEncoder { @@ -33,6 +34,9 @@ public class TotemProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, "*{%s},025,C,1#", Command.KEY_DEVICE_PASSWORD); case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "*{%s},025,C,0#", Command.KEY_DEVICE_PASSWORD); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; } return null; diff --git a/src/org/traccar/protocol/TramigoFrameDecoder.java b/src/org/traccar/protocol/TramigoFrameDecoder.java index ff2109136..aeeb4152c 100644 --- a/src/org/traccar/protocol/TramigoFrameDecoder.java +++ b/src/org/traccar/protocol/TramigoFrameDecoder.java @@ -41,7 +41,7 @@ public class TramigoFrameDecoder extends LengthFieldBasedFrameDecoder { // Swap byte order for legacy protocol if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) { int length = buf.readableBytes(); - byte bytes[] = new byte[length]; + byte[] bytes = new byte[length]; buf.getBytes(buf.readerIndex(), bytes); ChannelBuffer result = (ChannelBuffer) super.decode( diff --git a/src/org/traccar/web/AsyncServlet.java b/src/org/traccar/web/AsyncServlet.java index d541e29c5..73803ab91 100644 --- a/src/org/traccar/web/AsyncServlet.java +++ b/src/org/traccar/web/AsyncServlet.java @@ -113,8 +113,8 @@ public class AsyncServlet extends BaseServlet { destroyed = true; } Context.getConnectionManager().removeListener(devices, dataListener); - synchronized (asyncSessions) { - asyncSessions.remove(userId); + synchronized (ASYNC_SESSIONS) { + ASYNC_SESSIONS.remove(userId); } } }; @@ -175,17 +175,17 @@ public class AsyncServlet extends BaseServlet { } - private static final Map<Long, AsyncSession> asyncSessions = new HashMap<>(); + private static final Map<Long, AsyncSession> ASYNC_SESSIONS = new HashMap<>(); public static void sessionRefreshUser(long userId) { - synchronized (asyncSessions) { - asyncSessions.remove(userId); + synchronized (ASYNC_SESSIONS) { + ASYNC_SESSIONS.remove(userId); } } public static void sessionRefreshDevice(long deviceId) { - synchronized (asyncSessions) { - Iterator<Entry<Long, AsyncSession>> iterator = asyncSessions.entrySet().iterator(); + synchronized (ASYNC_SESSIONS) { + Iterator<Entry<Long, AsyncSession>> iterator = ASYNC_SESSIONS.entrySet().iterator(); while (iterator.hasNext()) { if (iterator.next().getValue().hasDevice(deviceId)) { iterator.remove(); @@ -199,14 +199,14 @@ public class AsyncServlet extends BaseServlet { context.setTimeout(ASYNC_TIMEOUT); HttpServletRequest req = (HttpServletRequest) context.getRequest(); - synchronized (asyncSessions) { + synchronized (ASYNC_SESSIONS) { - if (Boolean.parseBoolean(req.getParameter("first")) || !asyncSessions.containsKey(userId)) { + if (Boolean.parseBoolean(req.getParameter("first")) || !ASYNC_SESSIONS.containsKey(userId)) { Collection<Long> devices = Context.getPermissionsManager().allowedDevices(userId); - asyncSessions.put(userId, new AsyncSession(userId, devices)); + ASYNC_SESSIONS.put(userId, new AsyncSession(userId, devices)); } - asyncSessions.get(userId).request(context); + ASYNC_SESSIONS.get(userId).request(context); } } |