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

cloneController is now using the PB communication

parent 2180bdb1
......@@ -18,8 +18,6 @@
package fr.ill.ics.nscclient.servant;
import java.io.IOException;
import fr.ill.ics.nscclient.servant.CorbaServantManager.LoadConfigurationFailure;
import fr.ill.ics.nscclient.sessionmanagement.ServerSessionManager;
......
......@@ -30,7 +30,6 @@ import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener;
import fr.ill.ics.bridge.listeners.ServerResetCommandListener;
import fr.ill.ics.core.command.CommandAction;
import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.nomadserver.common.ListItem;
import fr.ill.ics.nomadserver.common.ListIterator;
import fr.ill.ics.nomadserver.core.Servant;
......@@ -246,43 +245,7 @@ public class CorbaServant implements Controller {
}
public void updateDynamicProperties() {
ControllerManager.getInstance().updateDynamicProperties(this);
// // first remove the current dynamic descriptors
// PropertyDatabase.getInstance().removeDynamicPropertyDescriptors(servantDescriptor.getId());
// PropertyManager.getInstance().removeDynamicProperties(servantDescriptor.getId());
//
// // re-inserts the dynamic descriptors, replacing the old ones
// try {
// ListIterator iterator = servant.getProperties(databaseId);
//
// // iterate over the list and create a new non-corba ServantDescriptor for each item
// while (iterator.hasNext()) {
// ListItem item = iterator.next();
//
// PropertyDescriptor corbaDescriptor = PropertyDescriptorHelper.narrow(item);
//
// // copy sequence values into vector
// List<Integer> ids = new ArrayList<Integer>();
// int[] idArray = corbaDescriptor.getIDArray();
//
// int propertyId = idArray[0];
//
// for (int i = 1; i < idArray.length; i++) {
// ids.add(new Integer(idArray[i]));
// }
//
// if (corbaDescriptor.isDynamic()) {
// PropertyDatabase.getInstance().addDynamicPropertyDescriptor(servantDescriptor.getId(), new DynamicPropertyDescriptor(propertyId, ids, corbaDescriptor.getName(), corbaDescriptor.getType()));
// }
// }
// // release the corba object
// iterator.releaseIterator();
//
// } catch (IteratorFailureException e) {
// e.printStackTrace();
// }
}
}
\ No newline at end of file
......@@ -115,29 +115,6 @@ public class CorbaServantManager {
}
public CorbaController cloneController(ClientServantDescriptor descriptor) {
CorbaController controller = null;
try {
int servantId = servantManager.cloneController(descriptor.getId());
// force the servant to be invisible
ClientServantDescriptor clonedDescriptor = new ClientServantDescriptor(servantId, servantManager.getController(servantId).getName(DATABASE_ID), descriptor.getType(), descriptor.getFamily(), descriptor.isCommand(), false, descriptor.isEnabled(), descriptor.isFavourite(), descriptor.isRoot());
ServantDatabase.getInstance().addController(clonedDescriptor);
controller = new CorbaController(DATABASE_ID, servantId, servantManager.getController(servantId), clonedDescriptor);
controller.init();
servants.put(servantId, controller);
return controller;
} catch (NoSuchServantException e) {
return null;
} catch (ServantCreationException e) {
return null;
}
}
public void removeController(ClientServantDescriptor descriptor) {
try {
......@@ -283,99 +260,108 @@ public class CorbaServantManager {
System.out.println("loaded whole configuration PB in " + (end - begin) + "ms");
}
private void initAllMaps(List<ServantDataConfiguration.ServantDescriptor> servants, boolean drivers) {
// iterate over servants
Iterator<ServantDataConfiguration.ServantDescriptor> s = servants.iterator();
while (s.hasNext()) {
private CorbaServant initAllMaps(ServantDataConfiguration.ServantDescriptor pbServant, boolean driver) {
CorbaServant servant = null;
// add the controller in ServantDatabase
ClientServantDescriptor descriptor = new ClientServantDescriptor(pbServant.getID(),
pbServant.getName(),
pbServant.getClientType(),
pbServant.getFamily(),
pbServant.getCommand(),
pbServant.getVisible(),
pbServant.getEnabled(),
false,
pbServant.getRoot());
if (driver) {
ServantDatabase.getInstance().addDriver(descriptor);
ServantDataConfiguration.ServantDescriptor pbServant = s.next();
// add the controller in ServantDatabase
ClientServantDescriptor descriptor = new ClientServantDescriptor(pbServant.getID(),
pbServant.getName(),
pbServant.getClientType(),
pbServant.getFamily(),
pbServant.getCommand(),
pbServant.getVisible(),
pbServant.getEnabled(),
false,
pbServant.getRoot());
ServantDataConfiguration.ServantDescriptor.Mode pbMode = pbServant.getMode();
if (drivers) {
ServantDatabase.getInstance().addDriver(descriptor);
ServantDataConfiguration.ServantDescriptor.Mode pbMode = pbServant.getMode();
CorbaDriver.Mode mode = CorbaDriver.Mode.REAL;
if (pbMode == ServantDataConfiguration.ServantDescriptor.Mode.REAL) {
mode = CorbaDriver.Mode.REAL;
} else if (pbMode == ServantDataConfiguration.ServantDescriptor.Mode.PERFECT) {
mode = CorbaDriver.Mode.PERFECT;
} else if (pbMode == ServantDataConfiguration.ServantDescriptor.Mode.SIMULATED) {
mode = CorbaDriver.Mode.SIMULATED;
}
createCorbaDriver(descriptor, pbServant.getChannel(), mode);
} else {
ServantDatabase.getInstance().addController(descriptor);
createCorbaController(descriptor);
CorbaDriver.Mode mode = CorbaDriver.Mode.REAL;
if (pbMode == ServantDataConfiguration.ServantDescriptor.Mode.REAL) {
mode = CorbaDriver.Mode.REAL;
} else if (pbMode == ServantDataConfiguration.ServantDescriptor.Mode.PERFECT) {
mode = CorbaDriver.Mode.PERFECT;
} else if (pbMode == ServantDataConfiguration.ServantDescriptor.Mode.SIMULATED) {
mode = CorbaDriver.Mode.SIMULATED;
}
servant = createCorbaDriver(descriptor, pbServant.getChannel(), mode);
} else {
ServantDatabase.getInstance().addController(descriptor);
servant = createCorbaController(descriptor);
}
// add the list of child names
LinkedList<String> childNames = new LinkedList<String>();
// add the list of child names
LinkedList<String> childNames = new LinkedList<String>();
// first level of child is not necessary to get the information
// ex: for drivers, pbChild1 = "children"
List<ServantDataConfiguration.ChildDescriptor> pbChildren = pbServant.getChildrenList();
// first level of child is not necessary to get the information
// ex: for drivers, pbChild1 = "children"
List<ServantDataConfiguration.ChildDescriptor> pbChildren = pbServant.getChildrenList();
Iterator<ServantDataConfiguration.ChildDescriptor> cd = pbChildren.iterator();
while (cd.hasNext()) {
ServantDataConfiguration.ChildDescriptor pbChild1 = cd.next();
Iterator<ServantDataConfiguration.ChildDescriptor> cd = pbChildren.iterator();
while (cd.hasNext()) {
ServantDataConfiguration.ChildDescriptor pbChild1 = cd.next();
Iterator<ServantDataConfiguration.ChildDescriptor.Child> ccd = pbChild1.getChildArrayList().iterator();
while (ccd.hasNext()) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = ccd.next();
Iterator<ServantDataConfiguration.ChildDescriptor.Child> ccd = pbChild1.getChildArrayList().iterator();
while (ccd.hasNext()) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = ccd.next();
childNames.add(pbChild2.getName());
}
childNames.add(pbChild2.getName());
}
}
childServantNames.put(descriptor.getId(), childNames);
// initialise the controller
Iterator<ServantDataConfiguration.PropertyDescriptor> p = pbServant.getPropertiesList().iterator();
while (p.hasNext()) {
childServantNames.put(descriptor.getId(), childNames);
ServantDataConfiguration.PropertyDescriptor pbProperty = p.next();
// copy sequence values
List<Integer> pbIds = pbProperty.getIDArrayList();
Iterator<Integer> i = pbIds.iterator();
int propertyId = i.next();
// initialise the controller
Iterator<ServantDataConfiguration.PropertyDescriptor> p = pbServant.getPropertiesList().iterator();
List<Integer> ids = new LinkedList<Integer>();
while (i.hasNext()) {
ids.add(i.next());
}
while (p.hasNext()) {
ServantDataConfiguration.PropertyDescriptor pbProperty = p.next();
// copy sequence values
List<Integer> pbIds = pbProperty.getIDArrayList();
Iterator<Integer> i = pbIds.iterator();
int propertyId = i.next();
List<Integer> ids = new LinkedList<Integer>();
while (i.hasNext()) {
ids.add(i.next());
}
if (pbProperty.getDynamic()) {
PropertyDatabase.getInstance().addDynamicPropertyDescriptor(descriptor.getId(), new DynamicPropertyDescriptor(propertyId, ids, pbProperty.getName(), pbProperty.getType()));
} else {
PropertyDatabase.getInstance().addStandardPropertyDescriptor(descriptor.getId(), new StandardPropertyDescriptor(propertyId, pbProperty.getName(), pbProperty.getType()));
}
if (pbProperty.getDynamic()) {
PropertyDatabase.getInstance().addDynamicPropertyDescriptor(descriptor.getId(), new DynamicPropertyDescriptor(propertyId, ids, pbProperty.getName(), pbProperty.getType()));
} else {
PropertyDatabase.getInstance().addStandardPropertyDescriptor(descriptor.getId(), new StandardPropertyDescriptor(propertyId, pbProperty.getName(), pbProperty.getType()));
}
}
Iterator<ServantDataConfiguration.CommandDescriptor> d = pbServant.getCommandsList().iterator();
while (d.hasNext()) {
Iterator<ServantDataConfiguration.CommandDescriptor> d = pbServant.getCommandsList().iterator();
ServantDataConfiguration.CommandDescriptor pbCommand = d.next();
CommandDatabase.getInstance().addCommandDescriptor(descriptor.getId(), new ClientCommandDescriptor(pbCommand.getID(), pbCommand.getName()));
}
return servant;
}
private void initAllMaps(List<ServantDataConfiguration.ServantDescriptor> servants, boolean drivers) {
// iterate over servants
Iterator<ServantDataConfiguration.ServantDescriptor> s = servants.iterator();
while (s.hasNext()) {
while (d.hasNext()) {
ServantDataConfiguration.CommandDescriptor pbCommand = d.next();
CommandDatabase.getInstance().addCommandDescriptor(descriptor.getId(), new ClientCommandDescriptor(pbCommand.getID(), pbCommand.getName()));
}
ServantDataConfiguration.ServantDescriptor pbServant = s.next();
initAllMaps(pbServant, drivers);
}
}
......@@ -464,11 +450,40 @@ public class CorbaServantManager {
if (pbProperty.getDynamic()) {
PropertyDatabase.getInstance().addDynamicPropertyDescriptor(servantID, new DynamicPropertyDescriptor(propertyId, ids, pbProperty.getName(), pbProperty.getType()));
// System.out.println("added property " + pbProperty.getName() + " with ids size " + ids);
} else {
System.err.println("properties should be dynamic in updateDynamicProperties");
}
}
}
public CorbaController cloneController(ClientServantDescriptor descriptor) {
CorbaController controller = null;
try {
// call to server to clone the controller
int servantId = servantManager.cloneController(descriptor.getId());
// get the controller description from the server
byte[] pbResult = servantManager.getControllerConfiguration(DATABASE_ID, servantId);
ServantDataConfiguration.ServantDescriptor pbServant = null;
try {
pbServant = ServantDataConfiguration.ServantDescriptor.parseFrom(new ByteArrayInputStream(pbResult));
} catch (IOException e) {
System.err.println("cannot parse servant descriptor data");
}
controller = (CorbaController)initAllMaps(pbServant, false);
return controller;
} catch (NoSuchServantException e) {
return null;
} catch (ServantCreationException e) {
return null;
}
}
}
......@@ -19,7 +19,6 @@
package fr.ill.ics.nscclient.sessionmanagement;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
......
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