Commit 78acbdb7 authored by legoc's avatar legoc

Added toggle background sync message

parent e54c731e
......@@ -201,6 +201,11 @@ public abstract class CommandWrapper implements IServerCommand, ICommandBoxEvent
@Override
public void onToggleParallel() {
commandBoxSyncListener.onToggleParallel();
}
}
@Override
public void onToggleBackground() {
commandBoxSyncListener.onToggleBackground();
}
}
\ No newline at end of file
......@@ -22,5 +22,6 @@ public interface ICommandBoxSyncEventListener {
int getCommandBoxID();
void onToggleParallel();
void onToggleBackground();
}
\ No newline at end of file
......@@ -21,4 +21,5 @@ package fr.ill.ics.bridge.listeners;
public interface ServerCommandBoxSyncListener {
void onToggleParallel();
void onToggleBackground();
}
\ No newline at end of file
/*
* 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;
public class CommandBoxToggleBackground extends CommandBoxSyncEvent {
public CommandBoxToggleBackground(int commandBoxId) {
super(commandBoxId);
}
}
\ No newline at end of file
......@@ -86,6 +86,20 @@ public class CommandZoneSyncEventClient {
}
}
private void notifyCommandBoxToggleBackground(CommandBoxToggleBackground event) {
synchronized (commandBoxListeners) {
if (commandBoxListeners.containsKey(event.getCommandBoxId())) {
HashSet<ICommandBoxSyncEventListener> listeners = commandBoxListeners.get(event.getCommandBoxId());
Iterator<ICommandBoxSyncEventListener> it = listeners.iterator();
while (it.hasNext()) {
it.next().onToggleBackground();
}
}
}
}
public void readAndDispatch() {
// copy pending property changes to unblock any server calls
......@@ -101,7 +115,10 @@ public class CommandZoneSyncEventClient {
ICommandZoneSyncEvent event = c.next();
if (event instanceof CommandBoxToggleParallel) {
notifyCommandBoxToggleParallel((CommandBoxToggleParallel)event);
}
}
else if (event instanceof CommandBoxToggleBackground) {
notifyCommandBoxToggleBackground((CommandBoxToggleBackground)event);
}
}
}
......
......@@ -19,7 +19,7 @@ public class CommandZoneSyncEventNotifier {
if (clientId == null) {
// Get the client id from the session manager.
clientId = SessionManager.getInstance(serverId).getClientId();
clientId = SessionManager.getInstance(serverId).getClientId();
}
return clientId;
......@@ -30,7 +30,15 @@ public class CommandZoneSyncEventNotifier {
try {
CommandZoneRequests.Message.Type type = CommandZoneRequests.Message.parseFrom(message.getSerializedType()).getType();
if (type == CommandZoneRequests.Message.Type.ToggleParallel) {
if (type == CommandZoneRequests.Message.Type.ToggleBackground) {
CommandZoneRequests.CommandBoxRequest request = CommandZoneRequests.CommandBoxRequest.parseFrom(message.getSerializedContent());
// Notify only if it is the same client that was the originator of the request.
if (request.getClientID() != getClientID()) {
return new CommandBoxToggleBackground(request.getCommandBoxID());
}
}
else if (type == CommandZoneRequests.Message.Type.ToggleParallel) {
CommandZoneRequests.CommandBoxRequest request = CommandZoneRequests.CommandBoxRequest.parseFrom(message.getSerializedContent());
System.out.println("Received a toggle parallel event with client id " + request.getClientID() + ", command box id " + request.getCommandBoxID());
......@@ -40,6 +48,7 @@ public class CommandZoneSyncEventNotifier {
return new CommandBoxToggleParallel(request.getCommandBoxID());
}
}
else {
System.out.println("Unable to process command zone sync message of type " + type);
}
......
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