Commit 157a12aa authored by yannick legoc's avatar yannick legoc
Browse files

Clean-up with some corba... classes.

parent 2620ce2f
......@@ -18,22 +18,34 @@
package fr.ill.ics.bridge;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import fr.ill.ics.bridge.listeners.ServerConfigurationChangeListener;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor.LoadConfigurationFailure;
import fr.ill.ics.nscclient.notification.DataNotificationClient;
import fr.ill.ics.nscclient.servant.CorbaControllerManager;
import fr.ill.ics.nscclient.servant.ClientServantDescriptor;
import fr.ill.ics.nscclient.servant.Controller;
import fr.ill.ics.util.exception.ControllerNotFoundException;
public abstract class ControllerManager {
public class ControllerManager implements ServerConfigurationChangeListener {
private String serverId;
private HashMap<String, LinkedHashSet<String>> visibleControllerNamesByType; // KEY=controller type VALUE=list of matching controller names
private HashMap<String, LinkedHashSet<String>> allControllerNamesByType; // KEY=controller type VALUE=list of matching controller names
private static ControllerManager instance = null;
public static ControllerManager getInstance() {
......@@ -41,52 +53,269 @@ public abstract class ControllerManager {
}
public static void initInstance(String serverId) {
instance = new CorbaControllerManager(serverId);
instance = new ControllerManager(serverId);
instance.init();
}
public static void resetInstance() {
instance = null;
}
protected abstract void init();
public void addConfigurationChangeListener(ServerConfigurationChangeListener listener) {
DataNotificationClient.getInstance().addConfigurationChangeListener(listener);
}
public ControllerManager(String serverId) {
this.serverId = serverId;
addConfigurationChangeListener(this);
}
/**
*
*/
protected void init() {
fillControllerNamesByTypeMaps();
}
protected void reset() {
try {
ServantManagerAccessor.getInstance(serverId).updateWholeConfiguration();
} catch (LoadConfigurationFailure e) {
System.err.println("Unable to update the whole configuration");
}
fillControllerNamesByTypeMaps();
}
public abstract Set getCommandsOfType(String controllerType);
public abstract String getType(String controllerName);
/**
*
*/
public Controller getController(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
Controller controller = ServantManagerAccessor.getInstance(serverId).getController(descriptor);
return controller;
}
ControllerNotFoundException cnfe = new ControllerNotFoundException(controllerName, "", getClass().getCanonicalName(), "getController");
return null;
}
public abstract Map getInstalledCommands();
public Controller cloneController(String controllerName) throws ControllerNotFoundException {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
Controller controller = ServantManagerAccessor.getInstance(serverId).cloneController(descriptor);
return controller;
}
ControllerNotFoundException cnfe = new ControllerNotFoundException(controllerName, "", getClass().getCanonicalName(), "cloneController");
throw cnfe;
}
public abstract Map<String, Map<String, List<String>>> getInstalledControllers();
public void removeController(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
ServantManagerAccessor.getInstance(serverId).removeController(descriptor);
}
}
/**
*
*/
public Set<String> getControllersOfType(String type, boolean onlyVisibleOnes) {
return ServantDatabase.getInstance().getControllersOfType(type, onlyVisibleOnes);
}
public abstract Set<String> getControllerTypes();
public Set<String> getControllerTypes() {
return ServantDatabase.getInstance().getControllerTypes();
}
//public abstract Map getInstalledControllers();
public abstract Set<String> getControllersOfType(String type, boolean onlyVisibleOnes);
public boolean controllerIsEnabled(String controllerName) {
return ServantDatabase.getInstance().controllerIsEnabled(controllerName);
}
public HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric() {
return ServantManagerAccessor.getInstance(serverId).getPropertiesForGeneric();
}
public abstract boolean controllerIsEnabled(String controllerName);
public String getType(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
return descriptor.getType();
}
return null;
}
public abstract LinkedHashSet<String> getControllersOfTypeInDisplayOrder(String controllerType, boolean onlyVisibleOnes);
private Map<String, Map<String, List<String>>> getInstalledControllers(boolean testCommand) {
Map<String, Map<String, List<String>>> installedControllers = new TreeMap<String, Map<String, List<String>>>();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
boolean testCommandOk = true;
if (testCommand && !descriptor.isCommand()) {
testCommandOk = false;
}
if (testCommandOk && descriptor.isEnabled() && descriptor.isVisible()) {
String family = descriptor.getFamily();
String subfamily = descriptor.getSubfamily();
Map<String, List<String>> familyMembers = installedControllers.get(family);
if (familyMembers == null) {
familyMembers = new TreeMap<String, List<String>>();
installedControllers.put(family, familyMembers);
}
if (subfamily.equals("none")) {
familyMembers.put(descriptor.getName(), new ArrayList<String>());
} else {
List<String> subfamilyMembers = familyMembers.get(subfamily);
if (subfamilyMembers == null) {
subfamilyMembers = new ArrayList<String>();
familyMembers.put(subfamily, subfamilyMembers);
}
subfamilyMembers.add(descriptor.getName());
}
}
}
return installedControllers;
}
public Map<String, Map<String, List<String>>> getInstalledControllers() {
return getInstalledControllers(false);
}
public abstract Set getStartedControllers();
public Map<String, Map<String, List<String>>> getInstalledCommands() {
return getInstalledControllers(true);
}
/**
*
*/
private void fillControllerNamesByTypeMaps() {
visibleControllerNamesByType = new HashMap<String, LinkedHashSet<String>>();
allControllerNamesByType = new HashMap<String, LinkedHashSet<String>>();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
/**
* H.ORTIZ Sept.2012: remove test on isCommand property because the map "controllerNamesByType" is
* also used for "for-all" plugins in Settings tab. Somehow, it may now result in a inconstistency
* because if one controller of a given type has its attribute isCommand set to false, this controller
* will however appear in "for-all" spy plugins.
*/
if (descriptor.isEnabled()) {
String controllerType = descriptor.getType();
if (!allControllerNamesByType.containsKey(controllerType)) {
allControllerNamesByType.put(controllerType, new LinkedHashSet<String>());
}
LinkedHashSet<String> set = allControllerNamesByType.get(controllerType);
set.add(descriptor.getName());
if (descriptor.isVisible()) {
if (!visibleControllerNamesByType.containsKey(controllerType)) {
visibleControllerNamesByType.put(controllerType, new LinkedHashSet<String>());
}
LinkedHashSet<String> set2 = visibleControllerNamesByType.get(controllerType);
set2.add(descriptor.getName());
}
}
}
}
public Set getStartedControllers() {
Set startedCommands = new HashSet();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
Controller controller = getController(descriptor.getName());
if (controller.isStarted()) {
startedCommands.add(controller);
}
}
return startedCommands;
}
public Set getCommandsOfType(String type) {
Set commandsOfType = new HashSet();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getControllers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
if (descriptor.getType().equals(type) && descriptor.isCommand() && descriptor.isEnabled()) {
commandsOfType.add(descriptor.getName());
}
}
return commandsOfType;
}
public abstract Controller getController(String controllerName);
public abstract Controller cloneController(String controllerName) throws ControllerNotFoundException;
public abstract void removeController(String controllerName);
public abstract String getFamily(String controllerName);
public abstract String getSubfamily(String controllerName);
public String getFamily(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
return descriptor.getFamily();
}
return null;
}
public void addConfigurationChangeListener(ServerConfigurationChangeListener listener) {
DataNotificationClient.getInstance().addConfigurationChangeListener(listener);
public String getSubfamily(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
return descriptor.getSubfamily();
}
return null;
}
public LinkedHashSet<String> getControllersOfTypeInDisplayOrder(String controllerType, boolean onlyVisibleOnes) {
if (onlyVisibleOnes) {
return visibleControllerNamesByType.get(controllerType);
}
return allControllerNamesByType.get(controllerType);
}
public abstract HashMap<String, LinkedHashMap<String, String>> getPropertiesForGeneric();
public abstract void updateDynamicProperties(Controller controller);
public void updateDynamicProperties(IServant servant) {
Controller controller = (Controller)servant;
ServantManagerAccessor.getInstance(serverId).updateDynamicProperties(controller.getId());
}
public void configurationChanged(int servantID, ClientEnableState enable) {
// the reload of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes
ServantManagerAccessor.getInstance(serverId).updateDynamicProperties(servantID);
}
public abstract void reloadControllers();
public void reloadControllers() {
// reset controller information
reset();
}
public abstract String getControllerNameWithRole(Controller controller, String role);
public String getControllerNameWithRole(IServant servant, String role) {
Controller controller = (Controller)servant;
return ServantManagerAccessor.getInstance(serverId).getControllerNameWithRole(controller.getId(), role);
}
}
......@@ -19,15 +19,25 @@
package fr.ill.ics.bridge;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import fr.ill.ics.nscclient.servant.CorbaDriverManager;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.servant.ClientServantDescriptor;
import fr.ill.ics.nscclient.servant.Driver;
public abstract class DriverManager {
public class DriverManager {
private String serverId;
private static DriverManager instance = null;
public static DriverManager getInstance() {
......@@ -35,7 +45,7 @@ public abstract class DriverManager {
}
public static void initInstance(String serverId) {
instance = new CorbaDriverManager(serverId);
instance = new DriverManager(serverId);
instance.init();
}
......@@ -43,21 +53,103 @@ public abstract class DriverManager {
instance = null;
}
protected abstract void init();
public DriverManager(String serverId) {
this.serverId = serverId;
}
public abstract String getType(String treeItemText);
protected void init() {
}
public abstract Map getInstalledDrivers();
public Driver getDriver(String driverName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getDriverDescriptor(driverName);
if (descriptor != null) {
Driver driver = ServantManagerAccessor.getInstance(serverId).getDriver(descriptor);
return driver;
}
return null;
}
public abstract void setPaused(boolean checked);
public String getType(String driverName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getDriverDescriptor(driverName);
if (descriptor != null) {
return descriptor.getType();
}
return null;
}
public abstract Set getStartedControllers();
public Map getInstalledDrivers() {
Map<String, Map<String, Map<String, String>>> installedDrivers = new TreeMap<String, Map<String, Map<String, String>>>();
public abstract Controller getDriver(String driverName);
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
public abstract Collection getControllersOfType(String controllerType);
if (descriptor.isEnabled() && descriptor.isRoot()) {
public abstract Long getChannel(String driverName);
public abstract void reconnectDriver(String driverName);
Map<String, Map<String, String>> children = getChildren(descriptor);
installedDrivers.put(descriptor.getName(), children);
}
}
return installedDrivers;
}
private Map getChildren(ClientServantDescriptor descriptor) {
Map<String, Map<String, String>> allChildren = new LinkedHashMap<String, Map<String, String>>();
List<String> children = ServantManagerAccessor.getInstance(serverId).getChildServants(descriptor.getId());
Iterator<String> it = children.iterator();
while (it.hasNext()) {
String childName = it.next();
ClientServantDescriptor childDescriptor = ServantDatabase.getInstance().getDriverDescriptor(childName);
if (childDescriptor.isVisible() && childDescriptor.isEnabled()) {
allChildren.put(childName, getChildren(childDescriptor));
}
}
return allChildren;
}
public Collection getControllersOfType(String driverType) {
return ServantDatabase.getInstance().getDriversOfType(driverType, false);
}
public Set getStartedControllers() {
Set startedCommands = new HashSet();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
Driver driver = getDriver(descriptor.getName());
if (driver.isStarted()) {
startedCommands.add(driver);
}
}
return startedCommands;
}
public void setPaused(boolean isPaused) {
ServantManagerAccessor.getInstance(serverId).pauseSpies(isPaused);
}
public Long getChannel(String driverName) {
Driver driver = getDriver(driverName);
if (driver != null) {
return getDriver(driverName).getChannel();
}
return null;
}
public void reconnectDriver(String driverName) {
Driver driver = getDriver(driverName);
if (driver != null) {
ServantManagerAccessor.getInstance(serverId).reconnectDriver(driver.getDatabaseId(), driver.getId());
}
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener;
import fr.ill.ics.bridge.listeners.ServerResetCommandListener;
public interface Controller {
public interface IServant {
public String getName();
public String getType();
......@@ -47,7 +47,7 @@ public interface Controller {
public void addServerResetCommandListener(ServerResetCommandListener listener);
public void removeServerResetCommandListener(ServerResetCommandListener listener);
public Controller getLinkedController();
public IServant getLinkedController();
public void updateDynamicProperties();
public int getDatabaseId();
......
......@@ -21,13 +21,13 @@ package fr.ill.ics.bridge.command;
import java.util.Map;
import java.util.Set;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.IServant;
import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener;
import fr.ill.ics.nscclient.command.ServerAtomicCommandBox;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
public class AtomicCommandWrapper extends CommandWrapper implements Controller {
public class AtomicCommandWrapper extends CommandWrapper implements IServant {
private ServerAtomicCommandBox serverAtomicCommandBox;
private int servantId;
......@@ -96,7 +96,7 @@ public class AtomicCommandWrapper extends CommandWrapper implements Controller {
// do nothing
}
public Controller getLinkedController() {
public IServant getLinkedController() {
return null;
}
......
......@@ -27,7 +27,7 @@ import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import fr.ill.ics.nscclient.dataprovider.DataAccessor.ClientCommandState;
import fr.ill.ics.nscclient.notification.DataNotificationClient;
import fr.ill.ics.nscclient.servant.CorbaServant.UnknownCommandException;
import fr.ill.ics.nscclient.servant.Servant.UnknownCommandException;
public class Command extends CommandAction implements ServerCommandStateChangeListener, ServerProgressChangeListener, ServerCommandRefusedListener {
......
......@@ -21,10 +21,10 @@ package fr.ill.ics.core.command;
import java.util.HashMap;
import java.util.Map;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.IServant;
import fr.ill.ics.bridge.command.AtomicCommandWrapper;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.servant.CorbaServant;
import fr.ill.ics.nscclient.servant.Servant;
import fr.ill.ics.util.exception.CommandNotFoundException;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
......@@ -44,7 +44,7 @@ public class CommandManager {
return instance;
}
public Command getCommand(Controller controller, String commandName, boolean createExceptionIfNotFound, PluginType pluginType) throws CommandNotFoundException {
public Command getCommand(IServant controller, String commandName, boolean createExceptionIfNotFound, PluginType pluginType) throws CommandNotFoundException {
// Create a new Map of commandName:Command instance if it doesn't exist for the abstract controller
if (controllerCommands == null) {
......@@ -57,8 +57,8 @@ public class CommandManager {
int servantId;
if (controller instanceof CorbaServant) {
servantId = ((CorbaServant)controller).getId();
if (controller instanceof Servant) {
servantId = ((Servant)controller).getId();
} else {
servantId = ((AtomicCommandWrapper)controller).getServantId();
}
......
......@@ -33,7 +33,7 @@ import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.IServant;
import fr.ill.ics.bridge.ControllerManager;
import fr.ill.ics.bridge.DriverManager;
import fr.ill.ics.bridge.ResourceManager;
......@@ -46,7 +46,7 @@ import fr.ill.ics.core.property.parser.descriptor.XMLPropertyDescriptor;
import fr.ill.ics.nscclient.dataprovider.PropertyDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
import fr.ill.ics.nscclient.servant.ClientServantDescriptor;
import fr.ill.ics.nscclient.servant.CorbaServant;
import fr.ill.ics.nscclient.servant.Servant;
import fr.ill.ics.nscclient.servant.DynamicPropertyDescriptor;
import fr.ill.ics.nscclient.servant.ResourceNotFoundException;
import fr.ill.ics.nscclient.servant.SpyPropertyDescriptor;
......@@ -126,10 +126,10 @@ public class PropertyManager {
boolean clientFilesExist = readPropertiesClientFilesFor(descriptor.getType());
if (clientFilesExist) {
Controller controller = DriverManager.getInstance().getDriver(descriptor.getName());
createPropertiesForController((CorbaServant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((CorbaServant)controller).getType())) {
createDynamicPropertiesForController((CorbaServant)controller);