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

Update of dynamic properties is now made by protocol buffers

parent ef19944a
...@@ -77,7 +77,7 @@ public abstract class ControllerManager { ...@@ -77,7 +77,7 @@ public abstract class ControllerManager {
public abstract HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric(); public abstract HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric();
public abstract void createDynamicPropertiesForController(Controller controller); public abstract void updateDynamicProperties(Controller controller);
public abstract void reloadControllers(); public abstract void reloadControllers();
......
...@@ -246,9 +246,9 @@ public class CorbaControllerManager extends ControllerManager implements ServerC ...@@ -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 corbaController = (CorbaController)controller;
corbaController.updateDynamicProperties(); servantManager.updateDynamicProperties(corbaController.getId());
} }
...@@ -258,18 +258,11 @@ public class CorbaControllerManager extends ControllerManager implements ServerC ...@@ -258,18 +258,11 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
// the reload of controllers is not made here but in the CommandsSelectionPlugin // the reload of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes // and SettingsSelectionPlugin classes
servantManager.updateDynamicProperties(servantID);
CorbaServant servant = servantManager.getServant(servantID);
if (servant != null) {
servant.updateDynamicProperties();
}
} }
@Override @Override
public void reloadControllers() { public void reloadControllers() {
System.out.println("reloading controllers");
// reset controller information // reset controller information
reset(); reset();
} }
......
...@@ -24,6 +24,7 @@ import java.util.Map; ...@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import fr.ill.ics.bridge.Controller; 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.ServerCommandStateChangeListener;
import fr.ill.ics.bridge.listeners.ServerProgressChangeListener; import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener; import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener;
...@@ -246,40 +247,42 @@ public class CorbaServant implements Controller { ...@@ -246,40 +247,42 @@ public class CorbaServant implements Controller {
public void updateDynamicProperties() { public void updateDynamicProperties() {
// first remove the current dynamic descriptors ControllerManager.getInstance().updateDynamicProperties(this);
PropertyDatabase.getInstance().removeDynamicPropertyDescriptors(servantDescriptor.getId());
PropertyManager.getInstance().removeDynamicProperties(servantDescriptor.getId());
// re-inserts the dynamic descriptors, replacing the old ones // // first remove the current dynamic descriptors
try { // PropertyDatabase.getInstance().removeDynamicPropertyDescriptors(servantDescriptor.getId());
ListIterator iterator = servant.getProperties(databaseId); // PropertyManager.getInstance().removeDynamicProperties(servantDescriptor.getId());
//
// iterate over the list and create a new non-corba ServantDescriptor for each item // // re-inserts the dynamic descriptors, replacing the old ones
while (iterator.hasNext()) { // try {
ListItem item = iterator.next(); // ListIterator iterator = servant.getProperties(databaseId);
//
PropertyDescriptor corbaDescriptor = PropertyDescriptorHelper.narrow(item); // // iterate over the list and create a new non-corba ServantDescriptor for each item
// while (iterator.hasNext()) {
// copy sequence values into vector // ListItem item = iterator.next();
List<Integer> ids = new ArrayList<Integer>(); //
int[] idArray = corbaDescriptor.getIDArray(); // PropertyDescriptor corbaDescriptor = PropertyDescriptorHelper.narrow(item);
//
int propertyId = idArray[0]; // // copy sequence values into vector
// List<Integer> ids = new ArrayList<Integer>();
for (int i = 1; i < idArray.length; i++) { // int[] idArray = corbaDescriptor.getIDArray();
ids.add(new Integer(idArray[i])); //
} // int propertyId = idArray[0];
//
if (corbaDescriptor.isDynamic()) { // for (int i = 1; i < idArray.length; i++) {
PropertyDatabase.getInstance().addDynamicPropertyDescriptor(servantDescriptor.getId(), new DynamicPropertyDescriptor(propertyId, ids, corbaDescriptor.getName(), corbaDescriptor.getType())); // ids.add(new Integer(idArray[i]));
} // }
} //
// release the corba object // if (corbaDescriptor.isDynamic()) {
iterator.releaseIterator(); // PropertyDatabase.getInstance().addDynamicPropertyDescriptor(servantDescriptor.getId(), new DynamicPropertyDescriptor(propertyId, ids, corbaDescriptor.getName(), corbaDescriptor.getType()));
// }
} catch (IteratorFailureException e) { // }
e.printStackTrace(); // // 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; ...@@ -30,11 +30,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.nomadserver.common.ListItem; import fr.ill.ics.nomadserver.common.ListItem;
import fr.ill.ics.nomadserver.common.ListIterator; import fr.ill.ics.nomadserver.common.ListIterator;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration; import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantData; import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantData;
import fr.ill.ics.nomadserver.configuration.ServantDataConfiguration.ServantDataUpdate; 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.Driver;
import fr.ill.ics.nomadserver.core.ServantManager; import fr.ill.ics.nomadserver.core.ServantManager;
import fr.ill.ics.nomadserver.core.DriverPackage.DriverMode; import fr.ill.ics.nomadserver.core.DriverPackage.DriverMode;
...@@ -385,26 +387,16 @@ public class CorbaServantManager { ...@@ -385,26 +387,16 @@ public class CorbaServantManager {
public void updateWholeConfiguration() { public void updateWholeConfiguration() {
System.out.println("updating whole configuration");
long begin = new Date().getTime();
byte[] pbResult = servantManager.getWholeConfigurationUpdate(DATABASE_ID); 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; ServantDataUpdate servantDataUpdate = null;
try { try {
servantDataUpdate = ServantDataUpdate.parseFrom(new ByteArrayInputStream(pbResult)); servantDataUpdate = ServantDataUpdate.parseFrom(new ByteArrayInputStream(pbResult));
} catch (IOException e) { } catch (IOException e) {
System.err.println("cannot parse servant data update"); 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.getDriversList(), true);
updateAllMaps(servantDataUpdate.getControllersList(), false); updateAllMaps(servantDataUpdate.getControllersList(), false);
} }
...@@ -425,4 +417,58 @@ public class CorbaServantManager { ...@@ -425,4 +417,58 @@ public class CorbaServantManager {
descriptor.setEnabled(pbServant.getEnabled()); 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