diff options
Diffstat (limited to 'src/org/traccar/database/ConnectionManager.java')
-rw-r--r-- | src/org/traccar/database/ConnectionManager.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index e45c83651..450f2f61f 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -18,6 +18,7 @@ package org.traccar.database; import java.net.SocketAddress; import java.sql.SQLException; import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -27,6 +28,7 @@ import java.util.Set; import org.jboss.netty.channel.Channel; import org.traccar.Protocol; import org.traccar.helper.Log; +import org.traccar.model.Device; import org.traccar.model.Position; public class ConnectionManager { @@ -47,13 +49,14 @@ public class ConnectionManager { } } - public void setActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) { + public void addActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) { activeDevices.put(deviceId, new ActiveDevice(deviceId, protocol, channel, remoteAddress)); } public void removeActiveDevice(Channel channel) { for (ActiveDevice activeDevice : activeDevices.values()) { if (activeDevice.getChannel() == channel) { + updateDevice(activeDevice.getDeviceId(), Device.STATUS_OFFLINE, new Date()); activeDevices.remove(activeDevice.getDeviceId()); break; } @@ -64,12 +67,18 @@ public class ConnectionManager { return activeDevices.get(deviceId); } - public synchronized void update(Position position) { + public synchronized void updateDevice(long deviceId, String status, Date time) { + // TODO update cache and call listener + /*Log.debug(deviceId + " " + status + " " + + new SimpleDateFormat(Log.DATE_FORMAT).format(time));*/ + } + + public synchronized void updatePosition(Position position) { long deviceId = position.getDeviceId(); positions.put(deviceId, position); if (listeners.containsKey(deviceId)) { for (DataCacheListener listener : listeners.get(deviceId)) { - listener.onUpdate(position); + listener.onUpdatePosition(position); } } } @@ -92,7 +101,7 @@ public class ConnectionManager { } public interface DataCacheListener { - void onUpdate(Position position); + void onUpdatePosition(Position position); } public void addListener(Collection<Long> devices, DataCacheListener listener) { |