aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
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");