Commit d51c4b75 authored by yannick legoc's avatar yannick legoc
Browse files

Reimplemented corba command zone accessor.

parent 2bbdfa5b
......@@ -193,16 +193,6 @@
<arg line="${idlFlags} ${idlCoreDir}/SessionGateway.idl" />
</exec>
<echo message="Generating CommandZoneAccessor.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandZoneAccessor.idl" />
</exec>
<echo message="Generating CommandBoxDescriptor.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandBoxDescriptor.idl" />
</exec>
<!-- common -->
<echo message="Generating ListIterator.java" />
<exec executable="idl">
......
......@@ -28,7 +28,7 @@ import fr.ill.ics.bridge.listeners.ServerCommandStateChangeListener;
import fr.ill.ics.bridge.listeners.ServerCommandZoneErrorListener;
import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerResetCommandListener;
import fr.ill.ics.nscclient.command.CommandZoneAccessorProxy;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.command.ServerCommandZone;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
......@@ -276,7 +276,7 @@ public class CommandZoneWrapper implements ICommandZoneEventListener {
}
public int create() {
return CommandZoneAccessorProxy.getInstance(serverId).create();
return CommandZoneAccessor.getInstance(serverId).create();
}
public boolean isPaused() {
......
......@@ -42,6 +42,7 @@ public class CommandZoneAccessor {
private String serverId;
private Application.Requester commandBoxRequester;
private Map<Integer, Boolean> commandConflicts = new HashMap<Integer, Boolean>();
public enum ExecutionPhaseState {CONSTRUCTION, RUNNING, FINISHED, PAUSED};
public enum ContainerType {COMMANDZONE, IFTHEN, IFELSE, FORLOOP, SCAN};
......@@ -101,37 +102,41 @@ public class CommandZoneAccessor {
commandBoxRequester.terminate();
}
private void processError(Type type, int commandBoxID) {
public boolean commandConflicts(int commandZoneId) {
return commandConflicts.get(commandZoneId);
}
private void processError(Type type, int containerID) {
if (type == Common.Error.Type.COMMAND_LIST_CREATION_ERROR) {
LOGGER.log(Level.SEVERE, "CommandListCreationException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "CommandListCreationException occured for command box " + containerID);
}
else if (type == Common.Error.Type.COMMAND_ZONE_NOT_FOUND) {
LOGGER.log(Level.SEVERE, "CommandZoneNotFoundException occured");
}
else if (type == Common.Error.Type.COMMAND_BOX_NOT_FOUND) {
LOGGER.log(Level.SEVERE, "CommandBoxNotFoundException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "CommandBoxNotFoundException occured for command box " + containerID);
}
else if (type == Common.Error.Type.COMMAND_CONFLICTS) {
LOGGER.log(Level.SEVERE, "CommandConflicts occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "CommandConflicts occured for command box " + containerID);
}
else if (type == Common.Error.Type.COMMAND_BOX_FORBIDDEN) {
LOGGER.log(Level.SEVERE, "CommandBoxForbiddenException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "CommandBoxForbiddenException occured for command box " + containerID);
}
else if (type == Common.Error.Type.BAD_COMMAND_BOX_TYPE) {
LOGGER.log(Level.SEVERE, "BadCommandBoxTypeException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "BadCommandBoxTypeException occured for command box " + containerID);
}
else if (type == Common.Error.Type.PROPERTY_EXPRESSION_SYNTAX_ERROR) {
LOGGER.log(Level.SEVERE, "PropertyExpressionSyntaxErrorException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "PropertyExpressionSyntaxErrorException occured for command box " + containerID);
}
else if (type == Common.Error.Type.VALUES_SYNTAX_ERROR) {
LOGGER.log(Level.SEVERE, "ValuesSyntaxErrorException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "ValuesSyntaxErrorException occured for command box " + containerID);
}
else if (type == Common.Error.Type.BAD_PROPERTY_TYPE) {
LOGGER.log(Level.SEVERE, "BadPropertyTypeException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "BadPropertyTypeException occured for command box " + containerID);
}
else if (type == Common.Error.Type.NO_SUCH_PROPERTY) {
LOGGER.log(Level.SEVERE, "NoSuchPropertyException occured for command box " + commandBoxID);
LOGGER.log(Level.SEVERE, "NoSuchPropertyException occured for command box " + containerID);
}
}
......@@ -358,11 +363,11 @@ public class CommandZoneAccessor {
return false;
}
public void stop(int commandBoxID) {
public void stopCommandBox(int commandBoxID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Stop)
.setType(CommandZoneRequests.Message.Type.StopCommandBox)
.build();
// Create the request.
......@@ -385,11 +390,11 @@ public class CommandZoneAccessor {
}
}
public int getProgression(int commandBoxID) {
public int getCommandBoxProgression(int commandBoxID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetProgression)
.setType(CommandZoneRequests.Message.Type.GetCommandBoxProgression)
.build();
// Create the request.
......@@ -2240,4 +2245,423 @@ public class CommandZoneAccessor {
return 1;
}
public int create() {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Create)
.build();
// Create the request.
CommandZoneRequests.EmptyRequest request = CommandZoneRequests.EmptyRequest.newBuilder()
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Int32Response response = Common.Int32Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
return -1;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "create", "error in parsing response");
}
return -1;
}
public boolean reset(int commandZoneID, int databaseID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Reset)
.build();
// Create the request.
CommandZoneRequests.DatabaseCommandZoneRequest request = CommandZoneRequests.DatabaseCommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.setDatabaseID(databaseID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "reset", "error in parsing response");
}
return false;
}
public boolean execute(int commandZoneID, int databaseID) {
commandConflicts.put(commandZoneID, false);
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Execute)
.build();
// Create the request.
CommandZoneRequests.DatabaseCommandZoneRequest request = CommandZoneRequests.DatabaseCommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.setDatabaseID(databaseID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
if (response.getError() == Common.Error.Type.COMMAND_CONFLICTS) {
commandConflicts.put(commandZoneID, true);
}
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "execute", "error in parsing response");
}
return false;
}
public boolean stop(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Stop)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "stop", "error in parsing response");
}
return false;
}
public boolean stopAtEnd(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.StopAtEnd)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "stopAtEnd", "error in parsing response");
}
return false;
}
public boolean pause(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Pause)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "pause", "error in parsing response");
}
return false;
}
public boolean restart(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Restart)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "restart", "error in parsing response");
}
return false;
}
public boolean isRunning(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.IsRunning)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return false;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "isRunning", "error in parsing response");
}
return false;
}
public boolean isPaused(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.IsPaused)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return false;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "isPaused", "error in parsing response");
}
return false;
}
public double getProgression(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetProgression)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Float64Response response = Common.Float64Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return 0;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getProgression", "error in parsing response");
}
return 0;
}
public String getConflictingCommands(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetConflictingCommands)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return "";
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getConflictingCommands", "error in parsing response");
}
return "";
}
public double getEstimatedTime(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetEstimatedTime)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Float64Response response = Common.Float64Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return 0;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getEstimatedTime", "error in parsing response");
}
return 0;
}
public String print(int commandZoneID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.Print)
.build();
// Create the request.
CommandZoneRequests.CommandZoneRequest request = CommandZoneRequests.CommandZoneRequest.newBuilder()
.setCommandZoneID(commandZoneID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandZoneID);
return "";
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "print", "error in parsing response");
}
return "";
}
}
\ 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.command;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.ill.ics.nomadserver.common.ListItem;
import fr.ill.ics.nomadserver.common.ListIterator;
import fr.ill.ics.nomadserver.core.commandzone.CommandBoxDescriptor;
import fr.ill.ics.nomadserver.core.commandzone.CommandBoxDescriptorHelper;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneAccessor;
import fr.ill.ics.nomadserver.core.commandzone.CommandZoneAccessorHelper;
import fr.ill.ics.nomadserver.core.commandzone.CommandBoxDescriptorPackage.CommandBoxType;