Commit 2180bdb1 authored by yannick legoc's avatar yannick legoc

Update of dynamic properties is now made by protocol buffers

parent ef19944a
......@@ -77,7 +77,7 @@ public abstract class ControllerManager {
public abstract HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric();
public abstract void createDynamicPropertiesForController(Controller controller);
public abstract void updateDynamicProperties(Controller controller);
public abstract void reloadControllers();
......
......@@ -246,9 +246,9 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
}
public void createDynamicPropertiesForController(Controller controller) {
public void updateDynamicProperties(Controller controller) {
CorbaController corbaController = (CorbaController)controller;
corbaController.updateDynamicProperties();
servantManager.updateDynamicProperties(corbaController.getId());
}
......@@ -258,18 +258,11 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
// the reload of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes
CorbaServant servant = servantManager.getServant(servantID);
if (servant != null) {
servant.updateDynamicProperties();
}
servantManager.updateDynamicProperties(servantID);
}
@Override
public void reloadControllers() {
System.out.println("reloading controllers");
// reset controller information
reset();
}
......
......@@ -24,6 +24,7 @@ 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.listeners.ServerCommandStateChangeListener;
import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener;
......@@ -246,40 +247,42 @@ public class CorbaServant implements Controller {
public void updateDynamicProperties() {
// first remove the current dynamic descriptors
PropertyDatabase.getInstance().removeDynamicPropertyDescriptors(servantDescriptor.getId());
PropertyManager.getInstance().removeDynamicProperties(servantDescriptor.getId());
ControllerManager.getInstance().updateDynamicProperties(this);
// 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();
}
// // 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
......@@ -30,11 +30,13 @@ import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
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.configuration.ServantDataConfiguration;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantData;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDataUpdate;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDynamicProperties;
import fr.ill.ics.nomadserver.core.Driver;
import fr.ill.ics.nomadserver.core.ServantManager;
import fr.ill.ics.nomadserver.core.DriverPackage.DriverMode;
......@@ -385,26 +387,16 @@ public class CorbaServantManager {
public void updateWholeConfiguration() {
System.out.println("updating whole configuration");
long begin = new Date().getTime();
byte[] pbResult = servantManager.getWholeConfigurationUpdate(DATABASE_ID);
long end = new Date().getTime();
System.out.println("got whole configuration update PB in " + (end - begin) + "ms");
begin = new Date().getTime();
ServantDataUpdate servantDataUpdate = null;
try {
servantDataUpdate = ServantDataUpdate.parseFrom(new ByteArrayInputStream(pbResult));
} catch (IOException e) {
System.err.println("cannot parse servant data update");
return;
}
end = new Date().getTime();
System.out.println("servant data update parsed into " + (end - begin) + "ms");
updateAllMaps(servantDataUpdate.getDriversList(), true);
updateAllMaps(servantDataUpdate.getControllersList(), false);
}
......@@ -425,4 +417,58 @@ public class CorbaServantManager {
descriptor.setEnabled(pbServant.getEnabled());
}
}
public void updateDynamicProperties(int servantID) {
// first remove the current dynamic descriptors
PropertyDatabase.getInstance().removeDynamicPropertyDescriptors(servantID);
PropertyManager.getInstance().removeDynamicProperties(servantID);
// get the dynamic properties from the server
byte[] pbResult;
try {
pbResult = servantManager.getServantDynamicProperties(DATABASE_ID, servantID);
} catch (NoSuchServantException e) {
System.err.println("cannot update dynamic properties of servant with ID " + servantID);
return;
}
ServantDynamicProperties servantDynamicProperties = null;
try {
servantDynamicProperties = ServantDynamicProperties.parseFrom(new ByteArrayInputStream(pbResult));
} catch (IOException e) {
System.err.println("cannot parse servant dynamic properties");
return;
}
// iterate the properties
Iterator<ServantDataConfiguration.PropertyDescriptor> p = servantDynamicProperties.getPropertiesList().iterator();
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(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");
}
}
}
}
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