Commit 6ac75586 authored by Locatelli's avatar Locatelli
Browse files

Commit changes:

- cameo v2
- Re-structure configuration
- compute remaining estimated time
parent da38d162
......@@ -28,6 +28,7 @@ import fr.ill.ics.bridge.events.ServerResetCommandEvent;
import fr.ill.ics.bridge.listeners.ServerCommandBoxDeletedListener;
import fr.ill.ics.bridge.listeners.ServerCommandStateChangeListener;
import fr.ill.ics.bridge.listeners.ServerCommandZoneErrorListener;
import fr.ill.ics.bridge.listeners.ServerCommandZoneEstimatedTime;
import fr.ill.ics.bridge.listeners.ServerCommandZoneSyncListener;
import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerResetCommandListener;
......@@ -56,7 +57,8 @@ public class CommandZoneWrapper implements ICommandZoneEventListener, ICommandZo
private ServerCommandZoneErrorListener commandZoneErrorListener;
private ServerCommandZoneSyncListener commandZoneSyncListener;
private ServerCommandBoxDeletedListener commandBoxDeletedListener;
private ServerCommandZoneEstimatedTime commandZoneEstimatedTime;
public CommandZoneWrapper(String serverId) {
this.serverId = serverId;
serverCommandZone = new ServerCommandZone(serverId, 0);
......@@ -108,6 +110,10 @@ public class CommandZoneWrapper implements ICommandZoneEventListener, ICommandZo
this.commandBoxDeletedListener = listener;
}
public void addServerCommandZoneEstimatedTimeListener(ServerCommandZoneEstimatedTime listener) {
this.commandZoneEstimatedTime = listener;
}
public void removeServerProgressChangeListener(ServerProgressChangeListener listener) {
this.commandProgressListener = null;
CommandZoneEventClient.getInstance().removeCommandZoneListener(this);
......@@ -134,6 +140,10 @@ public class CommandZoneWrapper implements ICommandZoneEventListener, ICommandZo
this.commandBoxDeletedListener = null;
}
public void removeaddServerCommandZoneEstimatedTimeListener(ServerCommandZoneEstimatedTime listener) {
this.commandZoneEstimatedTime = null;
}
public void commandZoneStarted() {
if (commandStateListener != null) {
ServerCommandStateChangeEvent event = new ServerCommandStateChangeEvent(null, null);
......@@ -176,6 +186,12 @@ public class CommandZoneWrapper implements ICommandZoneEventListener, ICommandZo
System.out.println(" command box " + id);
}*/
}
public void estimatedTimeChanged(double value) {
if (commandZoneEstimatedTime != null) {
commandZoneEstimatedTime.estimatedTimeChanged(value);
}
}
public void errorOccurred(String message) {
commandZoneErrorListener.errorOccurred(message);
......@@ -270,6 +286,9 @@ public class CommandZoneWrapper implements ICommandZoneEventListener, ICommandZo
return serverCommandZone.reset(DATABASE_ID);
}
public void setComputeEstimatedTimeState(boolean state) {
serverCommandZone.setComputeEstimatedTimeState( state);
}
public boolean accessDenied() {
// do nothing for new server
......@@ -302,10 +321,6 @@ public class CommandZoneWrapper implements ICommandZoneEventListener, ICommandZo
return serverCommandZone.isPaused();
}
public double getEstimatedTime() {
return serverCommandZone.getEstimatedTime();
}
public void removeServerId() {
}
......
......@@ -31,5 +31,6 @@ public interface ICommandZoneEventListener {
int getCommandZoneID();
void onReset();
void onCommandBoxesDeleted(List<Integer> commandBoxIds);
void estimatedTimeChanged(double value);
}
\ 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.bridge.listeners;
public interface ServerCommandZoneEstimatedTime {
void estimatedTimeChanged(double remainingtime);
}
\ No newline at end of file
......@@ -3133,39 +3133,6 @@ public class CommandZoneAccessor {
return "";
}
public synchronized 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()
.setClientID(getClientID())
.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, "getEstimatedTime");
return 0;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getEstimatedTime", "error in parsing response");
}
return 0;
}
public synchronized String print(int commandZoneID) {
// Create the message type.
......@@ -3436,4 +3403,27 @@ public class CommandZoneAccessor {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "appendToFile", "error in parsing response");
}
}
public synchronized void setComputeEstimatedTimeState(boolean state) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.ComputeEstimatedTimeState)
.build();
// Create the request.
CommandZoneRequests.ComputeEstimatedTimeStateRequest request = CommandZoneRequests.ComputeEstimatedTimeStateRequest.newBuilder()
.setState(state).build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Int32Response response = Common.Int32Response.parseFrom(commandBoxRequester.receive());
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "addNewAtomicCommandBoxAtEnd", "error in parsing response");
}
}
}
......@@ -25,10 +25,11 @@ public class ServerCommandZone {
private String serverId;
private int commandZoneId;
private int computeEstimatedTimeCounterState;
public ServerCommandZone(String serverId, int commandZoneId) {
this.serverId = serverId;
computeEstimatedTimeCounterState = 0;
if (commandZoneId != 0) {
System.out.println("Command zone created with non-zero ID not implemented");
}
......@@ -146,11 +147,17 @@ public class ServerCommandZone {
return CommandZoneAccessor.getInstance(serverId).getConflictingCommands(commandZoneId);
}
public double getEstimatedTime() {
return CommandZoneAccessor.getInstance(serverId).getEstimatedTime(commandZoneId);
}
public String print() {
return CommandZoneAccessor.getInstance(serverId).print(commandZoneId);
}
public void setComputeEstimatedTimeState(boolean state) {
if (state == false) {
++computeEstimatedTimeCounterState;
}
else {
--computeEstimatedTimeCounterState;
}
CommandZoneAccessor.getInstance(serverId).setComputeEstimatedTimeState(computeEstimatedTimeCounterState == 0);
}
}
\ No newline at end of file
......@@ -538,9 +538,11 @@ public class ServantManagerAccessor {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getServantDescriptorWithId(pbServant.getID());
descriptor.setFamily(pbServant.getFamily());
descriptor.setVisible(pbServant.getVisible());
descriptor.setEnabled(pbServant.getEnabled());
if (descriptor != null) {
descriptor.setFamily(pbServant.getFamily());
descriptor.setVisible(pbServant.getVisible());
descriptor.setEnabled(pbServant.getEnabled());
}
}
}
......
......@@ -383,6 +383,19 @@ public class CommandZoneEventClient {
}
}
private void notifyNewEstimatedTime(NewEstimatedTimeEvent event) {
synchronized (commandZoneListeners) {
if (commandZoneListeners.containsKey(event.getCommandZoneId())) {
HashSet<ICommandZoneEventListener> listeners = commandZoneListeners.get(event.getCommandZoneId());
Iterator<ICommandZoneEventListener> it = listeners.iterator();
while (it.hasNext()) {
it.next().estimatedTimeChanged(event.getValue());
}
}
}
}
public void readAndDispatch() {
......@@ -432,6 +445,10 @@ public class CommandZoneEventClient {
} else if (event instanceof CommandBoxesDeletedEvent) {
notifyCommandBoxesDeleted((CommandBoxesDeletedEvent)event);
} else if (event instanceof NewEstimatedTimeEvent) {
notifyNewEstimatedTime((NewEstimatedTimeEvent)event);
}
}
......
/*
* 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;
public class NewEstimatedTimeEvent implements ICommandZoneEvent {
private int commandZoneId;
private double value;
public NewEstimatedTimeEvent(int commandZoneId, double value) {
this.commandZoneId = commandZoneId;
this.value = value;
}
public int getCommandZoneId() {
return commandZoneId;
}
public double getValue() {
return value;
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@ import fr.ill.ics.nomadserver.notification.NotificationMessage.CommandZoneChange
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.nomadserver.notification.NotificationMessage.EstimatedTimeMessage;
import fr.ill.ics.nscclient.notification.commandzone.sync.CommandZoneSyncEventClient;
import fr.ill.ics.nscclient.notification.commandzone.sync.CommandZoneSyncEventNotifier;
import fr.ill.ics.nscclient.notification.commandzone.sync.ICommandZoneSyncEvent;
......@@ -150,6 +151,9 @@ public class ServerCommandZoneEventManager {
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.CommandZoneSync) {
notifyCommandZoneSync(syncEventNotifier.processMessage(NotificationMessage.CommandZoneSync.parseFrom(new ByteArrayInputStream(data[1]))));
}
else if (NotificationMessage.Message.parseFrom(data[0]).getType() == fr.ill.ics.nomadserver.notification.NotificationMessage.Message.Type.NewCommandZoneEstimatedTime) {
notifyCommandZoneEstimatedTime(NotificationMessage.EstimatedTimeMessage.parseFrom(new ByteArrayInputStream(data[1])));
}
else {
System.out.println("Unable to process " + NotificationMessage.Message.parseFrom(data[0]).getType());
}
......@@ -253,6 +257,10 @@ public class ServerCommandZoneEventManager {
private void notifyCommandBoxesDeleted(CommandBoxesDeleted message) {
CommandZoneEventClient.getInstance().eventOccurred(new CommandBoxesDeletedEvent(message.getCommandZoneID(), message.getCommandBoxIDList()));
}
private void notifyCommandZoneEstimatedTime(EstimatedTimeMessage message) {
CommandZoneEventClient.getInstance().eventOccurred(new NewEstimatedTimeEvent(message.getCommandZoneID(), message.getValue()));
}
private void notifyCommandZoneSync(ICommandZoneSyncEvent event) {
......
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