Commit 01941acf authored by yannick legoc's avatar yannick legoc
Browse files

Reimplemented CommandLineProxy Corba classes with Cameo.

parent 58124022
......@@ -325,12 +325,6 @@
<arg line="${idlFlags} ${idlDataProviderDir}/SurveyPublisher.idl" />
</exec>
<!-- command line -->
<echo message="Generating CommandLineProxy.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandline/CommandLineProxy.idl" />
</exec>
<!-- proto files -->
<echo message="Generating ServantConfiguration.java" />
<exec executable="protoc">
......@@ -356,6 +350,11 @@
<exec executable="protoc">
<arg line="${protoFlags} ${protoDir}/ServantManagerRequests.proto" />
</exec>
<echo message="Generating CommandLineRequests.java" />
<exec executable="protoc">
<arg line="${protoFlags} ${protoDir}/CommandLineRequests.proto" />
</exec>
</target>
</configuration>
......
......@@ -21,7 +21,7 @@ package fr.ill.ics.bridge.commandline;
import java.util.HashMap;
import java.util.Map;
import fr.ill.ics.nscclient.commandline.CommandLineProxyImpl;
import fr.ill.ics.nscclient.commandline.CommandLineAccessor;
public class CommandLineProxyWrapper {
......@@ -43,35 +43,35 @@ public class CommandLineProxyWrapper {
}
public void executeCommand(String text) {
CommandLineProxyImpl.getInstance(serverId).executeCommand(text);
CommandLineAccessor.getInstance(serverId).executeCommand(text);
}
public void pauseCommands() {
CommandLineProxyImpl.getInstance(serverId).pauseCommands();
CommandLineAccessor.getInstance(serverId).pauseCommands();
}
public void restartCommands() {
CommandLineProxyImpl.getInstance(serverId).restartCommands();
CommandLineAccessor.getInstance(serverId).restartCommands();
}
public void stopCommands() {
CommandLineProxyImpl.getInstance(serverId).stopCommands();
CommandLineAccessor.getInstance(serverId).stopCommands();
}
public void stopAtEndCommands() {
CommandLineProxyImpl.getInstance(serverId).stopAtEndCommands();
CommandLineAccessor.getInstance(serverId).stopAtEndCommands();
}
public boolean isStarted() {
return CommandLineProxyImpl.getInstance(serverId).isStarted();
return CommandLineAccessor.getInstance(serverId).isStarted();
}
public boolean isPaused() {
return CommandLineProxyImpl.getInstance(serverId).isPaused();
return CommandLineAccessor.getInstance(serverId).isPaused();
}
public void setCommandLineState(boolean state) {
CommandLineProxyImpl.getInstance(serverId).setCommandLineState(state);
CommandLineAccessor.getInstance(serverId).setCommandLineState(state);
}
}
\ 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.commandline;
import java.util.HashMap;
import java.util.Map;
import com.google.protobuf.InvalidProtocolBufferException;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.RequesterCreationException;
import fr.ill.ics.nomadserver.commandline.CommandLineRequest;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
public class CommandLineAccessor {
private static Map<String, CommandLineAccessor> instances = new HashMap<String, CommandLineAccessor>();
private String serverId;
private Application.Requester commandLineRequester;
private CommandLineAccessor(String serverId) {
this.serverId = serverId;
}
public static CommandLineAccessor getInstance(String serverId) {
if (!instances.containsKey(serverId)) {
CommandLineAccessor instance = new CommandLineAccessor(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;
}
System.out.println("Trying to create command line requester");
// Create the requester.
try {
commandLineRequester = Application.Requester.create(nomad, "command_line");
} catch (RequesterCreationException e) {
System.err.println("Problem to connect to the command line responder");
return;
}
System.out.println("Created requester " + commandLineRequester);
}
public void reset() {
// Terminate the requester.
commandLineRequester.terminate();
}
public void executeCommand(String text) {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.ExecuteCommand)
.build();
// Create the request.
CommandLineRequest.CommandRequest request = CommandLineRequest.CommandRequest.newBuilder()
.setText(text)
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of executeCommand");
}
}
public void pauseCommands() {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.PauseCommands)
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of pauseCommands");
}
}
public void restartCommands() {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.RestartCommands)
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of restartCommands");
}
}
public void stopCommands() {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.StopCommands)
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of stopCommands");
}
}
public void stopAtEndCommands() {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.StopAtEndCommands)
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of stopAtEndCommands");
}
}
public boolean isStarted() {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.IsStarted)
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of isStarted");
}
return false;
}
public boolean isPaused() {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.IsPaused)
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of isPaused");
}
return false;
}
public void setCommandLineState(boolean state) {
// Create the message type.
CommandLineRequest.Message type = CommandLineRequest.Message.newBuilder()
.setType(CommandLineRequest.Message.Type.SetCommandLineState)
.build();
// Create the request.
CommandLineRequest.CommandLineStateRequest request = CommandLineRequest.CommandLineStateRequest.newBuilder()
.setState(state)
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of setCommandLineState");
}
}
}
\ 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.commandline;
import java.util.HashMap;
import java.util.Map;
import fr.ill.ics.bridge.command.CommandZoneWrapper;
import fr.ill.ics.nomadserver.core.commandline.CommandLineProxy;
import fr.ill.ics.nomadserver.core.commandline.CommandLineProxyHelper;
import fr.ill.ics.nscclient.corbabase.CorbaNamingService;
public class CommandLineProxyImpl {
private CommandLineProxy commandLine;
private static Map<String, CommandLineProxyImpl> instances = new HashMap<String, CommandLineProxyImpl>();
private String serverId;
private CommandLineProxyImpl(String serverId) {
this.serverId = serverId;
}
public static CommandLineProxyImpl getInstance(String serverId) {
if (!instances.containsKey(serverId)) {
CommandLineProxyImpl instance = new CommandLineProxyImpl(serverId);
instances.put(serverId, instance);
}
return instances.get(serverId);
}
public void init() {
try {
String contextName = "NomadServer";
if (!serverId.equals(CommandZoneWrapper.SERVER_ID)) {
contextName += serverId;
}
org.omg.CORBA.Object corbaObj = CorbaNamingService.getInstance().resolveObject(contextName, "Core", "commandLineProxy");
commandLine = CommandLineProxyHelper.narrow(corbaObj);
} catch (CorbaNamingService.CORBAResolveFailureException rfe) {
System.err.println("Unable to obtain CommandLineProxy from Naming Service");
} catch (org.omg.CORBA.SystemException e) {
System.err.println("Unable to obtain CommandLineProxy from Naming Service");
}
}
public void executeCommand(String text) {
commandLine.executeCommand(text);
}
public void pauseCommands() {
commandLine.pauseCommands();
}
public void restartCommands() {
commandLine.restartCommands();
}
public void stopCommands() {
commandLine.stopCommands();
}
public void stopAtEndCommands() {
commandLine.stopAtEndCommands();
}
public boolean isStarted() {
return commandLine.isStarted();
}
public boolean isPaused() {
return commandLine.isPaused();
}
public void setCommandLineState(boolean state) {
commandLine.setCommandLineState(state);
}
}
\ No newline at end of file
......@@ -28,18 +28,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import fr.ill.ics.bridge.command.CommandZoneWrapper;
import fr.ill.ics.bridge.events.ServerLogEvent;
import fr.ill.ics.bridge.events.ServerLogEvent.LogLevel;
import fr.ill.ics.bridge.listeners.ServerLogEventListener;
import fr.ill.ics.bridge.listeners.ServerLogImageDataReadyListener;
import fr.ill.ics.bridge.listeners.ServerLogXMLListener;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.ConnectionTimeout;
import fr.ill.ics.cameo.Server;
import fr.ill.ics.nomadserver.notification.NotificationMessage;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.util.ConfigManager;
public class LogSubscriber {
......
......@@ -35,7 +35,6 @@ import fr.ill.ics.bridge.listeners.ServerConfigurationChangeListener;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor.LoadConfigurationFailure;
import fr.ill.ics.nscclient.sessionmanagement.ServerSessionManager;
import fr.ill.ics.util.exception.ControllerNotFoundException;
public class CorbaControllerManager extends ControllerManager implements ServerConfigurationChangeListener {
......
......@@ -30,7 +30,6 @@ import java.util.TreeMap;
import fr.ill.ics.bridge.DriverManager;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.sessionmanagement.ServerSessionManager;
public class CorbaDriverManager extends DriverManager {
......
......@@ -32,7 +32,7 @@ import fr.ill.ics.nscclient.command.ControlCommandBoxAccessorProxy;
import fr.ill.ics.nscclient.command.ForLoopCommandBoxAccessorProxy;
import fr.ill.ics.nscclient.command.GenericCommandBoxAccessorProxy;
import fr.ill.ics.nscclient.command.ScanCommandBoxAccessorProxy;
import fr.ill.ics.nscclient.commandline.CommandLineProxyImpl;
import fr.ill.ics.nscclient.commandline.CommandLineAccessor;
import fr.ill.ics.nscclient.condition.ConditionManagerProxy;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
......@@ -81,7 +81,7 @@ public class ServerSessionManager {
ServerCommandZoneEventManager.getInstance(serverId).init();
ConditionManagerProxy.getInstance(serverId).init();
CommandLineProxyImpl.getInstance(serverId).init();
CommandLineAccessor.getInstance(serverId).init();
LogSubscriber.getInstance(serverId).init();
SurveySubcriberImpl.getInstance(serverId).init();
}
......@@ -156,6 +156,7 @@ public class ServerSessionManager {
DataAccessor.getInstance(serverId).reset();
ServantManagerAccessor.getInstance(serverId).reset();
CommandLineAccessor.getInstance(serverId).reset();
currentSession.logout();
currentSession = null;
......
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