Commit 45ff1819 authored by legoc's avatar legoc
Browse files

Added token client ID and modified token visibility

parent 9eea4cc2
......@@ -45,7 +45,7 @@ public class TokenManager {
public void requireToken() {
// for the moment => immediately accepted
TokenEvent event = new TokenEvent("?");
TokenEvent event = new TokenEvent(0, "?");
event.setState(TokenServerState.OWNED);
TokenEventSender.getInstance().notifyTokenEventListeners(event);
}
......
......@@ -27,10 +27,12 @@ public class TokenEvent {
public enum TokenServerState {FREE, OWNED};
private TokenServerState state = TokenServerState.FREE;
private String owner;
private int ownerClientID;
private String ownerEndpoint;
public TokenEvent(String owner) {
this.owner = owner;
public TokenEvent(int ownerClientID, String ownerEndpoint) {
this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint;
}
public void setState(TokenServerState state) {
......@@ -41,8 +43,12 @@ public class TokenEvent {
return state;
}
public String getOwner() {
return owner;
public int getOwnerClientID() {
return ownerClientID;
}
public String getOwnerEndpoint() {
return ownerEndpoint;
}
}
\ No newline at end of file
......@@ -273,7 +273,7 @@ public class DataChangeSubscriber {
}
private void notifyTokenStateChanged(TokenState message) {
System.out.println("TokenState " + message.getState() + " owner " + message.getOwner());
System.out.println("TokenState " + message.getState() + " owner " + message.getOwnerClientID() + " " + message.getOwnerEndpoint());
ClientTokenState state = ClientTokenState.FREE;
......@@ -284,7 +284,7 @@ public class DataChangeSubscriber {
state = ClientTokenState.OWNED;
}
DataNotificationClient.getInstance().tokenStateChanged(state, message.getOwner());
DataNotificationClient.getInstance().tokenStateChanged(state, message.getOwnerClientID(), message.getOwnerEndpoint());
}
private void notifyChatMessage(ChatMessage message) {
......
......@@ -180,9 +180,9 @@ public class DataNotificationClient {
}
}
public void tokenStateChanged(ClientTokenState state, String owner) {
public void tokenStateChanged(ClientTokenState state, int ownerClientID, String ownerEndpoint) {
synchronized (pendingChanges) {
TokenChangedNotificationData change = new TokenChangedNotificationData(state, owner);
TokenChangedNotificationData change = new TokenChangedNotificationData(state, ownerClientID, ownerEndpoint);
updatePendingChanges(change);
}
}
......@@ -506,13 +506,13 @@ public class DataNotificationClient {
}
}
public void notifyTokenStateChanged(ClientTokenState state, String owner) {
public void notifyTokenStateChanged(ClientTokenState state, int ownerClientID, String ownerEndpoint) {
synchronized (tokenChangeListeners) {
Iterator<TokenEventListener> it = tokenChangeListeners.iterator();
while (it.hasNext()) {
TokenEventListener listener = it.next();
TokenEvent event = new TokenEvent(owner);
TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint);
if (state == ClientTokenState.FREE) {
event.setState(TokenEvent.TokenServerState.FREE);
} else {
......@@ -593,7 +593,7 @@ public class DataNotificationClient {
} else if (data instanceof TokenChangedNotificationData) {
TokenChangedNotificationData tokenChangedData = (TokenChangedNotificationData)data;
notifyTokenStateChanged(tokenChangedData.getState(), tokenChangedData.getOwner());
notifyTokenStateChanged(tokenChangedData.getState(), tokenChangedData.getOwnerClientID(), tokenChangedData.getOwnerEndpoint());
} else if (data instanceof ChatNotificationData) {
ChatNotificationData chatData = (ChatNotificationData)data;
......
......@@ -23,19 +23,25 @@ import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientTokenState;
public class TokenChangedNotificationData implements INotificationData {
private ClientTokenState state;
private String owner;
private int ownerClientID;
private String ownerEndpoint;
public TokenChangedNotificationData(ClientTokenState state, String owner) {
public TokenChangedNotificationData(ClientTokenState state, int ownerClientID, String ownerEndpoint) {
this.state = state;
this.owner = owner;
this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint;
}
public ClientTokenState getState() {
return state;
}
public String getOwner() {
return owner;
public int getOwnerClientID() {
return ownerClientID;
}
public String getOwnerEndpoint() {
return ownerEndpoint;
}
public boolean equals(Object obj) {
......@@ -48,15 +54,16 @@ public class TokenChangedNotificationData implements INotificationData {
TokenChangedNotificationData otherOne = (TokenChangedNotificationData)obj;
if (otherOne.getOwner().equals(owner) && otherOne.getState() == state) {
if (otherOne.getOwnerEndpoint().equals(ownerEndpoint)
&& otherOne.getOwnerClientID() == ownerClientID
&& otherOne.getState() == state) {
return true;
}
return false;
}
public int hashCode() {
String id = "token " + owner + "." + state;
String id = "token " + ownerClientID + "." + state;
return id.hashCode();
}
}
\ No newline at end of file
......@@ -133,6 +133,7 @@ public class SessionManager {
// Create the request.
SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -153,7 +154,8 @@ public class SessionManager {
.build();
// Create the request.
SessionRequests.EmptyRequest request = SessionRequests.EmptyRequest.newBuilder()
SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder()
.setClientID(clientId)
.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