Commit 7e0a75a3 authored by Locatelli's avatar Locatelli
Browse files

- Add two new calls for transferring properties values and commands

state in one time
- Do not load spyProperties for tablette client.
parent df063c47
......@@ -36,6 +36,7 @@ public interface Controller {
public Map getPropertyNamesAndTypes();
public String getPropertyType(String propertyName);
public Map getPropertyNamesAndValues();
public void addServerPropertyChangeListener(ServerPropertyChangeListener listener);
......
......@@ -318,4 +318,12 @@ public class ControllerManager implements ServerConfigurationChangeListener {
ControllerServant controller = (ControllerServant)servant;
return ServantManagerAccessor.getInstance(serverId).getControllerNameWithRole(controller.getId(), role);
}
public HashMap<String, String> getServantPropertiesValue(int databaseID, int servantID) {
return ServantManagerAccessor.getInstance(serverId).getServantPropertiesValue(databaseID, servantID);
}
public HashMap<String, Integer> getServantCommandStates(int databaseID, int servantID) {
return ServantManagerAccessor.getInstance(serverId).getServantCommandStates(databaseID, servantID);
}
}
......@@ -71,6 +71,11 @@ public class AtomicCommandWrapper extends CommandWrapper implements Controller {
// not needed for command: generic controller
return null;
}
public Map getPropertyNamesAndValues() {
// not needed for command: generic controller
return null;
}
public int getId() {
return serverAtomicCommandBox.getId();
......
......@@ -36,16 +36,18 @@ public class Command extends CommandAction implements ServerCommandStateChangeLi
private String serverId;
// package protected constructor (have to be created by CommandManager)
Command(int databaseId, int id, String commandName) {
Command(int databaseId, int id, String commandName, boolean getstate) {
super(commandName);
this.id = id;
this.databaseId = databaseId;
DataNotificationClient.getInstance().addCommandStateChangeListener(this);
DataNotificationClient.getInstance().addCommandProgressionChangeListener(this);
serverId = DataAccessor.getServerId(databaseId);
this.isRunning = (DataAccessor.getInstance(serverId).getCommandState(0, id) == ClientCommandState.ACTIVE);
if (getstate) {
this.isRunning = (DataAccessor.getInstance(serverId).getCommandState(0, id) == ClientCommandState.ACTIVE);
}
}
public ClientCommandState getCommandState() {
return DataAccessor.getInstance(serverId).getCommandState(0, id);
......
......@@ -126,6 +126,10 @@ public abstract class CommandAction {
return isRunning;
}
public void setStarted(boolean running) {
isRunning = running;
}
public int getProgress() {
return progress;
}
......
......@@ -19,12 +19,18 @@
package fr.ill.ics.core.command;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.ControllerManager;
import fr.ill.ics.bridge.command.AtomicCommandWrapper;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientCommandState;
import fr.ill.ics.nscclient.servant.Servant;
import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.exception.CommandNotFoundException;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
......@@ -71,7 +77,7 @@ public class CommandManager {
} else {
int id = CommandDatabase.getInstance().getCommandId(servantId, commandName);
if (id != -1) {
command = new Command(controller.getDatabaseId(), id, commandName);
command = new Command(controller.getDatabaseId(), id, commandName, true);
allCommands.put(commandName, command);
}
}
......@@ -86,4 +92,48 @@ public class CommandManager {
return getCommand(controller, commandName, false, PluginType.GENERAL);
}
public Map getAllCommands(Controller controller) {
if (controllerCommands == null) {
controllerCommands = new HashMap();
}
if (!controllerCommands.containsKey(controller)) {
controllerCommands.put(controller, new HashMap());
}
else {
return (HashMap) controllerCommands.get(controller);
}
int servantId;
int databaseId;
if (controller instanceof Servant) {
servantId = ((Servant)controller).getId();
databaseId = ((Servant)controller).getDatabaseId();
} else {
servantId = ((AtomicCommandWrapper)controller).getServantId();
databaseId = ((AtomicCommandWrapper)controller).getDatabaseId();
}
Map allCommands = (HashMap)controllerCommands.get(controller);
Command command = null;
HashMap<String, Integer> states = ControllerManager.getInstance().getServantCommandStates(databaseId, servantId);
Set names = controller.getCommandNames();
if (names != null) {
Iterator it = names.iterator();
String commandName;
int id;
while (it.hasNext()) {
commandName = (String)it.next();
id = CommandDatabase.getInstance().getCommandId(servantId, commandName);
if (id != -1) {
command = new Command(controller.getDatabaseId(), id, commandName, false);
command.setStarted(states.get(commandName).intValue() == ClientCommandState.ACTIVE.ordinal());
allCommands.put(commandName, command);
}
}
}
return allCommands;
}
}
\ No newline at end of file
......@@ -682,9 +682,6 @@ public class DataAccessor {
} else if (commandState == Common.CommandStateType.Type.ACTIVE) {
return ClientCommandState.ACTIVE;
} else if (commandState == Common.CommandStateType.Type.ACTIVE) {
return ClientCommandState.ACTIVE;
} else if (commandState == Common.CommandStateType.Type.PAUSED) {
return ClientCommandState.PAUSED;
......
......@@ -31,19 +31,25 @@ import java.util.logging.Logger;
import com.google.protobuf.InvalidProtocolBufferException;
import fr.ill.ics.bridge.events.ServerCommandStateChangeEvent.CommandState;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.RequesterCreationException;
import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.PropertyValue;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.CommandStateValue;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantCommandsState;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantData;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDataUpdate;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDescriptor;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDynamicProperties;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantPropertiesValue;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantSpyProperties;
import fr.ill.ics.nomadserver.servantmanager.ServantManagerRequest;
import fr.ill.ics.nscclient.servant.ClientCommandDescriptor;
import fr.ill.ics.nscclient.servant.ClientServantDescriptor;
import fr.ill.ics.nscclient.servant.ConfigurationManager;
import fr.ill.ics.nscclient.servant.ControllerServant;
import fr.ill.ics.nscclient.servant.DriverServant;
import fr.ill.ics.nscclient.servant.DriverServant.Mode;
......@@ -489,8 +495,10 @@ public class ServantManagerAccessor {
}
// add the spy properties
if (driver == false) {
addSpyProperties(servant.getId());
if (ConfigurationManager.getInstance().isMainClient()) {
if (driver == false) {
addSpyProperties(servant.getId());
}
}
return servant;
......@@ -880,7 +888,69 @@ public class ServantManagerAccessor {
}
}
public HashMap<String, String> getServantPropertiesValue(int databaseID, int servantID) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.GetServantPropertiesValue)
.build();
// Create the request.
ServantManagerRequest.ServantRequest request = ServantManagerRequest.ServantRequest.newBuilder()
.setDatabaseID(databaseID)
.setServantID(servantID)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
ServantPropertiesValue response = ServantPropertiesValue.parseFrom(servantManagerRequester.receive());
HashMap<String, String> properties = new HashMap<String, String>();
Iterator<PropertyValue> p = response.getPropertiesList().iterator();
while (p.hasNext()) {
PropertyValue prop = p.next();
properties.put(prop.getName(), prop.getValue());
}
return properties;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getServantPropertiesValue", "error in parsing response");
}
return null;
}
public HashMap<String, Integer> getServantCommandStates(int databaseID, int servantID) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.GetServantCommandsState)
.build();
// Create the request.
ServantManagerRequest.ServantRequest request = ServantManagerRequest.ServantRequest.newBuilder()
.setDatabaseID(databaseID)
.setServantID(servantID)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
ServantCommandsState response = ServantCommandsState.parseFrom(servantManagerRequester.receive());
HashMap<String, Integer> commands = new HashMap<String, Integer>();
Iterator<CommandStateValue> p = response.getCommandsList().iterator();
while (p.hasNext()) {
CommandStateValue command = p.next();
commands.put(command.getName(), command.getValue());
}
return commands;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getServantCommandStates", "error in parsing response");
}
return null;
}
}
\ No newline at end of file
......@@ -26,15 +26,16 @@ public class ConfigurationManager {
private static ConfigurationManager instance = null;
private String serverId;
private ServantManagerAccessor servantManagerAccessor;
private boolean mainClient;
public class LoadFailure extends Exception {}
public static ConfigurationManager getInstance() {
return instance;
}
public static void initInstance(String serverId) throws LoadFailure {
instance = new ConfigurationManager(serverId);
public static void initInstance(String serverId, boolean mainclient) throws LoadFailure {
instance = new ConfigurationManager(serverId, mainclient);
instance.init();
}
......@@ -45,8 +46,9 @@ public class ConfigurationManager {
/**
*
*/
private ConfigurationManager(String serverId) {
private ConfigurationManager(String serverId, boolean mainclient) {
this.serverId = serverId;
this.mainClient = mainclient;
}
/**
......@@ -67,5 +69,9 @@ public class ConfigurationManager {
throw new LoadFailure();
}
}
public boolean isMainClient() {
return mainClient;
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@
package fr.ill.ics.nscclient.servant;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
......@@ -32,6 +33,7 @@ import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientCommandState;
import fr.ill.ics.nscclient.dataprovider.PropertyDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.notification.DataNotificationClient;
......@@ -97,7 +99,10 @@ public class Servant implements Controller {
return PropertyDatabase.getInstance().getPropertyNamesAndTypes(servantDescriptor.getId());
}
public HashMap<String, String> getPropertyNamesAndValues() {
return ControllerManager.getInstance().getServantPropertiesValue(databaseId, servantId);
}
public int getId() {
return servantId;
}
......
......@@ -98,7 +98,7 @@ public class ServerSessionManager {
// This is because ControllerManager and DriverManager are accessed by getInstance() without any serverId
if (serverId.equals("real") || (!serverId.equals("real") && !getInstance("real").isLogged())) {
ConfigurationManager.initInstance(serverId);
ConfigurationManager.initInstance(serverId, true);
ResourceManager.initInstance(serverId);
ControllerManager.initInstance(serverId);
DriverManager.initInstance(serverId);
......@@ -134,7 +134,7 @@ public class ServerSessionManager {
// This is because ControllerManager and DriverManager are accessed by getInstance() without any serverId
if (serverId.equals("real") || (!serverId.equals("real") && !getInstance("real").isLogged())) {
ConfigurationManager.initInstance(serverId);
ConfigurationManager.initInstance(serverId, false);
ResourceManager.initInstance(serverId);
ControllerManager.initInstance(serverId);
DriverManager.initInstance(serverId);
......
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