Commit 33c6ebcf authored by yannick legoc's avatar yannick legoc
Browse files

Replaced Corba command zone notification.

parent 4c9a41cf
......@@ -233,16 +233,6 @@
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandBoxDescriptor.idl" />
</exec>
<echo message="Generating CommandZoneEventPublisher.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandZoneEventPublisher.idl" />
</exec>
<echo message="Generating CommandZoneEventSubscriber.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandZoneEventSubscriber.idl" />
</exec>
<!-- common -->
<echo message="Generating ListIterator.java" />
<exec executable="idl">
......
/*
* 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;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneEventSubscriberPOA;
public class CommandZoneEventSubscriberImpl extends CommandZoneEventSubscriberPOA {
private int ID;
private byte[] corbaID;
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public void setByteID(byte[] corbaID) {
this.corbaID = corbaID;
}
public byte[] getCorbaID() {
return corbaID;
}
public void commandBoxStarted(int databaseID, int commandBoxID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExecutionEvent(databaseID, commandBoxID, CommandBoxExecutionEvent.ExecutionState.STARTED));
}
public void commandBoxPaused(int databaseID, int commandBoxID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExecutionEvent(databaseID, commandBoxID, CommandBoxExecutionEvent.ExecutionState.PAUSED));
}
public void commandBoxTerminated(int databaseID, int commandBoxID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExecutionEvent(databaseID, commandBoxID, CommandBoxExecutionEvent.ExecutionState.FINISHED));
}
public void commandBoxProgressionChanged(int databaseID, int commandBoxID, double progression) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxProgressionEvent(databaseID, commandBoxID, progression));
}
public void commandBoxReset(int databaseID, int commandBoxID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxResetEvent(databaseID, commandBoxID));
}
public void commandBoxPropertyChanged(int databaseID, int commandBoxID, int propertyID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxPropertyEvent(databaseID, commandBoxID, propertyID));
}
public void commandZoneStarted(int commandZoneID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneExecutionEvent(commandZoneID, CommandZoneExecutionEvent.ExecutionState.STARTED));
}
public void commandZonePaused(int commandZoneID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneExecutionEvent(commandZoneID, CommandZoneExecutionEvent.ExecutionState.PAUSED));
}
public void commandZoneTerminated(int commandZoneID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneExecutionEvent(commandZoneID, CommandZoneExecutionEvent.ExecutionState.FINISHED));
}
public void commandZoneProgressionChanged(int commandZoneID, double progression) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneProgressionEvent(commandZoneID, progression));
}
public void commandZoneReset(int commandZoneID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneResetEvent(commandZoneID));
}
public void forLoopCurrentValueChanged(int databaseID, int forLoopCommandBoxID, int lineIndex, double currentValue) {
CommandZoneEventClient.getInstance().eventOccurred(new ForLoopCurrentValueChangeEvent(databaseID, forLoopCommandBoxID, lineIndex, currentValue));
}
public void commandZoneErrorOccurred(int commandZoneID, String message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneErrorEvent(commandZoneID, message));
}
public void commandBoxExpressionChanged(int databaseID, int commandBoxID) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExpressionChangedEvent(databaseID, commandBoxID));
}
public void commandBoxExpressionValueChanged(int databaseID, int commandBoxID, boolean currentValue) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExpressionValueChangedEvent(databaseID, commandBoxID, currentValue));
}
}
\ No newline at end of file
......@@ -18,33 +18,33 @@
package fr.ill.ics.nscclient.notification.commandzone;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.omg.PortableServer.POAPackage.ObjectNotActive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongAdapter;
import org.omg.PortableServer.POAPackage.WrongPolicy;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneEventPublisher;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneEventPublisherHelper;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneEventSubscriber;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneEventSubscriberHelper;
import fr.ill.ics.nscclient.corbabase.CorbaNamingService;
import fr.ill.ics.nscclient.corbabase.CorbaNamingService.CORBAResolveFailureException;
import fr.ill.ics.nscclient.corbabase.CorbaORB;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.nomadserver.notification.NotificationMessage;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandBoxChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandBoxExpressionValueChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandBoxProgressionChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandBoxPropertyChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandZoneChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandZoneErrorOccurred;
import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandZoneProgressionChanged;
import fr.ill.ics.nomadserver.notification.NotificationMessage.ForLoopCurrentValueChanged;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
public class ServerCommandZoneEventManager {
private static final Logger LOGGER = Logger.getLogger(ServerCommandZoneEventManager.class.getName());
private Application.Subscriber subscriber;
private Thread subscriberThread;
private String serverId;
private static Map<String, ServerCommandZoneEventManager> instances = new HashMap<String, ServerCommandZoneEventManager>();
private CommandZoneEventPublisher commandZoneEventPublisher;
private CommandZoneEventSubscriberImpl commandZoneEventSubscriberImpl;
private ServerCommandZoneEventManager(String serverId) {
this.serverId = serverId;
......@@ -59,64 +59,178 @@ public class ServerCommandZoneEventManager {
}
public void init() {
try {
// get data change publisher
String contextName = "NomadServer";
if (!serverId.equals("real")) {
contextName += serverId;
}
org.omg.CORBA.Object commandZoneEventPublisherObject = CorbaNamingService.getInstance().resolveObject(contextName, "Core", "commandZoneEventPublisher");
commandZoneEventPublisher = CommandZoneEventPublisherHelper.narrow(commandZoneEventPublisherObject);
// subscribe to state change publisher
commandZoneEventSubscriberImpl = new CommandZoneEventSubscriberImpl();
org.omg.CORBA.Object o = CorbaORB.getInstance().getPOA().servant_to_reference(commandZoneEventSubscriberImpl);
CommandZoneEventSubscriber commandZoneEventSubscriber = CommandZoneEventSubscriberHelper.narrow(o);
int ID = commandZoneEventPublisher.subscribe(commandZoneEventSubscriber);
commandZoneEventSubscriberImpl.setID(ID);
commandZoneEventSubscriberImpl.setByteID(CorbaORB.getInstance().getPOA().reference_to_id(o));
} catch (CORBAResolveFailureException e) {
LOGGER.log(Level.SEVERE, "Unable to obtain commandZoneEventPublisher corba object");
} catch (WrongPolicy e) {
System.err.println("Unable to create CORBA object in connection with server (WrongPolicy)");
} catch (WrongAdapter e) {
System.err.println("Unable to create CORBA object in connection with server (WrongAdapter)");
} catch (ServantNotActive e) {
System.err.println("Unable to create CORBA object in connection with server (ServantNotActive)");
// 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 zone publisher.
String commandZonePublisherName = "command_zone_publisher";
System.out.println("Trying to connect command zone subscriber to " + commandZonePublisherName);
// Create the subscriber.
subscriber = Application.Subscriber.create(nomad, commandZonePublisherName);
System.out.println("Connected command zone 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.CommandZoneStarted) {
notifyCommandZoneStarted(NotificationMessage.CommandZoneChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandZonePaused) {
notifyCommandZonePaused(NotificationMessage.CommandZoneChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandZoneTerminated) {
notifyCommandZoneTerminated(NotificationMessage.CommandZoneChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandZoneReset) {
notifyCommandZoneReset(NotificationMessage.CommandZoneChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxStarted) {
notifyCommandBoxStarted(NotificationMessage.CommandBoxChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxPaused) {
notifyCommandBoxPaused(NotificationMessage.CommandBoxChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxTerminated) {
notifyCommandBoxTerminated(NotificationMessage.CommandBoxChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxReset) {
notifyCommandBoxReset(NotificationMessage.CommandBoxChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxExpressionChanged) {
notifyCommandBoxExpressionChanged(NotificationMessage.CommandBoxChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxProgressionChanged) {
notifyCommandBoxProgressionChanged(NotificationMessage.CommandBoxProgressionChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxPropertyChanged) {
notifyCommandBoxPropertyChanged(NotificationMessage.CommandBoxPropertyChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandZoneProgressionChanged) {
notifyCommandZoneProgressionChanged(NotificationMessage.CommandZoneProgressionChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandZoneErrorOccurred) {
notifyCommandZoneErrorOccurred(NotificationMessage.CommandZoneErrorOccurred.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandBoxExpressionValueChanged) {
notifyCommandBoxExpressionValueChanged(NotificationMessage.CommandBoxExpressionValueChanged.parseFrom(new ByteArrayInputStream(data[1])));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.ForLoopCurrentValueChanged) {
notifyForLoopCurrentValueChanged(NotificationMessage.ForLoopCurrentValueChanged.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 data change message");
}
}
else {
break;
}
}
}
});
subscriberThread.start();
}
public void reset() {
if (commandZoneEventPublisher != null) {
try {
commandZoneEventPublisher.unsubscribe(commandZoneEventSubscriberImpl.getID());
} catch (Exception e) {
System.err.println("unable to unsubscribe");
}
}
System.out.println("Unsubscribing command zone...");
// Stop the subscriber.
subscriber.cancel();
// Join the thread.
try {
if (commandZoneEventSubscriberImpl != null) {
CorbaORB.getInstance().getPOA().deactivate_object(commandZoneEventSubscriberImpl.getCorbaID());
commandZoneEventSubscriberImpl = null;
}
} catch (WrongPolicy e) {
e.printStackTrace();
} catch (ObjectNotActive e) {
subscriberThread.join();
}
catch (InterruptedException e) {
e.printStackTrace();
}
// Terminate the subscriber.
subscriber.terminate();
System.out.println("Unsubscribed from the command zone");
}
private void notifyCommandZoneStarted(CommandZoneChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneExecutionEvent(message.getCommandZoneID(), CommandZoneExecutionEvent.ExecutionState.STARTED));
}
private void notifyCommandZonePaused(CommandZoneChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneExecutionEvent(message.getCommandZoneID(), CommandZoneExecutionEvent.ExecutionState.PAUSED));
}
private void notifyCommandZoneTerminated(CommandZoneChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneExecutionEvent(message.getCommandZoneID(), CommandZoneExecutionEvent.ExecutionState.FINISHED));
}
private void notifyCommandZoneReset(CommandZoneChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneResetEvent(message.getCommandZoneID()));
}
private void notifyCommandBoxStarted(CommandBoxChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExecutionEvent(message.getDatabaseID(), message.getCommandBoxID(), CommandBoxExecutionEvent.ExecutionState.STARTED));
}
private void notifyCommandBoxPaused(CommandBoxChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExecutionEvent(message.getDatabaseID(), message.getCommandBoxID(), CommandBoxExecutionEvent.ExecutionState.PAUSED));
}
private void notifyCommandBoxTerminated(CommandBoxChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExecutionEvent(message.getDatabaseID(), message.getCommandBoxID(), CommandBoxExecutionEvent.ExecutionState.FINISHED));
}
private void notifyCommandBoxReset(CommandBoxChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxResetEvent(message.getDatabaseID(), message.getCommandBoxID()));
}
private void notifyCommandBoxExpressionChanged(CommandBoxChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExpressionChangedEvent(message.getDatabaseID(), message.getCommandBoxID()));
}
private void notifyCommandBoxProgressionChanged(CommandBoxProgressionChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxProgressionEvent(message.getDatabaseID(), message.getCommandBoxID(), message.getProgression()));
}
private void notifyCommandBoxPropertyChanged(CommandBoxPropertyChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxPropertyEvent(message.getDatabaseID(), message.getCommandBoxID(), message.getPropertyID()));
}
private void notifyCommandZoneProgressionChanged(CommandZoneProgressionChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneProgressionEvent(message.getCommandZoneID(), message.getProgression()));
}
private void notifyCommandZoneErrorOccurred(CommandZoneErrorOccurred message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandZoneErrorEvent(message.getCommandZoneID(), message.getMessage()));
}
private void notifyCommandBoxExpressionValueChanged(CommandBoxExpressionValueChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxExpressionValueChangedEvent(message.getDatabaseID(), message.getCommandBoxID(), message.getCurrentValue()));
}
private void notifyForLoopCurrentValueChanged(ForLoopCurrentValueChanged message) {
CommandZoneEventClient.getInstance().eventOccurred(new ForLoopCurrentValueChangeEvent(message.getDatabaseID(), message.getCommandBoxID(), message.getIndex(), message.getCurrentValue()));
}
}
\ 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