Commit d539a617 authored by Locatelli's avatar Locatelli
Browse files

Merge remote-tracking branch 'origin/V4.0' into ploty2

parents acedc387 fce42683
......@@ -47,7 +47,7 @@ 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);
}
......@@ -60,4 +60,5 @@ public class TokenManager {
public void askForToken(String clientType) {
SessionManager.getInstance(SERVER_ID).requestToken(clientType);
}
}
\ No newline at end of file
......@@ -22,6 +22,8 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import fr.ill.ics.bridge.command.CommandZoneWrapper;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
import fr.ill.ics.util.ConfigManager;
/**
......@@ -75,28 +77,14 @@ public class ChatEvent {
}
public boolean comesFromMe() {
return sender.equals(ConfigManager.getInstance().getServerEndpoint());
}
public String getFormattedSender() {
if (formattedSender == null) {
formattedSender = formatEndPoint(sender);
if (ConfigManager.getInstance().isMainClient()) {
return sender.equals(SessionManager.getInstance(CommandZoneWrapper.SERVER_ID).getInstrumentName());
} else {
return sender.equals(SessionManager.getInstance(CommandZoneWrapper.SERVER_ID).getUserName());
}
return formattedSender;
}
public boolean comesFromServer() {
return sender.equals(NOMAD);
}
public static String formatEndPoint(String endPoint) {
String formattedEndPoint = endPoint.replace("tcp://", "");
int index = formattedEndPoint.indexOf(":");
if (index != -1) {
formattedEndPoint = formattedEndPoint.substring(0, index);
}
return formattedEndPoint;
}
}
\ 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
......@@ -29,6 +29,7 @@ import fr.ill.ics.cameo.RequesterCreationException;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.session.SessionRequests;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.util.ConfigManager;
public class SessionManager {
......@@ -38,10 +39,13 @@ public class SessionManager {
private int clientId = 0;
// If remote access
private String user;
private String remoteUserName;
private String password;
private String instrumentName;
private String user = null;
private static Map<String, SessionManager> instances = new HashMap<String, SessionManager>();
public class ClientAlreadyLaunchedException extends Exception {};
......@@ -176,6 +180,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.setUser(getUser())
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -199,6 +204,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.setUser(getUser())
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -223,6 +229,7 @@ public class SessionManager {
SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder()
.setClientType(clientType)
.setClientID(clientId)
.setUser(getUser())
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -245,6 +252,7 @@ public class SessionManager {
// Create the request.
SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder()
.setClientID(clientId)
.setUser(getUser())
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -310,13 +318,32 @@ public class SessionManager {
return clientId;
}
public void setRemoteAccessInformation(String user, String password, String instrumentName) {
this.user = user;
public void setSessionInformation(String userName, String password, String instrumentName) {
this.remoteUserName = userName;
this.password = password;
this.instrumentName = instrumentName;
}
public String getInstrumentName() {
return instrumentName;
}
public String getUserName() {
return remoteUserName;
}
private String getUser() {
if (user == null) {
if (ConfigManager.getInstance().isRemoteClient()) {
user = getUserName();
} else {
user = getInstrumentName();
}
}
return user;
}
}
\ No newline at end of file
......@@ -27,6 +27,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -86,6 +88,9 @@ public class ConfigManager {
public final static String X_UNCLOSEABLE_SPY = "X_UNCLOSEABLE_SPY";
public final static String Y_UNCLOSEABLE_SPY = "Y_UNCLOSEABLE_SPY";
public final static String MAGNIFY_FACTOR_INDEX = "MAGNIFY_FACTOR_INDEX";
public final static String REMOTE_USER_NAME = "REMOTE_USER_NAME";
public final static String REMOTE_INSTRUMENT = "REMOTE_INSTRUMENT";
public final static String USE_NOMADLOGS = "USE_NOMADLOGS";
public final static String X_CONDITIONS_SPY = "X_CONDITIONS_SPY";
......@@ -147,7 +152,7 @@ public class ConfigManager {
}
}
public void initPreferences() {
private void initPreferences() {
preferences = new Properties();
......@@ -228,6 +233,8 @@ public class ConfigManager {
clientType = getString(ConfigManager.CLIENT_TYPE_PROPERTY).toLowerCase();
mainClient = (clientType.equals(TokenManager.ClientType.MAIN.toString().toLowerCase()) || clientType.equals(TokenManager.ClientType.TABLET.toString().toLowerCase()));
remoteClient = !mainClient;
initPreferences();
}
......@@ -559,6 +566,7 @@ public class ConfigManager {
public String getServerEndpoint() {
// The server endpoint can be entirely defined in the variable 'serverEndpoint'.
String serverEndpoint = getStringOrNothingAtAll("serverEndpoint");
if (serverEndpoint != null) {
......@@ -566,6 +574,24 @@ public class ConfigManager {
return serverEndpoint;
}
// The server endpoint can be partially defined in the variable 'serverPort'.
// In that case, the own IP address is used.
// It is necessary in case of a remote client because this endpoint is passed to the server responder to contact the client for its response.
// In future implementation of requester/responder this may not be necessary.
String serverPort = getStringOrNothingAtAll("serverPort");
// Default value for port.
if (serverPort == null) {
serverPort = "7000";
}
try {
serverEndpoint = "tcp://" + InetAddress.getLocalHost().getHostAddress() + ":" + serverPort;
System.out.println("================> serverEndPoint " + serverEndpoint);
return serverEndpoint;
} catch (UnknownHostException e) {
}
return "tcp://localhost:7000";
}
......
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