Commit c1e4efeb authored by legoc's avatar legoc
Browse files

Added user in different SessionManager requests and notification of token state

parent d0b33f70
......@@ -47,17 +47,17 @@ public class TokenManager {
public void requireToken() {
// for the moment => immediately accepted
TokenEvent event = new TokenEvent(0, "?");
TokenEvent event = new TokenEvent(0, "?", "?");
event.setState(TokenServerState.OWNED);
}
public void freeToken() {
SessionManager.getInstance(SERVER_ID).releaseToken();
SessionManager.getInstance(SERVER_ID).releaseToken("USER");
}
public void askForToken(String clientType) {
SessionManager.getInstance(SERVER_ID).requestToken(clientType);
SessionManager.getInstance(SERVER_ID).requestToken(clientType, "USER");
}
}
\ No newline at end of file
......@@ -31,10 +31,12 @@ public class TokenEvent {
private TokenServerState state = TokenServerState.FREE;
private int ownerClientID;
private String ownerEndpoint;
private String user;
public TokenEvent(int ownerClientID, String ownerEndpoint) {
public TokenEvent(int ownerClientID, String ownerEndpoint, String user) {
this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint;
this.user = user;
}
public void setRemoteControlState(RemoteControlServerState remoteControlState) {
......@@ -61,4 +63,8 @@ public class TokenEvent {
return ownerEndpoint;
}
public String getUser() {
return user;
}
}
\ No newline at end of file
......@@ -294,7 +294,7 @@ public class DataChangeSubscriber {
state = ClientTokenState.OWNED;
}
DataNotificationClient.getInstance().tokenStateChanged(remoteControlState, state, message.getOwnerClientID(), message.getOwnerEndpoint());
DataNotificationClient.getInstance().tokenStateChanged(remoteControlState, state, message.getOwnerClientID(), message.getOwnerEndpoint(), message.getUser());
}
private void notifyChatMessage(ChatMessage message) {
......
......@@ -180,9 +180,9 @@ public class DataNotificationClient {
}
}
public void tokenStateChanged(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) {
public void tokenStateChanged(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint, String user) {
synchronized (pendingChanges) {
TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint);
TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint, user);
updatePendingChanges(change);
}
}
......@@ -506,13 +506,13 @@ public class DataNotificationClient {
}
}
public void notifyTokenStateChanged(ClientRemoteControlState clientRemoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) {
public void notifyTokenStateChanged(ClientRemoteControlState clientRemoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint, String user) {
synchronized (tokenChangeListeners) {
Iterator<TokenEventListener> it = tokenChangeListeners.iterator();
while (it.hasNext()) {
TokenEventListener listener = it.next();
TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint);
TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint, user);
if (clientRemoteControlState == ClientRemoteControlState.DISABLED) {
event.setRemoteControlState(TokenEvent.RemoteControlServerState.DISABLED);
......@@ -599,7 +599,7 @@ public class DataNotificationClient {
} else if (data instanceof TokenChangedNotificationData) {
TokenChangedNotificationData tokenChangedData = (TokenChangedNotificationData)data;
notifyTokenStateChanged(tokenChangedData.getRemoteControlState(), tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint());
notifyTokenStateChanged(tokenChangedData.getRemoteControlState(), tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint(), tokenChangedData.getUser());
} else if (data instanceof ChatNotificationData) {
ChatNotificationData chatData = (ChatNotificationData)data;
......
......@@ -27,12 +27,14 @@ public class TokenChangedNotificationData implements INotificationData {
private ClientTokenState state;
private int ownerClientID;
private String ownerEndpoint;
private String user;
public TokenChangedNotificationData(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint) {
public TokenChangedNotificationData(ClientRemoteControlState remoteControlState, ClientTokenState state, int ownerClientID, String ownerEndpoint, String user) {
this.remoteControlState = remoteControlState;
this.state = state;
this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint;
this.user = user;
}
public ClientRemoteControlState getRemoteControlState() {
......@@ -51,6 +53,10 @@ public class TokenChangedNotificationData implements INotificationData {
return ownerEndpoint;
}
public String getUser() {
return user;
}
public boolean equals(Object obj) {
if(this == obj) {
return true;
......@@ -63,6 +69,7 @@ public class TokenChangedNotificationData implements INotificationData {
if (otherOne.getOwnerEndpoint().equals(ownerEndpoint)
&& otherOne.getOwnerClientID() == ownerClientID
&& otherOne.getUser() == user
&& otherOne.getState() == state
&& otherOne.getRemoteControlState() == remoteControlState) {
return true;
......@@ -71,7 +78,7 @@ public class TokenChangedNotificationData implements INotificationData {
}
public int hashCode() {
String id = "token " + ownerClientID + "." + state + "." + remoteControlState;
String id = "token " + ownerClientID + "." + user + "." + state + "." + remoteControlState;
return id.hashCode();
}
}
\ No newline at end of file
......@@ -165,7 +165,7 @@ public class SessionManager {
}
}
public void enableRemoteControl(String clientType) {
public void enableRemoteControl(String clientType, String user) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
......@@ -176,6 +176,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.setUser(user)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -188,7 +189,7 @@ public class SessionManager {
}
}
public void disableRemoteControl(String clientType) {
public void disableRemoteControl(String clientType, String user) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
......@@ -199,6 +200,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.setUser(user)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -212,7 +214,7 @@ public class SessionManager {
}
public void requestToken(String clientType) {
public void requestToken(String clientType, String user) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
......@@ -223,6 +225,7 @@ public class SessionManager {
SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.setUser(user)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -235,7 +238,7 @@ public class SessionManager {
}
}
public void releaseToken() {
public void releaseToken(String user) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
......@@ -245,6 +248,7 @@ public class SessionManager {
// Create the request.
SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder()
.setClientID(clientId)
.setUser(user)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment