aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/ConnectionManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-16 12:33:32 +1200
committerGitHub <noreply@github.com>2016-07-16 12:33:32 +1200
commit6aa4a84c9ef97f5d7980e71cf524a445e87de714 (patch)
treea3e90f40f0c42cc59a6654965ff3dcf37d8d99cb /src/org/traccar/database/ConnectionManager.java
parent6fefd48ab48a2382a9a7bc07e168b48a1ce8bc40 (diff)
parentd71210f1f408c757d4fe3da07829bbc3362a7e93 (diff)
downloadtrackermap-server-6aa4a84c9ef97f5d7980e71cf524a445e87de714.tar.gz
trackermap-server-6aa4a84c9ef97f5d7980e71cf524a445e87de714.tar.bz2
trackermap-server-6aa4a84c9ef97f5d7980e71cf524a445e87de714.zip
Merge pull request #2116 from Abyss777/device_manager_final
Move code related to devices to DeviceManager
Diffstat (limited to 'src/org/traccar/database/ConnectionManager.java')
-rw-r--r--src/org/traccar/database/ConnectionManager.java72
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);