aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/ExtendedObjectDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-05-10 14:49:06 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-05-10 14:49:06 +1200
commit426611e0fd6aaad5e882b2661a66f8c2e48a6af0 (patch)
tree4159a3b47f5f001d977d8d45786b4faa7eaf4824 /src/org/traccar/ExtendedObjectDecoder.java
parentf4a4fafb5c6eb6cdd2d219a3b31c7e232bcd0807 (diff)
downloadtrackermap-server-426611e0fd6aaad5e882b2661a66f8c2e48a6af0.tar.gz
trackermap-server-426611e0fd6aaad5e882b2661a66f8c2e48a6af0.tar.bz2
trackermap-server-426611e0fd6aaad5e882b2661a66f8c2e48a6af0.zip
Add option to save empty messages
Diffstat (limited to 'src/org/traccar/ExtendedObjectDecoder.java')
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index 2734f5469..ded749e6c 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,15 +59,20 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage); // call after decode
if (originalMessage == decodedMessage) {
ctx.sendUpstream(evt);
- } else if (decodedMessage != null) {
- if (decodedMessage instanceof Collection) {
- for (Object o : (Collection) decodedMessage) {
- saveOriginal(o, originalMessage);
- Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
+ } else {
+ if (decodedMessage == null) {
+ decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
+ }
+ if (decodedMessage != null) {
+ if (decodedMessage instanceof Collection) {
+ for (Object o : (Collection) decodedMessage) {
+ saveOriginal(o, originalMessage);
+ Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
+ }
+ } else {
+ saveOriginal(decodedMessage, originalMessage);
+ Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
- } else {
- saveOriginal(decodedMessage, originalMessage);
- Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
}
}
@@ -75,6 +80,10 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) {
}
+ protected Object handleEmptyMessage(Channel channel, SocketAddress remoteAddress, Object msg) {
+ return null;
+ }
+
protected abstract Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception;
}