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 { ...@@ -47,7 +47,7 @@ public class TokenManager {
public void requireToken() { public void requireToken() {
// for the moment => immediately accepted // for the moment => immediately accepted
TokenEvent event = new TokenEvent(0, "?"); TokenEvent event = new TokenEvent(0, "?", "?");
event.setState(TokenServerState.OWNED); event.setState(TokenServerState.OWNED);
} }
...@@ -60,4 +60,5 @@ public class TokenManager { ...@@ -60,4 +60,5 @@ public class TokenManager {
public void askForToken(String clientType) { public void askForToken(String clientType) {
SessionManager.getInstance(SERVER_ID).requestToken(clientType); SessionManager.getInstance(SERVER_ID).requestToken(clientType);
} }
} }
\ No newline at end of file
...@@ -22,6 +22,8 @@ import java.time.LocalDate; ...@@ -22,6 +22,8 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; 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; import fr.ill.ics.util.ConfigManager;
/** /**
...@@ -75,28 +77,14 @@ public class ChatEvent { ...@@ -75,28 +77,14 @@ public class ChatEvent {
} }
public boolean comesFromMe() { public boolean comesFromMe() {
return sender.equals(ConfigManager.getInstance().getServerEndpoint()); if (ConfigManager.getInstance().isMainClient()) {
} return sender.equals(SessionManager.getInstance(CommandZoneWrapper.SERVER_ID).getInstrumentName());
} else {
public String getFormattedSender() { return sender.equals(SessionManager.getInstance(CommandZoneWrapper.SERVER_ID).getUserName());
if (formattedSender == null) {
formattedSender = formatEndPoint(sender);
} }
return formattedSender;
} }
public boolean comesFromServer() { public boolean comesFromServer() {
return sender.equals(NOMAD); 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 { ...@@ -31,10 +31,12 @@ public class TokenEvent {
private TokenServerState state = TokenServerState.FREE; private TokenServerState state = TokenServerState.FREE;
private int ownerClientID; private int ownerClientID;
private String ownerEndpoint; private String ownerEndpoint;
private String user;
public TokenEvent(int ownerClientID, String ownerEndpoint) { public TokenEvent(int ownerClientID, String ownerEndpoint, String user) {
this.ownerClientID = ownerClientID; this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint; this.ownerEndpoint = ownerEndpoint;
this.user = user;
} }
public void setRemoteControlState(RemoteControlServerState remoteControlState) { public void setRemoteControlState(RemoteControlServerState remoteControlState) {
...@@ -61,4 +63,8 @@ public class TokenEvent { ...@@ -61,4 +63,8 @@ public class TokenEvent {
return ownerEndpoint; return ownerEndpoint;
} }
public String getUser() {
return user;
}
} }
\ No newline at end of file
...@@ -294,7 +294,7 @@ public class DataChangeSubscriber { ...@@ -294,7 +294,7 @@ public class DataChangeSubscriber {
state = ClientTokenState.OWNED; 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) { private void notifyChatMessage(ChatMessage message) {
......
...@@ -180,9 +180,9 @@ public class DataNotificationClient { ...@@ -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) { synchronized (pendingChanges) {
TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint); TokenChangedNotificationData change = new TokenChangedNotificationData(remoteControlState, state, ownerClientID, ownerEndpoint, user);
updatePendingChanges(change); updatePendingChanges(change);
} }
} }
...@@ -506,13 +506,13 @@ public class DataNotificationClient { ...@@ -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) { synchronized (tokenChangeListeners) {
Iterator<TokenEventListener> it = tokenChangeListeners.iterator(); Iterator<TokenEventListener> it = tokenChangeListeners.iterator();
while (it.hasNext()) { while (it.hasNext()) {
TokenEventListener listener = it.next(); TokenEventListener listener = it.next();
TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint); TokenEvent event = new TokenEvent(ownerClientID, ownerEndpoint, user);
if (clientRemoteControlState == ClientRemoteControlState.DISABLED) { if (clientRemoteControlState == ClientRemoteControlState.DISABLED) {
event.setRemoteControlState(TokenEvent.RemoteControlServerState.DISABLED); event.setRemoteControlState(TokenEvent.RemoteControlServerState.DISABLED);
...@@ -599,7 +599,7 @@ public class DataNotificationClient { ...@@ -599,7 +599,7 @@ public class DataNotificationClient {
} else if (data instanceof TokenChangedNotificationData) { } else if (data instanceof TokenChangedNotificationData) {
TokenChangedNotificationData tokenChangedData = (TokenChangedNotificationData)data; 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) { } else if (data instanceof ChatNotificationData) {
ChatNotificationData chatData = (ChatNotificationData)data; ChatNotificationData chatData = (ChatNotificationData)data;
......
...@@ -27,12 +27,14 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -27,12 +27,14 @@ public class TokenChangedNotificationData implements INotificationData {
private ClientTokenState state; private ClientTokenState state;
private int ownerClientID; private int ownerClientID;
private String ownerEndpoint; 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.remoteControlState = remoteControlState;
this.state = state; this.state = state;
this.ownerClientID = ownerClientID; this.ownerClientID = ownerClientID;
this.ownerEndpoint = ownerEndpoint; this.ownerEndpoint = ownerEndpoint;
this.user = user;
} }
public ClientRemoteControlState getRemoteControlState() { public ClientRemoteControlState getRemoteControlState() {
...@@ -51,6 +53,10 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -51,6 +53,10 @@ public class TokenChangedNotificationData implements INotificationData {
return ownerEndpoint; return ownerEndpoint;
} }
public String getUser() {
return user;
}
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(this == obj) { if(this == obj) {
return true; return true;
...@@ -63,6 +69,7 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -63,6 +69,7 @@ public class TokenChangedNotificationData implements INotificationData {
if (otherOne.getOwnerEndpoint().equals(ownerEndpoint) if (otherOne.getOwnerEndpoint().equals(ownerEndpoint)
&& otherOne.getOwnerClientID() == ownerClientID && otherOne.getOwnerClientID() == ownerClientID
&& otherOne.getUser() == user
&& otherOne.getState() == state && otherOne.getState() == state
&& otherOne.getRemoteControlState() == remoteControlState) { && otherOne.getRemoteControlState() == remoteControlState) {
return true; return true;
...@@ -71,7 +78,7 @@ public class TokenChangedNotificationData implements INotificationData { ...@@ -71,7 +78,7 @@ public class TokenChangedNotificationData implements INotificationData {
} }
public int hashCode() { public int hashCode() {
String id = "token " + ownerClientID + "." + state + "." + remoteControlState; String id = "token " + ownerClientID + "." + user + "." + state + "." + remoteControlState;
return id.hashCode(); return id.hashCode();
} }
} }
\ No newline at end of file
...@@ -29,6 +29,7 @@ import fr.ill.ics.cameo.RequesterCreationException; ...@@ -29,6 +29,7 @@ import fr.ill.ics.cameo.RequesterCreationException;
import fr.ill.ics.nomadserver.common.Common; import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.session.SessionRequests; import fr.ill.ics.nomadserver.session.SessionRequests;
import fr.ill.ics.nscclient.serverconnection.ServerInstance; import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.util.ConfigManager;
public class SessionManager { public class SessionManager {
...@@ -38,10 +39,13 @@ public class SessionManager { ...@@ -38,10 +39,13 @@ public class SessionManager {
private int clientId = 0; private int clientId = 0;
// If remote access // If remote access
private String user; private String remoteUserName;
private String password; private String password;
private String instrumentName; private String instrumentName;
private String user = null;
private static Map<String, SessionManager> instances = new HashMap<String, SessionManager>(); private static Map<String, SessionManager> instances = new HashMap<String, SessionManager>();
public class ClientAlreadyLaunchedException extends Exception {}; public class ClientAlreadyLaunchedException extends Exception {};
...@@ -176,6 +180,7 @@ public class SessionManager { ...@@ -176,6 +180,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder() SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType) .setClientType(clientType)
.setClientID(clientId) .setClientID(clientId)
.setUser(getUser())
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -199,6 +204,7 @@ public class SessionManager { ...@@ -199,6 +204,7 @@ public class SessionManager {
SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder() SessionRequests.RemoteControlRequest request = SessionRequests.RemoteControlRequest.newBuilder()
.setClientType(clientType) .setClientType(clientType)
.setClientID(clientId) .setClientID(clientId)
.setUser(getUser())
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -223,6 +229,7 @@ public class SessionManager { ...@@ -223,6 +229,7 @@ public class SessionManager {
SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder() SessionRequests.GetTokenRequest request = SessionRequests.GetTokenRequest.newBuilder()
.setClientType(clientType) .setClientType(clientType)
.setClientID(clientId) .setClientID(clientId)
.setUser(getUser())
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -245,6 +252,7 @@ public class SessionManager { ...@@ -245,6 +252,7 @@ public class SessionManager {
// Create the request. // Create the request.
SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder() SessionRequests.ReleaseTokenRequest request = SessionRequests.ReleaseTokenRequest.newBuilder()
.setClientID(clientId) .setClientID(clientId)
.setUser(getUser())
.build(); .build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray()); sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
...@@ -310,13 +318,32 @@ public class SessionManager { ...@@ -310,13 +318,32 @@ public class SessionManager {
return clientId; return clientId;
} }
public void setRemoteAccessInformation(String user, String password, String instrumentName) { public void setSessionInformation(String userName, String password, String instrumentName) {
this.user = user; this.remoteUserName = userName;
this.password = password; this.password = password;
this.instrumentName = instrumentName; this.instrumentName = instrumentName;
} }
public String getInstrumentName() { public String getInstrumentName() {
return instrumentName; 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; ...@@ -27,6 +27,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
...@@ -86,6 +88,9 @@ public class ConfigManager { ...@@ -86,6 +88,9 @@ public class ConfigManager {
public final static String X_UNCLOSEABLE_SPY = "X_UNCLOSEABLE_SPY"; public final static String X_UNCLOSEABLE_SPY = "X_UNCLOSEABLE_SPY";
public final static String Y_UNCLOSEABLE_SPY = "Y_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 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 USE_NOMADLOGS = "USE_NOMADLOGS";
public final static String X_CONDITIONS_SPY = "X_CONDITIONS_SPY"; public final static String X_CONDITIONS_SPY = "X_CONDITIONS_SPY";
...@@ -147,7 +152,7 @@ public class ConfigManager { ...@@ -147,7 +152,7 @@ public class ConfigManager {
} }
} }
public void initPreferences() { private void initPreferences() {
preferences = new Properties(); preferences = new Properties();
...@@ -228,6 +233,8 @@ public class ConfigManager { ...@@ -228,6 +233,8 @@ public class ConfigManager {
clientType = getString(ConfigManager.CLIENT_TYPE_PROPERTY).toLowerCase(); clientType = getString(ConfigManager.CLIENT_TYPE_PROPERTY).toLowerCase();
mainClient = (clientType.equals(TokenManager.ClientType.MAIN.toString().toLowerCase()) || clientType.equals(TokenManager.ClientType.TABLET.toString().toLowerCase())); mainClient = (clientType.equals(TokenManager.ClientType.MAIN.toString().toLowerCase()) || clientType.equals(TokenManager.ClientType.TABLET.toString().toLowerCase()));
remoteClient = !mainClient; remoteClient = !mainClient;
initPreferences();
} }
...@@ -559,6 +566,7 @@ public class ConfigManager { ...@@ -559,6 +566,7 @@ public class ConfigManager {
public String getServerEndpoint() { public String getServerEndpoint() {
// The server endpoint can be entirely defined in the variable 'serverEndpoint'.
String serverEndpoint = getStringOrNothingAtAll("serverEndpoint"); String serverEndpoint = getStringOrNothingAtAll("serverEndpoint");
if (serverEndpoint != null) { if (serverEndpoint != null) {
...@@ -566,6 +574,24 @@ public class ConfigManager { ...@@ -566,6 +574,24 @@ public class ConfigManager {
return serverEndpoint; 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"; 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