diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/controller/SessionController.java b/src/java/org/jivesoftware/openfire/plugin/rest/controller/SessionController.java index 070687b3b..2436a588f 100644 --- a/src/java/org/jivesoftware/openfire/plugin/rest/controller/SessionController.java +++ b/src/java/org/jivesoftware/openfire/plugin/rest/controller/SessionController.java @@ -65,6 +65,18 @@ public SessionEntities getAllSessions() throws ServiceException { return sessionEntities; } + /** + * Gets the number of all sessions. + * + * @return the number of all sessions + * @throws ServiceException the service exception + */ + public SessionEntities getAllSessionsLoad() throws ServiceException { + Collection clientSessions = SessionManager.getInstance().getSessions(); + SessionEntities sessionEntities = convertToSessionEntitiesLoad(clientSessions); + return sessionEntities; + } + /** * Removes the user sessions. * @@ -79,6 +91,34 @@ public void removeUserSessions(String username) throws ServiceException { } } + /** + * Convert to session entities. + * + * @param clientSessions the client sessions + * @return the session entities + * @throws ServiceException the service exception + */ + private SessionEntities convertToSessionEntitiesLoad(Collection clientSessions) throws ServiceException { + int load = 0; + + List sessions = new ArrayList(); + SessionEntities sessionEntities = new SessionEntities(sessions); + + for (ClientSession clientSession : clientSessions) { + if (clientSession instanceof LocalClientSession) { + ++load; + } + } + + SessionEntity session = new SessionEntity(); + + session.setLoad(load); + + sessions.add(session); + + return sessionEntities; + } + /** * Convert to session entities. * @@ -144,7 +184,11 @@ private SessionEntities convertToSessionEntities(Collection clien } session.setPriority(clientSession.getPresence().getPriority()); } - + + // Load is set to the real local load of each server when specific + // REST query is received. + session.setLoad(0); + try { session.setHostAddress(clientSession.getHostAddress()); session.setHostName(clientSession.getHostName()); diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/entity/SessionEntity.java b/src/java/org/jivesoftware/openfire/plugin/rest/entity/SessionEntity.java index d29750f95..dfc8edfbc 100644 --- a/src/java/org/jivesoftware/openfire/plugin/rest/entity/SessionEntity.java +++ b/src/java/org/jivesoftware/openfire/plugin/rest/entity/SessionEntity.java @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlType; @XmlRootElement(name = "session") -@XmlType(propOrder = { "sessionId", "username", "resource", "node", "sessionStatus", "presenceStatus", "presenceMessage", "priority", +@XmlType(propOrder = { "sessionId", "username", "resource", "node", "sessionStatus", "presenceStatus", "presenceMessage", "priority", "load", "hostAddress", "hostName", "creationDate", "lastActionDate", "secure" }) public class SessionEntity { @@ -19,6 +19,7 @@ public class SessionEntity { private String presenceStatus; private String presenceMessage; private int priority; + private int load; private String hostAddress; private String hostName; @@ -92,6 +93,15 @@ public void setPresenceMessage(String presenceMessage) { this.presenceMessage = presenceMessage; } + @XmlElement + public int getLoad() { + return load; + } + + public void setLoad(int load) { + this.load = load; + } + @XmlElement public int getPriority() { return priority; diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/service/SessionService.java b/src/java/org/jivesoftware/openfire/plugin/rest/service/SessionService.java index fd81c077a..98e396e3e 100644 --- a/src/java/org/jivesoftware/openfire/plugin/rest/service/SessionService.java +++ b/src/java/org/jivesoftware/openfire/plugin/rest/service/SessionService.java @@ -29,6 +29,13 @@ public SessionEntities getAllSessions() throws ServiceException { return sessionController.getAllSessions(); } + @GET + @Path("/load") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public SessionEntities getAllSessionsLoad() throws ServiceException { + return sessionController.getAllSessionsLoad(); + } + @GET @Path("/{username}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })