diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/DeviceSession.java | 3 | ||||
-rw-r--r-- | src/org/traccar/MainEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/api/SecurityRequestFilter.java | 3 | ||||
-rw-r--r-- | src/org/traccar/api/resource/SessionResource.java | 2 | ||||
-rw-r--r-- | src/org/traccar/database/StatisticsManager.java | 22 |
5 files changed, 12 insertions, 20 deletions
diff --git a/src/org/traccar/DeviceSession.java b/src/org/traccar/DeviceSession.java index 45bc5dcde..5e2686f23 100644 --- a/src/org/traccar/DeviceSession.java +++ b/src/org/traccar/DeviceSession.java @@ -21,9 +21,6 @@ public class DeviceSession { public DeviceSession(long deviceId) { this.deviceId = deviceId; - if (Context.getStatisticsManager() != null) { - Context.getStatisticsManager().registerDevice(deviceId); - } } public long getDeviceId() { diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 24aa50117..9f172c584 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -62,7 +62,7 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { } Log.info(s.toString()); - Context.getStatisticsManager().registerMessageStored(); + Context.getStatisticsManager().registerMessageStored(position.getDeviceId()); } } diff --git a/src/org/traccar/api/SecurityRequestFilter.java b/src/org/traccar/api/SecurityRequestFilter.java index ff4241b97..9e0f03de7 100644 --- a/src/org/traccar/api/SecurityRequestFilter.java +++ b/src/org/traccar/api/SecurityRequestFilter.java @@ -55,7 +55,6 @@ public class SecurityRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { - Context.getStatisticsManager().registerRequest(); if (requestContext.getMethod().equals("OPTIONS")) { return; @@ -70,6 +69,7 @@ public class SecurityRequestFilter implements ContainerRequestFilter { String[] auth = decodeBasicAuth(authHeader); User user = Context.getDataManager().login(auth[0], auth[1]); if (user != null) { + Context.getStatisticsManager().registerRequest(user.getId()); securityContext = new UserSecurityContext(new UserPrincipal(user.getId())); } } catch (SQLException e) { @@ -80,6 +80,7 @@ public class SecurityRequestFilter implements ContainerRequestFilter { Long userId = (Long) request.getSession().getAttribute(SessionResource.USER_ID_KEY); if (userId != null) { + Context.getStatisticsManager().registerRequest(userId); securityContext = new UserSecurityContext(new UserPrincipal(userId)); } diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java index 4ab1960c9..deed70b37 100644 --- a/src/org/traccar/api/resource/SessionResource.java +++ b/src/org/traccar/api/resource/SessionResource.java @@ -73,7 +73,6 @@ public class SessionResource extends BaseResource { } if (userId != null) { - Context.getStatisticsManager().registerUser(userId); return Context.getPermissionsManager().getUser(userId); } else { throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); @@ -86,7 +85,6 @@ public class SessionResource extends BaseResource { @FormParam("email") String email, @FormParam("password") String password) throws SQLException { User user = Context.getPermissionsManager().login(email, password); if (user != null) { - Context.getStatisticsManager().registerUser(user.getId()); request.getSession().setAttribute(USER_ID_KEY, user.getId()); return user; } else { diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java index b21380332..b9af4d9b7 100644 --- a/src/org/traccar/database/StatisticsManager.java +++ b/src/org/traccar/database/StatisticsManager.java @@ -27,7 +27,7 @@ import java.util.Set; public class StatisticsManager { - private static final int SPLIT_MODE = Calendar.MINUTE; + private static final int SPLIT_MODE = Calendar.DAY_OF_MONTH; private int lastUpdate = Calendar.getInstance().get(SPLIT_MODE); @@ -64,19 +64,12 @@ public class StatisticsManager { } } - public synchronized void registerUser(long userId) { - checkSplit(); - users.add(userId); - } - - public synchronized void registerDevice(long deviceId) { - checkSplit(); - devices.add(deviceId); - } - - public synchronized void registerRequest() { + public synchronized void registerRequest(long userId) { checkSplit(); requests += 1; + if (userId != 0) { + users.add(userId); + } } public synchronized void registerMessageReceived() { @@ -84,9 +77,12 @@ public class StatisticsManager { messagesReceived += 1; } - public synchronized void registerMessageStored() { + public synchronized void registerMessageStored(long deviceId) { checkSplit(); messagesStored += 1; + if (deviceId != 0) { + devices.add(deviceId); + } } } |