Commit ef19944a authored by yannick legoc's avatar yannick legoc

added ServantManager.getWholeConfigurationUpdate based on protocol buffer data...

added ServantManager.getWholeConfigurationUpdate based on protocol buffer data for updating enabled/disabled controllers
parent d8a9ff67
......@@ -185,7 +185,7 @@ public class ServantDatabase {
return null;
}
private ClientServantDescriptor getServantDescriptorWithId(int servantId) {
public ClientServantDescriptor getServantDescriptorWithId(int servantId) {
ClientServantDescriptor descriptor = controllers.get(servantId);
if (descriptor == null) {
descriptor = drivers.get(servantId);
......
......@@ -80,10 +80,18 @@ public class ClientServantDescriptor {
return isRoot;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
public void setFamily(String family) {
this.family = family;
}
public String toString() {
return "ClientServantDescriptor " + type + " " + name + " : enabled = " + isEnabled + " visible = " + isVisible + " favourite = " + isFavourite;
}
......
......@@ -61,14 +61,7 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
protected void reset() {
this.servantManager = ServerSessionManager.getInstance(serverId).getServantManager();
List controllersList = servantManager.getControllers();
Iterator it = controllersList.iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = (ClientServantDescriptor)it.next();
ServantDatabase.getInstance().addController(descriptor);
}
servantManager.updateWholeConfiguration();
fillControllerNamesByTypeMaps();
}
......@@ -261,6 +254,8 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
public void configurationChanged(int servantID, ClientEnableState enable) {
System.out.println("CorbaControllerManager configurationChanged " + servantID + " " + enable);
// the reload of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes
......@@ -273,8 +268,9 @@ public class CorbaControllerManager extends ControllerManager implements ServerC
@Override
public void reloadControllers() {
System.out.println("reloading controllers");
// reset controller information
ServantDatabase.getInstance().clearControllers();
reset();
}
......
......@@ -42,12 +42,6 @@ public class CorbaDriverManager extends DriverManager {
protected void init() {
this.servantManager = ServerSessionManager.getInstance(serverId).getServantManager();
List driversList = servantManager.getDrivers();
Iterator it = driversList.iterator();
while (it.hasNext()) {
ServantDatabase.getInstance().addDriver((ClientServantDescriptor)it.next());
}
}
public CorbaDriver getDriver(String driverName) {
......
......@@ -34,6 +34,7 @@ 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.core.Driver;
import fr.ill.ics.nomadserver.core.ServantManager;
import fr.ill.ics.nomadserver.core.DriverPackage.DriverMode;
......@@ -183,9 +184,6 @@ public class CorbaServantManager {
CorbaDriver driver = new CorbaDriver(DATABASE_ID, descriptor.getId(), null, descriptor);
driver.setChannel(channel);
driver.setMode(mode);
System.out.println("created driver " + descriptor.getId() + " mode " + mode);
// no init here
servants.put(descriptor.getId(), driver);
return driver;
......@@ -216,68 +214,8 @@ public class CorbaServantManager {
}
public List getDrivers() {
List drivers = new ArrayList();
try {
ListIterator iterator = servantManager.getDriversIterator(DATABASE_ID);
// iterate over the list and create a new non-corba ServantDescriptor for each item
while (iterator.hasNext()) {
ListItem item = iterator.next();
ServantDescriptor corbaDescriptor = ServantDescriptorHelper.narrow(item);
drivers.add(new ClientServantDescriptor(corbaDescriptor.getID(), corbaDescriptor.getName(), corbaDescriptor.getClientType(), corbaDescriptor.getFamily(), corbaDescriptor.isCommand(), corbaDescriptor.isVisible(), corbaDescriptor.isEnabled(), false, corbaDescriptor.isRoot()));
}
// release the corba object
iterator.releaseIterator();
} catch (IteratorFailureException e) {
e.printStackTrace();
}
return drivers;
}
public List<String> getChildServants(int id) {
return childServantNames.get(id);
// List<String> children = new ArrayList<String>();
//
// try {
// ListIterator iterator = servantManager.getChildServantsIterator(DATABASE_ID, id);
//
// // iterate over the list and create a new non-corba ServantDescriptor for each item
// while (iterator.hasNext()) {
// ListItem item = iterator.next();
//
// ChildServantDescriptor corbaDescriptor = ChildServantDescriptorHelper.narrow(item);
// String[] nameArray = corbaDescriptor.getNameArray();
// int[] indexArray = corbaDescriptor.getIndexArray();
// for (int i = 0; i < nameArray.length; i++) {
// children.add(nameArray[i]);
//
// if (indexArray[i] != -1) {
// int servantID = ServantDatabase.getInstance().getServantId(nameArray[i]);
// if (servants.containsKey(servantID)) {
// CorbaServant servant = servants.get(servantID);
// if (servant instanceof CorbaDriver) {
// CorbaDriver driver = (CorbaDriver)servant;
// driver.setChannel(indexArray[i]);
// }
// }
// }
// }
//
// }
// // release the corba object
// iterator.releaseIterator();
//
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// return children;
}
public void pauseSpies(boolean isPaused) {
......@@ -343,14 +281,14 @@ public class CorbaServantManager {
System.out.println("loaded whole configuration PB in " + (end - begin) + "ms");
}
private void initAllMaps(List<ServantDataConfiguration.ServantDescriptor> servants) {
private void initAllMaps(List<ServantDataConfiguration.ServantDescriptor> servants, boolean drivers) {
// iterate over controllers
Iterator<ServantDataConfiguration.ServantDescriptor> c = servants.iterator();
// iterate over servants
Iterator<ServantDataConfiguration.ServantDescriptor> s = servants.iterator();
while (c.hasNext()) {
while (s.hasNext()) {
ServantDataConfiguration.ServantDescriptor pbServant = c.next();
ServantDataConfiguration.ServantDescriptor pbServant = s.next();
// add the controller in ServantDatabase
ClientServantDescriptor descriptor = new ClientServantDescriptor(pbServant.getID(),
......@@ -363,7 +301,7 @@ public class CorbaServantManager {
false,
pbServant.getRoot());
if (pbServant.getDriver()) {
if (drivers) {
ServantDatabase.getInstance().addDriver(descriptor);
ServantDataConfiguration.ServantDescriptor.Mode pbMode = pbServant.getMode();
......@@ -441,8 +379,50 @@ public class CorbaServantManager {
private void initAllMaps(ServantData servantData) {
initAllMaps(servantData.getDriversList());
initAllMaps(servantData.getControllersList());
initAllMaps(servantData.getDriversList(), true);
initAllMaps(servantData.getControllersList(), false);
}
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");
}
end = new Date().getTime();
System.out.println("servant data update parsed into " + (end - begin) + "ms");
updateAllMaps(servantDataUpdate.getDriversList(), true);
updateAllMaps(servantDataUpdate.getControllersList(), false);
}
private void updateAllMaps(List<ServantDataConfiguration.ServantInfo> servants, boolean drivers) {
// iterate over servants
Iterator<ServantDataConfiguration.ServantInfo> s = servants.iterator();
while (s.hasNext()) {
ServantDataConfiguration.ServantInfo pbServant = s.next();
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getServantDescriptorWithId(pbServant.getID());
descriptor.setFamily(pbServant.getFamily());
descriptor.setVisible(pbServant.getVisible());
descriptor.setEnabled(pbServant.getEnabled());
}
}
}
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