Commit 2dd58ec1 authored by ics's avatar ics

Synchronise delete scan for multi clients

parent 57b661fc
......@@ -3252,6 +3252,7 @@ public class CommandZoneAccessor {
.build();
// Create the request.
CommandZoneRequests.DeleteFileRequest request = CommandZoneRequests.DeleteFileRequest.newBuilder()
.setClientID(getClientID())
.setFileName(fileName)
.build();
......
......@@ -31,6 +31,7 @@ public class CommandZoneFileSync {
private static CommandZoneFileSync instance;
private List<INewScanListener> newScanListeners;
private List<IDeleteScanListener> deleteScanListeners;
private List<INewSettingsFileListener> newSettingsFileListeners;
private List<INewXBUListener> newXBUListeners;
private List<INewPALListener> newPALListeners;
......@@ -92,6 +93,59 @@ public class CommandZoneFileSync {
}
/**
* <p>Adds a new IDeleteScanListener to the list of listeners.
* If the listener already exists then ignor.
* @param IDeleteScanListener a delete listener
*/
public void addDeleteScanListener(IDeleteScanListener deleteScanFileListener) {
if (deleteScanListeners == null) {
this.deleteScanListeners = new ArrayList<IDeleteScanListener>(2);
}
synchronized (deleteScanListeners) {
if (!deleteScanListeners.contains(deleteScanFileListener)) {
deleteScanListeners.add(deleteScanFileListener);
}
}
}
/**
* <p>Removes a IDeleteScanListener.
* <br>If the listener does not exist in the list of listeners then ignor it.
*/
public void removeDeleteScanListener(IDeleteScanListener deleteScanFileListener) {
if (deleteScanListeners != null) {
synchronized (deleteScanListeners) {
if (deleteScanListeners.contains(deleteScanFileListener)) {
deleteScanListeners.remove(deleteScanFileListener);
}
if (deleteScanListeners.isEmpty()) {
deleteScanListeners = null;
}
}
}
}
/**
* Notifies listeners that a scan has been deleted.
*/
public void notifyDeleteScanListeners(String scanName) {
if (deleteScanListeners != null) {
synchronized (deleteScanListeners) {
Iterator<IDeleteScanListener> listenerIterator = deleteScanListeners.iterator();
// Extract short scan name
String[] tokens = scanName.split("[\\\\|/]");
String shortScanName = tokens[tokens.length - 1].replace(".xml", "");
while (listenerIterator.hasNext()) {
listenerIterator.next().scanDeleted(shortScanName);
}
}
}
}
/**
* <p>Adds a new INewSettingsFileListener to the list of listeners to this particular plugin.
* If the listener already exists then ignor.
......
......@@ -560,6 +560,9 @@ public class CommandZoneSyncEventClient {
break;
}
}
else if (event instanceof DeleteFile) {
CommandZoneFileSync.getInstance().notifyDeleteScanListeners(((DeleteFile)event).getFileName());
}
}
}
......
......@@ -370,6 +370,14 @@ public class CommandZoneSyncEventNotifier {
return new NewFile(request.getFileName(), request.getFileType());
}
}
else if (type == CommandZoneRequests.Message.Type.DeleteFile) {
CommandZoneRequests.DeleteFileRequest request = CommandZoneRequests.DeleteFileRequest.parseFrom(message.getSerializedContent());
// Notify only if it is the same client that was the originator of the request.
if (request.getClientID() != getClientID()) {
return new DeleteFile(request.getFileName());
}
}
else {
System.out.println("Unable to process command zone sync message of type " + type);
}
......
/*
* 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;
/**
*
*
* @author ortizh
*/
public class DeleteFile implements ICommandZoneSyncEvent {
private String fileName;
public DeleteFile(String fileName) {
super();
this.fileName = fileName;
}
public String getFileName() {
return fileName;
}
}
\ 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 interface IDeleteScanListener {
public void scanDeleted(String scanName);
}
\ No newline at end of file
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