Commit 82636cda authored by legoc's avatar legoc
Browse files

Erased command line sync classes

parent 54eba31a
/*
* 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.bridge.command;
public interface ICommandLineSyncEventListener {
public void onStateChange();
}
\ No newline at end of file
......@@ -255,7 +255,6 @@ public class CommandLineAccessor {
// Create the request.
CommandLineRequest.CommandLineStateRequest request = CommandLineRequest.CommandLineStateRequest.newBuilder()
.setClientID(getClientID())
.setState(state)
.build();
......
/*
* 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.commandline;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.nomadserver.notification.NotificationMessage;
import fr.ill.ics.nscclient.notification.commandline.sync.CommandLineSyncEventClient;
import fr.ill.ics.nscclient.notification.commandline.sync.CommandLineSyncEventNotifier;
import fr.ill.ics.nscclient.notification.commandline.sync.ICommandLineSyncEvent;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
public class ServerCommandLineEventManager {
private Application.Subscriber subscriber;
private Thread subscriberThread;
private String serverId;
private static Map<String, ServerCommandLineEventManager> instances = new HashMap<String, ServerCommandLineEventManager>();
private CommandLineSyncEventNotifier syncEventNotifier;
private ServerCommandLineEventManager(String serverId) {
this.serverId = serverId;
syncEventNotifier = new CommandLineSyncEventNotifier(serverId);
}
public static ServerCommandLineEventManager getInstance(String serverId) {
if (!instances.containsKey(serverId)) {
ServerCommandLineEventManager instance = new ServerCommandLineEventManager(serverId);
instances.put(serverId, instance);
}
return instances.get(serverId);
}
public void init() {
// Connect nomad server.
Application.Instance nomad = ServerInstance.getInstance().getApplicationInstance(serverId);
if (nomad == null) {
System.err.println("Problem to connect to the nomad server " + serverId);
return;
}
// Define the command line publisher.
String commandLinePublisherName = "command_line_publisher";
System.out.println("Trying to connect command line subscriber to " + commandLinePublisherName);
// Create the subscriber.
subscriber = Application.Subscriber.create(nomad, commandLinePublisherName);
System.out.println("Connected command line subscriber " + subscriber);
// Start the thread.
subscriberThread = new Thread(new Runnable() {
@Override
public void run() {
// Receive data
while (true) {
// Blocking call.
byte[][] data = subscriber.receiveTwoParts();
if (data != null) {
try {
if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandLineSync) {
notifyCommandLineSync(syncEventNotifier.processMessage(NotificationMessage.CommandLineSync.parseFrom(new ByteArrayInputStream(data[1]))));
}
else {
System.out.println("Unable to process " + NotificationMessage.Message.parseFrom(data[0]).getType());
}
}
catch (IOException e) {
System.err.println("Cannot parse notification server command zone message");
}
}
else {
break;
}
}
}
});
subscriberThread.start();
}
public void reset() {
if (subscriber != null) {
System.out.println("Unsubscribing command line...");
// Stop the subscriber.
subscriber.cancel();
// Join the thread.
try {
subscriberThread.join();
}
catch (InterruptedException e) {
e.printStackTrace();
}
// Terminate the subscriber.
subscriber.terminate();
System.out.println("Unsubscribed from the command line");
}
}
private void notifyCommandLineSync(ICommandLineSyncEvent event) {
// The event can be null if the incoming message if from client itself.
if (event != null) {
CommandLineSyncEventClient.getInstance().eventOccurred(event);
}
}
}
\ 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.commandline.sync;
public class CommandLineSyncEvent implements ICommandLineSyncEvent {
}
/*
* 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.commandline.sync;
import java.util.HashSet;
import fr.ill.ics.bridge.command.ICommandLineSyncEventListener;
/**
* Class dispatching the command line sync events to the registered listeners.
*/
public class CommandLineSyncEventClient {
private static CommandLineSyncEventClient instance = null;
private HashSet<ICommandLineSyncEventListener> commandLineListeners = new HashSet<ICommandLineSyncEventListener>();
private CommandLineSyncEventClient() {
}
public static CommandLineSyncEventClient getInstance() {
if (instance == null) {
instance = new CommandLineSyncEventClient();
}
return instance;
}
public void addCommandLineListener(ICommandLineSyncEventListener listener) {
if (commandLineListeners == null) {
commandLineListeners = new HashSet<ICommandLineSyncEventListener>();
}
commandLineListeners.add(listener);
}
public void removeCommandLineListener(ICommandLineSyncEventListener listener) {
commandLineListeners.remove(listener);
}
public void notifyCommandLineListeners(ICommandLineSyncEvent event) {
if (commandLineListeners != null) {
synchronized (commandLineListeners) {
for (ICommandLineSyncEventListener listener : commandLineListeners) {
listener.onStateChange();
}
}
}
}
public void eventOccurred(ICommandLineSyncEvent event) {
//notifyCommandLineListeners(event);
}
}
\ 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.commandline.sync;
import java.io.IOException;
import fr.ill.ics.nomadserver.commandline.CommandLineRequest;
import fr.ill.ics.nomadserver.notification.NotificationMessage;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
public class CommandLineSyncEventNotifier {
private String serverId;
private Integer clientId;
public CommandLineSyncEventNotifier(String serverId) {
this.serverId = serverId;
}
private int getClientID() {
if (clientId == null) {
// Get the client id from the session manager.
clientId = SessionManager.getInstance(serverId).getClientId();
}
return clientId;
}
public ICommandLineSyncEvent processMessage(NotificationMessage.CommandLineSync message) {
try {
CommandLineRequest.Message.Type type = CommandLineRequest.Message.parseFrom(message.getSerializedType()).getType();
if (type == CommandLineRequest.Message.Type.SetCommandLineState) {
CommandLineRequest.CommandLineStateRequest request = CommandLineRequest.CommandLineStateRequest.parseFrom(message.getSerializedContent());
// Notify if it is not the same client that sent the request.
if (request.getClientID() != getClientID()) {
System.out.println("Process command line sync message of type " + type);
return new CommandLineSyncEvent();
}
}
else {
System.out.println("Unable to process command line sync message of type " + type);
}
}
catch (IOException e) {
System.err.println("Cannot parse notification server command line sync message");
}
return null;
}
}
/*
* 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.commandline.sync;
public interface ICommandLineSyncEvent {
}
\ No newline at end of file
......@@ -32,7 +32,6 @@ import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.log.LogSubscriber;
import fr.ill.ics.nscclient.notification.DataChangeSubscriber;
import fr.ill.ics.nscclient.notification.commandline.ServerCommandLineEventManager;
import fr.ill.ics.nscclient.notification.commandzone.ServerCommandZoneEventManager;
import fr.ill.ics.nscclient.ploty.PlotyInstance;
import fr.ill.ics.nscclient.servant.ConfigurationManager;
......@@ -70,7 +69,6 @@ public class ServerSessionManager {
CommandZoneAccessor.getInstance(serverId).init();
ServerCommandZoneEventManager.getInstance(serverId).init();
ServerCommandLineEventManager.getInstance(serverId).init();
VariableManagerAccessor.getInstance(serverId).init();
ConditionManagerAccessor.getInstance(serverId).init();
......@@ -149,7 +147,6 @@ public class ServerSessionManager {
public void logout() {
ServerCommandZoneEventManager.getInstance(serverId).reset();
ServerCommandLineEventManager.getInstance(serverId).reset();
LogSubscriber.getInstance(serverId).unsubscribe();
SurveySubscriberImpl.getInstance(serverId).unsubscribe();
......@@ -174,7 +171,6 @@ public class ServerSessionManager {
public void logoutAll(boolean stop) {
ServerCommandZoneEventManager.getInstance(serverId).reset();
ServerCommandLineEventManager.getInstance(serverId).reset();
try {
LogSubscriber.getInstance(serverId).unsubscribe();
......
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