From aee0810dddae833ab69c9426a6b6999c7c022ab3 Mon Sep 17 00:00:00 2001 From: ics Date: Fri, 15 Mar 2019 11:28:51 +0100 Subject: [PATCH] ForLoop synchronisation --- .../ics/bridge/command/CommandWrapper.java | 7 +++ .../bridge/command/ForLoopCommandWrapper.java | 2 +- .../command/ICommandBoxSyncEventListener.java | 2 + .../ServerCommandBoxSyncListener.java | 2 + .../sync/CommandZoneSyncEventClient.java | 21 +++++++-- .../sync/CommandZoneSyncEventNotifier.java | 10 +++++ .../commandzone/sync/SetForLoopStepType.java | 43 +++++++++++++++++++ 7 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/SetForLoopStepType.java diff --git a/src/main/java/fr/ill/ics/bridge/command/CommandWrapper.java b/src/main/java/fr/ill/ics/bridge/command/CommandWrapper.java index 7dd0efb..ccd3046 100644 --- a/src/main/java/fr/ill/ics/bridge/command/CommandWrapper.java +++ b/src/main/java/fr/ill/ics/bridge/command/CommandWrapper.java @@ -27,6 +27,7 @@ import fr.ill.ics.bridge.listeners.ServerExpressionChangeListener; import fr.ill.ics.bridge.listeners.ServerProgressChangeListener; import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener; import fr.ill.ics.bridge.listeners.ServerResetCommandListener; +import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType; import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType; import fr.ill.ics.nscclient.command.ServerCommandBox; import fr.ill.ics.nscclient.notification.commandzone.CommandZoneEventClient; @@ -84,6 +85,7 @@ public abstract class CommandWrapper implements IServerCommand, ICommandBoxEvent public void removeServerCommandBoxSyncListener(ServerCommandBoxSyncListener listener) { this.commandBoxSyncListener = null; + CommandZoneEventClient.getInstance().removeCommandBoxListener(this); } public void addServerExpressionChangeListener(ServerExpressionChangeListener listener) { @@ -239,6 +241,11 @@ public abstract class CommandWrapper implements IServerCommand, ICommandBoxEvent commandBoxSyncListener.onSetForLoopType(type, lineIndex); } + @Override + public void onSetForLoopStepType(ForLoopStepType type, int lineIndex) { + commandBoxSyncListener.onSetForLoopStepType(type, lineIndex); + } + @Override public void onSetForLoopValues(int lineIndex, String value) { commandBoxSyncListener.onSetForLoopValues(lineIndex, value); diff --git a/src/main/java/fr/ill/ics/bridge/command/ForLoopCommandWrapper.java b/src/main/java/fr/ill/ics/bridge/command/ForLoopCommandWrapper.java index 038490e..b03e75f 100644 --- a/src/main/java/fr/ill/ics/bridge/command/ForLoopCommandWrapper.java +++ b/src/main/java/fr/ill/ics/bridge/command/ForLoopCommandWrapper.java @@ -123,7 +123,7 @@ public class ForLoopCommandWrapper extends CommandWrapper implements IForLoopEve return StepType.NBPOINTS; } - public boolean addForLoopLine(int index) { + public final boolean addForLoopLine(int index) { return serverForLoopCommandBox.addForLoopLine(index); } diff --git a/src/main/java/fr/ill/ics/bridge/command/ICommandBoxSyncEventListener.java b/src/main/java/fr/ill/ics/bridge/command/ICommandBoxSyncEventListener.java index 4ffc643..c169cc8 100644 --- a/src/main/java/fr/ill/ics/bridge/command/ICommandBoxSyncEventListener.java +++ b/src/main/java/fr/ill/ics/bridge/command/ICommandBoxSyncEventListener.java @@ -18,6 +18,7 @@ package fr.ill.ics.bridge.command; +import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType; import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType; public interface ICommandBoxSyncEventListener { @@ -42,4 +43,5 @@ public interface ICommandBoxSyncEventListener { void onAddForLoopLine(int lineIndex); void onRemoveForLoopLine(int lineIndex); + void onSetForLoopStepType(ForLoopStepType forLoopStepType, int lineIndex); } \ No newline at end of file diff --git a/src/main/java/fr/ill/ics/bridge/listeners/ServerCommandBoxSyncListener.java b/src/main/java/fr/ill/ics/bridge/listeners/ServerCommandBoxSyncListener.java index e557148..a86ad4f 100644 --- a/src/main/java/fr/ill/ics/bridge/listeners/ServerCommandBoxSyncListener.java +++ b/src/main/java/fr/ill/ics/bridge/listeners/ServerCommandBoxSyncListener.java @@ -18,6 +18,7 @@ package fr.ill.ics.bridge.listeners; +import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType; import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType; public interface ServerCommandBoxSyncListener { @@ -37,4 +38,5 @@ public interface ServerCommandBoxSyncListener { void onSetForLoopStepSize(int lineIndex, double value); void onAddForLoopLine(int lineIndex); void onRemoveForLoopLine(int lineIndex); + void onSetForLoopStepType(ForLoopStepType type, int lineIndex); } \ No newline at end of file diff --git a/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventClient.java b/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventClient.java index 3b560f2..5038108 100644 --- a/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventClient.java +++ b/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventClient.java @@ -61,7 +61,7 @@ public class CommandZoneSyncEventClient { } } - public void removeCommandZoneListener(ICommandBoxSyncEventListener listener) { + public void removeCommandBoxListener(ICommandBoxSyncEventListener listener) { synchronized (commandBoxListeners) { if (commandBoxListeners.containsKey(listener.getCommandBoxID())) { HashSet listeners = commandBoxListeners.get(listener.getCommandBoxID()); @@ -157,6 +157,20 @@ public class CommandZoneSyncEventClient { } } + private void notifySetForLoopStepType(SetForLoopStepType event) { + + synchronized (commandBoxListeners) { + if (commandBoxListeners.containsKey(event.getCommandBoxId())) { + HashSet listeners = commandBoxListeners.get(event.getCommandBoxId()); + + Iterator it = listeners.iterator(); + while (it.hasNext()) { + it.next().onSetForLoopStepType(event.getForLoopStepType(), event.getLineIndex()); + } + } + } + } + private void notifySetForLoopValues(SetForLoopValues event) { synchronized (commandBoxListeners) { @@ -338,7 +352,6 @@ public class CommandZoneSyncEventClient { } private void notifyAddNewForLoopCommandBox(AddNewForLoopCommandBox event) { - synchronized (commandZoneListeners) { Iterator it = commandZoneListeners.iterator(); while (it.hasNext()) { @@ -348,7 +361,6 @@ public class CommandZoneSyncEventClient { } private void notifyAddNewForLoopCommandBoxAtEnd(AddNewForLoopCommandBoxAtEnd event) { - synchronized (commandZoneListeners) { Iterator it = commandZoneListeners.iterator(); while (it.hasNext()) { @@ -457,6 +469,9 @@ public class CommandZoneSyncEventClient { else if (event instanceof SetForLoopType) { notifySetForLoopType((SetForLoopType)event); } + else if (event instanceof SetForLoopStepType) { + notifySetForLoopStepType((SetForLoopStepType)event); + } else if (event instanceof SetForLoopValues) { notifySetForLoopValues((SetForLoopValues)event); } diff --git a/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventNotifier.java b/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventNotifier.java index fe989cf..66baaf8 100644 --- a/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventNotifier.java +++ b/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventNotifier.java @@ -6,6 +6,7 @@ import fr.ill.ics.nomadserver.commandzone.CommandZoneRequests; import fr.ill.ics.nomadserver.common.Common; import fr.ill.ics.nomadserver.notification.NotificationMessage; import fr.ill.ics.nscclient.command.CommandZoneAccessor.ContainerType; +import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType; import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType; import fr.ill.ics.nscclient.sessionmanagement.SessionManager; @@ -296,6 +297,15 @@ public class CommandZoneSyncEventNotifier { return new SetForLoopType(request.getCommandBoxID(), request.getLineIndex(), (forLoopType == CommandZoneRequests.ForLoopType.Type.VALUES ? ForLoopType.VALUES : ForLoopType.RANGE)); } } + else if (type == CommandZoneRequests.Message.Type.SetStepType) { + CommandZoneRequests.SetForLoopStepTypeRequest request = CommandZoneRequests.SetForLoopStepTypeRequest.parseFrom(message.getSerializedContent()); + + // Notify only if it is the same client that was the originator of the request. + if (request.getClientID() != getClientID()) { + CommandZoneRequests.ForLoopStepType.Type forLoopStepType = request.getType(); + return new SetForLoopStepType(request.getCommandBoxID(), request.getLineIndex(), (forLoopStepType == CommandZoneRequests.ForLoopStepType.Type.DELTA ? ForLoopStepType.DELTA : ForLoopStepType.NBPOINTS)); + } + } else if (type == CommandZoneRequests.Message.Type.SetVariableName) { CommandZoneRequests.SetForLoopStringValueRequest request = CommandZoneRequests.SetForLoopStringValueRequest.parseFrom(message.getSerializedContent()); diff --git a/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/SetForLoopStepType.java b/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/SetForLoopStepType.java new file mode 100644 index 0000000..2cce1bd --- /dev/null +++ b/src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/SetForLoopStepType.java @@ -0,0 +1,43 @@ +/* + * Nomad Instrument Control Software + * + * Copyright 2011 Institut Laue-Langevin + * + * Licensed under the EUPL, Version 1.1 only (the "License"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ + +package fr.ill.ics.nscclient.notification.commandzone.sync; + +import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType; + +public class SetForLoopStepType extends CommandBoxSyncEvent { + + private ForLoopStepType forLoopStepType; + private int lineIndex; + + public SetForLoopStepType(int commandBoxId, int lineIndex, ForLoopStepType forLoopStepType) { + super(commandBoxId); + + this.forLoopStepType = forLoopStepType; + this.lineIndex = lineIndex; + } + + public ForLoopStepType getForLoopStepType() { + return forLoopStepType; + } + + public int getLineIndex() { + return lineIndex; + } + +} \ No newline at end of file -- GitLab