Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to return load on each server i.e. number of local sessions. #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientSession> clientSessions = SessionManager.getInstance().getSessions();
SessionEntities sessionEntities = convertToSessionEntitiesLoad(clientSessions);
return sessionEntities;
}

/**
* Removes the user sessions.
*
Expand All @@ -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<ClientSession> clientSessions) throws ServiceException {
int load = 0;

List<SessionEntity> sessions = new ArrayList<SessionEntity>();
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.
*
Expand Down Expand Up @@ -144,7 +184,11 @@ private SessionEntities convertToSessionEntities(Collection<ClientSession> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down