diff options
Diffstat (limited to 'src/main/java/org/traccar')
7 files changed, 16 insertions, 22 deletions
diff --git a/src/main/java/org/traccar/MainEventHandler.java b/src/main/java/org/traccar/MainEventHandler.java index e2cad15c6..981888577 100644 --- a/src/main/java/org/traccar/MainEventHandler.java +++ b/src/main/java/org/traccar/MainEventHandler.java @@ -93,7 +93,6 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { cacheManager.updatePosition(position); connectionManager.updatePosition(true, position); - broadcastService.updatePosition(true, position); } } catch (StorageException error) { LOGGER.warn("Failed to update device", error); diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java index 403021c6c..489360619 100644 --- a/src/main/java/org/traccar/api/BaseObjectResource.java +++ b/src/main/java/org/traccar/api/BaseObjectResource.java @@ -16,7 +16,6 @@ */ package org.traccar.api; -import org.traccar.broadcast.BroadcastService; import org.traccar.helper.LogAction; import org.traccar.model.BaseModel; import org.traccar.model.Group; @@ -42,9 +41,6 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour @Inject private CacheManager cacheManager; - @Inject - private BroadcastService broadcastService; - protected final Class<T> baseClass; public BaseObjectResource(Class<T> baseClass) { @@ -72,7 +68,6 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour LogAction.create(getUserId(), entity); storage.addPermission(new Permission(User.class, getUserId(), baseClass, entity.getId())); cacheManager.invalidatePermission(User.class, getUserId(), baseClass, entity.getId()); - broadcastService.invalidatePermission(User.class, getUserId(), baseClass, entity.getId()); LogAction.link(getUserId(), User.class, getUserId(), baseClass, entity.getId()); return Response.ok(entity).build(); @@ -99,7 +94,6 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour new Columns.Exclude("id"), new Condition.Equals("id", "id"))); cacheManager.updateOrInvalidate(entity); - broadcastService.invalidateObject(entity.getClass(), entity.getId()); LogAction.edit(getUserId(), entity); return Response.ok(entity).build(); diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java index e205f2d28..8791a82f9 100644 --- a/src/main/java/org/traccar/api/resource/DeviceResource.java +++ b/src/main/java/org/traccar/api/resource/DeviceResource.java @@ -138,7 +138,6 @@ public class DeviceResource extends BaseObjectResource<Device> { cacheManager.addDevice(position.getDeviceId()); cacheManager.updatePosition(position); connectionManager.updatePosition(true, position); - broadcastService.updatePosition(true, position); } finally { cacheManager.removeDevice(position.getDeviceId()); } diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java index 5ca865c31..44fc897ac 100644 --- a/src/main/java/org/traccar/api/resource/PermissionsResource.java +++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java @@ -17,7 +17,6 @@ package org.traccar.api.resource; import org.traccar.api.BaseResource; -import org.traccar.broadcast.BroadcastService; import org.traccar.helper.LogAction; import org.traccar.model.Permission; import org.traccar.model.UserRestrictions; @@ -46,9 +45,6 @@ public class PermissionsResource extends BaseResource { @Inject private CacheManager cacheManager; - @Inject - private BroadcastService broadcastService; - private void checkPermission(Permission permission) throws StorageException { if (permissionsService.notAdmin(getUserId())) { permissionsService.checkPermission(permission.getOwnerClass(), getUserId(), permission.getOwnerId()); @@ -78,9 +74,6 @@ public class PermissionsResource extends BaseResource { cacheManager.invalidatePermission( permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId()); - broadcastService.invalidatePermission( - permission.getOwnerClass(), permission.getOwnerId(), - permission.getPropertyClass(), permission.getPropertyId()); LogAction.link(getUserId(), permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId()); @@ -105,9 +98,6 @@ public class PermissionsResource extends BaseResource { cacheManager.invalidatePermission( permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId()); - broadcastService.invalidatePermission( - permission.getOwnerClass(), permission.getOwnerId(), - permission.getPropertyClass(), permission.getPropertyId()); LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId()); diff --git a/src/main/java/org/traccar/notificators/NotificatorWeb.java b/src/main/java/org/traccar/notificators/NotificatorWeb.java index 061018ba9..f495042a5 100644 --- a/src/main/java/org/traccar/notificators/NotificatorWeb.java +++ b/src/main/java/org/traccar/notificators/NotificatorWeb.java @@ -57,7 +57,6 @@ public final class NotificatorWeb implements Notificator { copy.set("message", message.getBody()); connectionManager.updateEvent(true, user.getId(), copy); - broadcastService.updateEvent(true, user.getId(), copy); } } diff --git a/src/main/java/org/traccar/session/ConnectionManager.java b/src/main/java/org/traccar/session/ConnectionManager.java index 0e0ea1eb8..c2f602c11 100644 --- a/src/main/java/org/traccar/session/ConnectionManager.java +++ b/src/main/java/org/traccar/session/ConnectionManager.java @@ -285,7 +285,6 @@ public class ConnectionManager implements BroadcastInterface { } updateDevice(true, device); - broadcastService.updateDevice(true, device); } public DeviceState getDeviceState(long deviceId) { @@ -324,7 +323,9 @@ public class ConnectionManager implements BroadcastInterface { @Override public synchronized void updateDevice(boolean local, Device device) { - if (!local && Device.STATUS_ONLINE.equals(device.getStatus())) { + if (local) { + broadcastService.updateDevice(true, device); + } else if (Device.STATUS_ONLINE.equals(device.getStatus())) { timeouts.remove(device.getId()); removeDeviceSession(device.getId()); } @@ -339,6 +340,9 @@ public class ConnectionManager implements BroadcastInterface { @Override public synchronized void updatePosition(boolean local, Position position) { + if (local) { + broadcastService.updatePosition(true, position); + } for (long userId : deviceUsers.getOrDefault(position.getDeviceId(), Collections.emptySet())) { if (listeners.containsKey(userId)) { for (UpdateListener listener : listeners.get(userId)) { @@ -350,6 +354,9 @@ public class ConnectionManager implements BroadcastInterface { @Override public synchronized void updateEvent(boolean local, long userId, Event event) { + if (local) { + broadcastService.updateEvent(true, userId, event); + } if (listeners.containsKey(userId)) { for (UpdateListener listener : listeners.get(userId)) { listener.onUpdateEvent(event); diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index d2ada7d43..bc5fc357f 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -58,6 +58,7 @@ public class CacheManager implements BroadcastInterface { private final Config config; private final Storage storage; + private final BroadcastService broadcastService; private final ReadWriteLock lock = new ReentrantReadWriteLock(); @@ -73,9 +74,10 @@ public class CacheManager implements BroadcastInterface { public CacheManager(Config config, Storage storage, BroadcastService broadcastService) throws StorageException { this.config = config; this.storage = storage; - broadcastService.registerListener(this); + this.broadcastService = broadcastService; invalidateServer(); invalidateUsers(); + broadcastService.registerListener(this); } public Config getConfig() { @@ -198,6 +200,8 @@ public class CacheManager implements BroadcastInterface { } public <T extends BaseModel> void updateOrInvalidate(T object) throws StorageException { + broadcastService.invalidateObject(object.getClass(), object.getId()); + boolean invalidate = false; var before = getObject(object.getClass(), object.getId()); if (before == null) { @@ -231,6 +235,8 @@ public class CacheManager implements BroadcastInterface { public void invalidatePermission( Class<? extends BaseModel> clazz1, long id1, Class<? extends BaseModel> clazz2, long id2) { + broadcastService.invalidatePermission(clazz1, id1, clazz2, id2); + try { invalidate(new CacheKey(clazz1, id1), new CacheKey(clazz2, id2)); } catch (StorageException e) { |