Commit a3350ce9 authored by ics's avatar ics

Merge branch V3.1_182 into master

parent 1a981228
......@@ -6,7 +6,11 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
......
3.1.10 DD/MM/YYYY
------
3.1.9 12/10/2018
-----
* Change HashMap to TreeMap so that controller and property combo in generic command boxes are sorted.
3.1.8 DD/MM/YYYY
-----
* Remove deprecated code (since Java 10).
3.1.7 30/08/2018
-----
* Modifications for dynamic properties management.
3.1.6 06/04/2018
-----
* Added more control on the subscriber termination in survey.
3.1.5 06/04/2018
-----
* Do not call logoutAll in login. The call is made in the main application (NomadGUI, etc.).
3.1.4 13/03/2018
-----
* Avoid a NullPointerException when ConfigurationException.controllerName is null.
* Fix bug: Bad initialisation of a for loop command box while launching Nomad while the command zone already contains a for loop command box.
3.1.3 09/01/2018
-----
* Fix bug: when getting servant for a property, Nomad searches among controllers without checking before that the servant is really a controller and not a driver...
......
......@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.ill.ics</groupId>
<artifactId>nomadcommandsystem</artifactId>
<version>3.1.4-SNAPSHOT</version>
<version>3.1.9</version>
<name>NomadCommandSystem</name>
<description>Java bridge for the communication with the Nomad server</description>
<scm>
......@@ -54,14 +54,25 @@
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-api-java-jzmq</artifactId>
<version>0.1.2-SNAPSHOT</version>
<artifactId>protobuf-lite</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-api</artifactId>
<version>0.1.4</version>
<exclusions>
<exclusion>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-com-jeromq</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-com-jzmq</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -25,7 +25,7 @@ import java.util.Map.Entry;
import fr.ill.ics.nscclient.log.LogSubscriber;
import fr.ill.ics.nscclient.notification.DataNotificationClient;
import fr.ill.ics.nscclient.notification.commandzone.CommandZoneEventClient;
import fr.ill.ics.nscclient.survey.SurveySubcriberImpl;
import fr.ill.ics.nscclient.survey.SurveySubscriberImpl;
public class ChangeManager {
......@@ -56,10 +56,10 @@ public class ChangeManager {
}
// Iterating the map of survey subscribers
Map<String, SurveySubcriberImpl> surveySubscriberMap = SurveySubcriberImpl.getInstances();
Iterator<Entry<String, SurveySubcriberImpl>> it2 = surveySubscriberMap.entrySet().iterator();
Map<String, SurveySubscriberImpl> surveySubscriberMap = SurveySubscriberImpl.getInstances();
Iterator<Entry<String, SurveySubscriberImpl>> it2 = surveySubscriberMap.entrySet().iterator();
while (it2.hasNext()) {
SurveySubcriberImpl surveySubscriber = it2.next().getValue();
SurveySubscriberImpl surveySubscriber = it2.next().getValue();
surveySubscriber.readAndDispatch();
}
}
......
......@@ -138,7 +138,7 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
public HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
public TreeMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
return ServantManagerAccessor.getInstance(serverId).getPropertiesForGeneric();
}
......
......@@ -87,7 +87,7 @@ public class ResourceManager {
public void setFileContent(String controllerType, String fileName, String content) {
System.out.println("H.ORTIZ: call to writeResourceFile commented .................................................." + fileName);
//System.out.println("H.ORTIZ: call to writeResourceFile commented .................................................." + fileName);
//ServantManagerAccessor.getInstance(serverId).writeResourceFile(controllerType, fileName, content);
......
......@@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import fr.ill.ics.bridge.listeners.ServerSurveyXMLListener;
import fr.ill.ics.nscclient.survey.SurveySubcriberImpl;
import fr.ill.ics.nscclient.survey.SurveySubscriberImpl;
public class SurveyEventSender {
......@@ -47,11 +47,11 @@ public class SurveyEventSender {
* @param listener
*/
public void addSurveyXMLListener(ServerSurveyXMLListener listener) {
SurveySubcriberImpl.getInstance(serverId).addSurveyXMLListener(listener);
SurveySubscriberImpl.getInstance(serverId).addSurveyXMLListener(listener);
}
public void removeSurveyXMLListener(ServerSurveyXMLListener listener) {
SurveySubcriberImpl.getInstance(serverId).removeSurveyXMLListener(listener);
SurveySubscriberImpl.getInstance(serverId).removeSurveyXMLListener(listener);
}
}
\ No newline at end of file
......@@ -31,9 +31,9 @@ public class Float64Property extends FloatProperty {
public String getServerValue() {
try {
if (isCommandBox) {
return this.propertyFormat.formatForDisplay(new Double(CommandZoneAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(Double.valueOf(CommandZoneAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
} else {
return this.propertyFormat.formatForDisplay(new Double(DataAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(Double.valueOf(DataAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
}
} catch (Exception e) {
System.err.println("Exception while getting value for property " + getName());
......@@ -48,9 +48,9 @@ public class Float64Property extends FloatProperty {
boolean ok = isOk(serverValue);
if (ok) {
if (isCommandBox) {
ok = CommandZoneAccessor.getInstance(serverId).setFloat64Value(containerId, id, new Double(serverValue).doubleValue());
ok = CommandZoneAccessor.getInstance(serverId).setFloat64Value(containerId, id, Double.valueOf(serverValue));
} else {
ok = DataAccessor.getInstance(serverId).setFloat64Value(containerId, id, new Double(serverValue).doubleValue());
ok = DataAccessor.getInstance(serverId).setFloat64Value(containerId, id, Double.valueOf(serverValue));
if (!ok) {
sendPropertyChangedEvent();
}
......
......@@ -30,9 +30,9 @@ public class Int32Property extends IntegerProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.formatForDisplay(new Integer(CommandZoneAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(Integer.valueOf(CommandZoneAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
} else {
return this.propertyFormat.formatForDisplay(new Integer(DataAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(Integer.valueOf(DataAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
}
}
......@@ -43,9 +43,9 @@ public class Int32Property extends IntegerProperty {
boolean ok = isOk(serverValue);
if (ok) {
if (isCommandBox) {
ok = CommandZoneAccessor.getInstance(serverId).setInt32Value(containerId, id, new Integer(serverValue).intValue());
ok = CommandZoneAccessor.getInstance(serverId).setInt32Value(containerId, id, Integer.valueOf(serverValue));
} else {
ok = DataAccessor.getInstance(serverId).setInt32Value(containerId, id, new Integer(serverValue).intValue());
ok = DataAccessor.getInstance(serverId).setInt32Value(containerId, id, Integer.valueOf(serverValue));
if (!ok) {
sendPropertyChangedEvent();
}
......
......@@ -64,7 +64,7 @@ public abstract class IntegerProperty extends Property {
// String serverValue = this.propertyFormat.unformat(value);
// if (isOk(serverValue)) {
// try {
// abstractController.setValueByLong(name, new Integer(serverValue).intValue());
// abstractController.setValueByLong(name, Integer.valueOf(serverValue));
// showSettingPropertyMessage(value);
// } catch (CannotSetValueException e) {
// // if the value is refused then update all widgets with the true value.
......
......@@ -443,7 +443,7 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
synchronized (lockListeners) {
Iterator<ILockChangedListener> listenerIterator = lockListeners.iterator();
while (listenerIterator.hasNext()) {
((ILockChangedListener) (listenerIterator.next())).lockChanged(new LockEvent(this, isLocked));
listenerIterator.next().lockChanged(new LockEvent(this, isLocked));
}
}
}
......@@ -720,6 +720,12 @@ public abstract class Property implements ServerPropertyChangeListener, ICommand
}
public UndoState getUndoState() {
return undoState;
}
public abstract String getType();
/**
......
......@@ -284,12 +284,8 @@ public class PropertyManager {
}
/**
*
* @param controller
*/
public void deleteDynamicPropertyFromController(Servant servant, String propertyName) {
HashMap<String, DynamicProperty> dynamicProperties = dynamicPropertyMap.get(servant.getId());
public void deleteDynamicPropertyFromController(Controller controller, String propertyName) {
HashMap<String, DynamicProperty> dynamicProperties = dynamicPropertyMap.get(controller.getDatabaseId());
if (dynamicProperties != null) {
dynamicProperties.remove(propertyName);
}
......
......@@ -31,7 +31,7 @@ public class GreaterThanPropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() >= value);
boolean isOk = (Double.valueOf(valueToBeTested) >= value);
return isOk;
} catch (NumberFormatException e) {
return false;
......
......@@ -31,7 +31,7 @@ public class LowerThanPropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() <= this.value);
boolean isOk = (Double.valueOf(valueToBeTested) <= this.value);
return isOk;
} catch (NumberFormatException e) {
return false;
......
......@@ -25,7 +25,7 @@ public class PositivePropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() >= 0);
boolean isOk = (Double.valueOf(valueToBeTested) >= 0);
return isOk;
} catch (NumberFormatException e) {
return false;
......
......@@ -33,7 +33,7 @@ public class RangePropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
double valueToTest = new Double(valueToBeTested).doubleValue();
double valueToTest = Double.valueOf(valueToBeTested);
return (valueToTest >= minIncluded && valueToTest <= maxIncluded);
} catch (NumberFormatException e) {
return false;
......
......@@ -110,9 +110,9 @@ public class RangePropertyDependentCondition implements IPropertyCondition {
}
if (minProperty != null && maxProperty != null) {
double minValue = new Double(minProperty.getValue()).doubleValue();
double maxValue = new Double(maxProperty.getValue()).doubleValue();
double valueToTest = new Double(valueToBeTested).doubleValue();
double minValue = Double.valueOf(minProperty.getValue());
double maxValue = Double.valueOf(maxProperty.getValue());
double valueToTest = Double.valueOf(valueToBeTested);
if (minPropertyExcluded && maxPropertyExcluded) {
return (valueToTest > minValue && valueToTest < maxValue);
......
......@@ -25,7 +25,7 @@ public class StrictlyPositivePropertyCondition implements IPropertyCondition {
public boolean isOk(String valueToBeTested) {
try {
boolean isOk = (new Double(valueToBeTested).doubleValue() > 0);
boolean isOk = (Double.valueOf(valueToBeTested) > 0);
return isOk;
} catch (NumberFormatException e) {
return false;
......
......@@ -103,7 +103,7 @@ public class DecimalFormat extends PropertyFormat {
nbOfDecimalPlaces = numberOfDecimalPlaces;
}
if (value.equals((new Double(Double.NaN)).toString()) ) {
if (value.equals((Double.valueOf(Double.NaN)).toString()) ) {
return value;
}
if (value.equals("")) {
......@@ -112,9 +112,9 @@ public class DecimalFormat extends PropertyFormat {
double valueAsDouble;
try {
valueAsDouble = new Double(Double.parseDouble(value)).doubleValue();
valueAsDouble = Double.valueOf(Double.parseDouble(value));
} catch (NumberFormatException nfe) {
LOGGER.logp(Level.SEVERE, this.getClass().getName(), "format", "Trying to format: " + value + " as an double");
LOGGER.logp(Level.SEVERE, this.getClass().getName(), "format", "Trying to format: " + value + " as a double");
return value;
}
......
......@@ -23,12 +23,12 @@ import java.math.BigInteger;
public class HexadecimalFormat extends PropertyFormat {
public String formatForDisplay(String value) {
return Integer.toHexString(new Integer(value).intValue()).toUpperCase();
return Integer.toHexString(Integer.valueOf(value)).toUpperCase();
}
public String unformat(String value) {
int valueInDecimal = new BigInteger(value, 16).intValue();
return new Integer(valueInDecimal).toString();
return Integer.valueOf(valueInDecimal).toString();
}
// ????? ROBIN
......
......@@ -2031,7 +2031,7 @@ public class CommandZoneAccessor {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetCurrentValue)
.setType(CommandZoneRequests.Message.Type.GetType)
.build();
// Create the request.
......
......@@ -63,15 +63,15 @@ public class PortableByteArray {
int result;
if (endianness == Endianess.BIG) {
result = (int)(encodedData[pos+3] & 0xff) << 0 |
(int)(encodedData[pos+2] & 0xff) << 8 |
(int)(encodedData[pos+1] & 0xff) << 16 |
(int)(encodedData[pos+0] & 0xff) << 24;
result = (encodedData[pos+3] & 0xff) << 0 |
(encodedData[pos+2] & 0xff) << 8 |
(encodedData[pos+1] & 0xff) << 16 |
(encodedData[pos+0] & 0xff) << 24;
} else {
result = (int)(encodedData[pos+0] & 0xff) << 0 |
(int)(encodedData[pos+1] & 0xff) << 8 |
(int)(encodedData[pos+2] & 0xff) << 16 |
(int)(encodedData[pos+3] & 0xff) << 24;
result = (encodedData[pos+0] & 0xff) << 0 |
(encodedData[pos+1] & 0xff) << 8 |
(encodedData[pos+2] & 0xff) << 16 |
(encodedData[pos+3] & 0xff) << 24;
}
pos = pos + 4;
......
......@@ -25,6 +25,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -717,8 +718,8 @@ public class ServantManagerAccessor {
}
}
public HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
HashMap<String, LinkedHashMap<String, String>> list = new HashMap<String, LinkedHashMap<String, String>>();
public TreeMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
TreeMap<String, LinkedHashMap<String, String>> list = new TreeMap<String, LinkedHashMap<String, String>>();
String buf = getPropertiesForGenericRequest();
StringTokenizer tokgen = new StringTokenizer(buf,"\n");
while(tokgen.hasMoreTokens()) {
......@@ -1001,6 +1002,29 @@ public class ServantManagerAccessor {
return null;
}
public void logUserMessage(String userName, String message) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.UserLog)
.build();
// Create the request.
ServantManagerRequest.UserLogRequest request = ServantManagerRequest.UserLogRequest.newBuilder()
.setUserName(userName)
.setMessage(message)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(servantManagerRequester.receive());
// Nothing to return as the log should always succeed.
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "logUserMessage", "error in parsing response");
}
}
}
\ No newline at end of file
......@@ -51,7 +51,7 @@ public class CommandZoneEventClient {
}
public int hashCode() {
return (new Integer(databaseId)).hashCode() + (new Integer(commandBoxId)).hashCode();
return (Integer.valueOf(databaseId)).hashCode() + (Integer.valueOf(commandBoxId)).hashCode();
}
public boolean equals(Object key) {
......@@ -250,13 +250,12 @@ public class CommandZoneEventClient {
}
private void notifyCommandBoxPropertyChanged(CommandBoxPropertyEvent event) {
CommandZoneBoxKey key = new CommandZoneBoxKey(event.getDatabaseId(), event.getCommandBoxId());
synchronized (propertyListeners) {
if (propertyListeners.containsKey(key)) {
HashSet<ICommandBoxPropertyEventListener> listeners = propertyListeners.get(key);
HashSet<ICommandBoxPropertyEventListener> listenersorg = propertyListeners.get(key);
HashSet<ICommandBoxPropertyEventListener> listeners = new HashSet<ICommandBoxPropertyEventListener>(listenersorg);
Iterator<ICommandBoxPropertyEventListener> it = listeners.iterator();
while (it.hasNext()) {
it.next().commandBoxPropertyChanged(event.getCommandBoxId(), event.getPropertyId());
......
......@@ -36,7 +36,7 @@ import fr.ill.ics.nscclient.notification.commandzone.ServerCommandZoneEventManag
import fr.ill.ics.nscclient.servant.ConfigurationManager;
import fr.ill.ics.nscclient.servant.ConfigurationManager.LoadFailure;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager.ClientAlreadyLaunchedException;
import fr.ill.ics.nscclient.survey.SurveySubcriberImpl;
import fr.ill.ics.nscclient.survey.SurveySubscriberImpl;
public class ServerSessionManager {
......@@ -88,7 +88,7 @@ public class ServerSessionManager {
SessionManager.getInstance(serverId).login(standAlone);
}
catch (ClientAlreadyLaunchedException e) {
logoutAll(false);
// Only rethrow the exception. The call to logoutAll is made in the main application.
throw e;
}
......@@ -145,7 +145,7 @@ public class ServerSessionManager {
ServerCommandZoneEventManager.getInstance(serverId).reset();
LogSubscriber.getInstance(serverId).unsubscribe();
SurveySubcriberImpl.getInstance(serverId).unsubscribe();
SurveySubscriberImpl.getInstance(serverId).unsubscribe();
DataChangeSubscriber.getInstance(serverId).unsubscribe();
DataAccessor.getInstance(serverId).reset();
......@@ -169,7 +169,7 @@ public class ServerSessionManager {
}
try {
SurveySubcriberImpl.getInstance(serverId).unsubscribe();
SurveySubscriberImpl.getInstance(serverId).unsubscribe();
} catch (Exception e) {
System.out.println("Cannot unsubscribe survey");
}
......
......@@ -35,7 +35,7 @@ import fr.ill.ics.nscclient.serverconnection.ServerInstance;
public class SurveySubcriberImpl {
public class SurveySubscriberImpl {
private Set<ServerSurveyXMLListener> surveyXMLListeners = new LinkedHashSet<ServerSurveyXMLListener>();
private List<String> pendingXMLMessages = new ArrayList<String>();
......@@ -43,24 +43,24 @@ public class SurveySubcriberImpl {
private Application.Subscriber subscriber;
private Thread subscriberThread;
private static Map<String, SurveySubcriberImpl> instances = new HashMap<String, SurveySubcriberImpl>();
private static Map<String, SurveySubscriberImpl> instances = new HashMap<String, SurveySubscriberImpl>();
private String serverId;
private SurveySubcriberImpl(String serverId) {
private SurveySubscriberImpl(String serverId) {
this.serverId = serverId;
}
public static SurveySubcriberImpl getInstance(String serverId) {
public static SurveySubscriberImpl getInstance(String serverId) {
if (!instances.containsKey(serverId)) {
SurveySubcriberImpl instance = new SurveySubcriberImpl(serverId);
SurveySubscriberImpl instance = new SurveySubscriberImpl(serverId);
instances.put(serverId, instance);
}
return instances.get(serverId);
}
public static Map<String, SurveySubcriberImpl> getInstances() {
public static Map<String, SurveySubscriberImpl> getInstances() {
return instances;
}
......@@ -149,21 +149,40 @@ public class SurveySubcriberImpl {
public void unsubscribe() {
System.out.println("Unsubscribing survey...");
// The subscriber can be null in case the window was not open.
if (subscriber == null) {
System.out.println("The survey subscriber is null");
return;
}
// Stop the subscriber.
subscriber.cancel();
System.out.println("Unsubscribing survey with catch of the exceptions...");
// Join the thread.
// Cancel can throw a zeromq exception.
try {
// Stop the subscriber.
subscriber.cancel();
// Join the thread.
subscriberThread.join();
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
// Added the try catch if the exception in cancel leads to another exception in terminate.
try {
// Terminate the subscriber.
subscriber.terminate();
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate the subscriber.
subscriber.terminate();
// Reset the subscriber.
subscriber = null;
System.out.println("Unsubscribed from the survey");
}
......
......@@ -81,6 +81,7 @@ 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 USE_NOMADLOGS = "USE_NOMADLOGS";
public final static String X_CONDITIONS_SPY = "X_CONDITIONS_SPY";
public final static String Y_CONDITIONS_SPY = "Y_CONDITIONS_SPY";
......@@ -331,7 +332,7 @@ public class ConfigManager {
* @return the integer value that match with the propertyName in the config file
*/
public synchronized int getInt(String propertyName) {
return new Integer(properties.getProperty(propertyName)).intValue();
return Integer.valueOf(properties.getProperty(propertyName));
}
......@@ -497,7 +498,7 @@ public class ConfigManager {
if (configurationException instanceof PropertyNotFoundException) {
PropertyNotFoundException pnfe = (PropertyNotFoundException)configurationException;
if (pnfe.getControllerName().equals(controllerName)) {