diff options
author | ninioe <ninioe@gmail.com> | 2016-07-19 09:07:23 +0300 |
---|---|---|
committer | ninioe <ninioe@gmail.com> | 2016-07-19 09:07:23 +0300 |
commit | ef40f3317392068692606b484c6782b95b554cbf (patch) | |
tree | 41c48e6c87620a6444aed0ad5706a94e26b1662d /src/org/traccar/database/ConnectionManager.java | |
parent | 04627d7473e4ea21d6ecd950cbb3fdd6fa249429 (diff) | |
parent | d3e063cf9de8a45bed4dfe87b73aadfd8d2edeab (diff) | |
download | traccar-server-ef40f3317392068692606b484c6782b95b554cbf.tar.gz traccar-server-ef40f3317392068692606b484c6782b95b554cbf.tar.bz2 traccar-server-ef40f3317392068692606b484c6782b95b554cbf.zip |
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/database/ConnectionManager.java')
-rw-r--r-- | src/org/traccar/database/ConnectionManager.java | 72 |
1 files changed, 21 insertions, 51 deletions
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index 8796673b1..46ccab81e 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -28,12 +28,9 @@ import org.traccar.model.Position; 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; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -45,21 +42,11 @@ public class ConnectionManager { private final long deviceTimeout; private final Map<Long, ActiveDevice> activeDevices = new HashMap<>(); - private final Map<Long, Position> positions = new HashMap<>(); private final Map<Long, Set<UpdateListener>> listeners = new HashMap<>(); private final Map<Long, Timeout> timeouts = new HashMap<>(); - public ConnectionManager(DataManager dataManager) { + public ConnectionManager() { deviceTimeout = Context.getConfig().getLong("status.timeout", DEFAULT_TIMEOUT) * 1000; - if (dataManager != null) { - try { - for (Position position : dataManager.getLatestPositions()) { - positions.put(position.getDeviceId(), position); - } - } catch (SQLException error) { - Log.warning(error); - } - } } public void addActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) { @@ -80,31 +67,28 @@ public class ConnectionManager { return activeDevices.get(deviceId); } - public synchronized void updateDevice(final long deviceId, String status, Date time) { + public void updateDevice(final long deviceId, String status, Date time) { Device device = Context.getIdentityManager().getDeviceById(deviceId); if (device == null) { return; } - if (status.equals(Device.STATUS_MOVING) || status.equals(Device.STATUS_STOPPED)) { - device.setMotion(status); - } else { - if (!status.equals(device.getStatus())) { - Event event = new Event(Event.TYPE_DEVICE_OFFLINE, deviceId); - if (status.equals(Device.STATUS_ONLINE)) { - event.setType(Event.TYPE_DEVICE_ONLINE); - } - if (Context.getNotificationManager() != null) { - Context.getNotificationManager().updateEvent(event, null); - } + if (!status.equals(device.getStatus())) { + Event event = new Event(Event.TYPE_DEVICE_OFFLINE, deviceId); + if (status.equals(Device.STATUS_ONLINE)) { + event.setType(Event.TYPE_DEVICE_ONLINE); } - device.setStatus(status); - - Timeout timeout = timeouts.remove(deviceId); - if (timeout != null) { - timeout.cancel(); + if (Context.getNotificationManager() != null) { + Context.getNotificationManager().updateEvent(event, null); } } + device.setStatus(status); + + Timeout timeout = timeouts.remove(deviceId); + if (timeout != null) { + timeout.cancel(); + } + if (time != null) { device.setLastUpdate(time); @@ -122,12 +106,16 @@ public class ConnectionManager { } try { - Context.getDataManager().updateDeviceStatus(device); + Context.getDeviceManager().updateDeviceStatus(device); } catch (SQLException error) { Log.warning(error); } - for (long userId : Context.getPermissionsManager().getDeviceUsers(deviceId)) { + updateDevice(device); + } + + public synchronized void updateDevice(Device device) { + for (long userId : Context.getPermissionsManager().getDeviceUsers(device.getId())) { if (listeners.containsKey(userId)) { for (UpdateListener listener : listeners.get(userId)) { listener.onUpdateDevice(device); @@ -138,7 +126,6 @@ public class ConnectionManager { public synchronized void updatePosition(Position position) { long deviceId = position.getDeviceId(); - positions.put(deviceId, position); for (long userId : Context.getPermissionsManager().getDeviceUsers(deviceId)) { if (listeners.containsKey(userId)) { @@ -157,23 +144,6 @@ public class ConnectionManager { } } - public Position getLastPosition(long deviceId) { - return positions.get(deviceId); - } - - public synchronized Collection<Position> getInitialState(long userId) { - - List<Position> result = new LinkedList<>(); - - for (long deviceId : Context.getPermissionsManager().getDevicePermissions(userId)) { - if (positions.containsKey(deviceId)) { - result.add(positions.get(deviceId)); - } - } - - return result; - } - public interface UpdateListener { void onUpdateDevice(Device device); void onUpdatePosition(Position position); |