aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-06-29 10:49:13 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-06-29 10:49:13 +1200
commit55448d82b2971bc16c67bfa2b2e996d81c4c702e (patch)
tree565ee245ea0e98b88674b775147fbc6d3e1933cb /src/org/traccar/database
parent88b3f00f3855aa408c7859051efdcb5b37fe559f (diff)
parentd1c4cd526845aad56c5b0a3e20454638bbc7fecc (diff)
downloadtrackermap-server-55448d82b2971bc16c67bfa2b2e996d81c4c702e.tar.gz
trackermap-server-55448d82b2971bc16c67bfa2b2e996d81c4c702e.tar.bz2
trackermap-server-55448d82b2971bc16c67bfa2b2e996d81c4c702e.zip
Merge branch implement commands (fix #1271)
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/ActiveDevice.java37
-rw-r--r--src/org/traccar/database/DataManager.java13
2 files changed, 50 insertions, 0 deletions
diff --git a/src/org/traccar/database/ActiveDevice.java b/src/org/traccar/database/ActiveDevice.java
new file mode 100644
index 000000000..29f2b47d2
--- /dev/null
+++ b/src/org/traccar/database/ActiveDevice.java
@@ -0,0 +1,37 @@
+package org.traccar.database;
+
+import org.jboss.netty.channel.Channel;
+import org.traccar.Protocol;
+import org.traccar.http.commands.GpsCommand;
+
+import java.net.SocketAddress;
+
+public class ActiveDevice {
+ private String uniqueId;
+ private Protocol protocol;
+ private Channel channel;
+ private SocketAddress remoteAddress;
+
+ public ActiveDevice(String uniqueId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
+ this.uniqueId = uniqueId;
+ this.protocol = protocol;
+ this.channel = channel;
+ this.remoteAddress = remoteAddress;
+ }
+
+ public Channel getChannel() {
+ return channel;
+ }
+
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ public void sendCommand(GpsCommand command) {
+ protocol.sendCommand(this, command);
+ }
+
+ public void write(Object message) {
+ getChannel().write(message, remoteAddress);
+ }
+}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 496a5a1b6..62275af3c 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -17,6 +17,7 @@ package org.traccar.database;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.io.File;
+import java.net.SocketAddress;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
@@ -32,7 +33,10 @@ import java.util.Map;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.sql.DataSource;
+
+import org.jboss.netty.channel.Channel;
import org.traccar.Context;
+import org.traccar.Protocol;
import org.traccar.helper.DriverDelegate;
import org.traccar.helper.Log;
import org.traccar.http.AsyncServlet;
@@ -52,6 +56,7 @@ public class DataManager {
private DataSource dataSource;
private final Map<String, Device> devices = new HashMap<String, Device>();
+ private Map<String, ActiveDevice> activeDevices = new HashMap<String, ActiveDevice>();
private long devicesLastUpdate;
private long devicesRefreshDelay;
@@ -74,6 +79,14 @@ public class DataManager {
return dataSource;
}
+ public void setActiveDevice(String uniqueId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
+ this.activeDevices.put(uniqueId, new ActiveDevice(uniqueId, protocol, channel, remoteAddress));
+ }
+
+ public ActiveDevice getActiveDevice(String uniqueId) {
+ return this.activeDevices.get(uniqueId);
+ }
+
private void initDatabase(Properties properties) throws Exception {
String jndiName = properties.getProperty("database.jndi");