Commit c68b059f authored by helene ortiz's avatar helene ortiz
Browse files

modifications to reduce client starting time

parent 5b97d1c9
......@@ -26,6 +26,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -202,11 +203,11 @@ public class PropertyFactory {
* @param propertyDescriptors a map containing controller property names as keys and PropertyDescriptor instances as values
* @return a map containing controller property names as keys and Property instances as values
*/
public Map createPropertiesForController(int databaseId, int servantId, Map propertyDescriptors) {
Map properties = new LinkedHashMap();
Iterator it = propertyDescriptors.keySet().iterator();
public Map createPropertiesForController(int databaseId, int servantId, LinkedHashMap<String, XMLPropertyDescriptor> propertyDescriptors) {
Map<String, Property> properties = new LinkedHashMap<String, Property>();
Iterator<Entry<String, XMLPropertyDescriptor>> it = propertyDescriptors.entrySet().iterator();
while (it.hasNext()) {
XMLPropertyDescriptor propertyDescriptor = (XMLPropertyDescriptor)propertyDescriptors.get(it.next());
XMLPropertyDescriptor propertyDescriptor = propertyDescriptors.get(it.next().getKey());
int propertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, propertyDescriptor.getPropertyName());
if (propertyId > 0) {
properties.put(propertyDescriptor.getPropertyName(), createProperty(databaseId, propertyId, propertyDescriptor, false));
......@@ -274,12 +275,12 @@ public class PropertyFactory {
} else {
hasNext = false;
/*
if (index == 0) {
System.err.println("Dynamic property " + genericPropertyName + " from " + servantId + " not found in server");
} else {
//System.out.println("Dynamic property " + indexPropertyName + " added from " + servantId);
}
}*/
}
}
......
......@@ -92,6 +92,8 @@ public class PropertyManager {
return this.toString().equals(content);
}
}
private PropertyParser propertyParser;
private Map<Integer, Map<String, Property>> propertyMap = new HashMap<Integer, Map<String, Property>>(NB_CONTROLLERS); // KEY=Servant id VALUE=Map(KEY=propertyName VALUE=Property instance)
private Map<CommandBoxKey, Map<String, Property>> commandBoxPropertyMap = new HashMap<CommandBoxKey, Map<String, Property>>(NB_CONTROLLERS); // KEY=CommandBox id VALUE=Map(KEY=propertyName VALUE=Property instance)
......@@ -127,68 +129,15 @@ public class PropertyManager {
public void init() {
clientFilesFoundPerControllerType = new HashMap<String, Boolean>();
sizePropertyNames = new HashMap<String, String>();
propertyParser = new PropertyParser();
createAllProperties();
}
/**
* Initialize the property descriptors Map
* Reads all the properties files and builds a map of controllers and property descriptors
*/
private void readPropertyFiles() {
// initialise all controller properties
// Load the xml files for each controller...
Set subDirectories = FileHelper.getSubDirectories(ConfigManager.CONTROLLERS_DIRECTORY);
if (subDirectories != null && !subDirectories.isEmpty()) {
PropertyParser parser = new PropertyParser();
Iterator<String> it = subDirectories.iterator();
while (it.hasNext()) {
String directoryName = it.next();
String[] files = FileHelper.getFilesListByExtension(ConfigManager.CONTROLLERS_DIRECTORY + directoryName + ConfigManager.FILE_SEPARATOR, "Properties.xml", true, true);//changed
if (files.length == 0) {
// System.out.println("Properties file not found in directory " + ConfigManager.CONTROLLERS_DIRECTORY + directoryName);
} else {
for (int i = 0; i < files.length; i++) {
// We may have more than one "Properties.xml" file (see acquisition controller for example)
parser.parseXmlFile(files[i]);
LinkedHashMap<String, XMLPropertyDescriptor> propertiesFromFile = new LinkedHashMap<String, XMLPropertyDescriptor>(parser.getProperties().size());
propertiesFromFile.putAll(parser.getProperties());
propertiesByControllerType.put(parser.getControllerType(), propertiesFromFile);
if (!parser.getDynamicProperties().isEmpty()) {
if (dynamicPropertiesByControllerType == null) {
dynamicPropertiesByControllerType = new HashMap(NB_CONTROLLER_TYPES);
}
Map<String, XMLDynamicPropertyDescriptor> dynamicPropertiesFromFile = new LinkedHashMap(parser.getDynamicProperties().size());
dynamicPropertiesFromFile.putAll(parser.getDynamicProperties());
dynamicPropertiesByControllerType.put(parser.getControllerType(), dynamicPropertiesFromFile);
}
Map propertiesTypesFromFile = new LinkedHashMap(parser.getProperties().size());
propertiesTypesFromFile.putAll(parser.getPropertyTypes());
}
}
}
parser = null;
} else {
System.out.println("Directory " + ConfigManager.CONTROLLERS_DIRECTORY + " contains no directory");
}
}
/**
* Get all controllers installed in the server. For each one create all necessary properties
*/
private void createAllProperties() {
// Drivers
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
......@@ -235,28 +184,26 @@ public class PropertyManager {
clientFilesFoundPerControllerType.put(controllerType, false);
return false;
}
for (int i = 0; i < files.length; i++) {
for (int i = 0; i < files.length; i++) {
// We may have more than one "Properties.xml" file (see acquisition controller for example)
propertyParser.parseXmlFile(files[i]);
LinkedHashMap<String, XMLPropertyDescriptor> propertiesFromFile = new LinkedHashMap<String, XMLPropertyDescriptor>(propertyParser.getProperties().size());
PropertyParser parser = new PropertyParser();
parser.parseXmlFile(files[i]);
LinkedHashMap<String, XMLPropertyDescriptor> propertiesFromFile = new LinkedHashMap<String, XMLPropertyDescriptor>(parser.getProperties().size());
propertiesFromFile.putAll(propertyParser.getProperties());
propertiesFromFile.putAll(parser.getProperties());
propertiesByControllerType.put(propertyParser.getControllerType(), propertiesFromFile);
propertiesByControllerType.put(parser.getControllerType(), propertiesFromFile);
if (!parser.getDynamicProperties().isEmpty()) {
if (!propertyParser.getDynamicProperties().isEmpty()) {
if (dynamicPropertiesByControllerType == null) {
dynamicPropertiesByControllerType = new HashMap(NB_CONTROLLER_TYPES);
}
Map<String, XMLDynamicPropertyDescriptor> dynamicPropertiesFromFile = new LinkedHashMap(parser.getDynamicProperties().size());
dynamicPropertiesFromFile.putAll(parser.getDynamicProperties());
dynamicPropertiesByControllerType.put(parser.getControllerType(), dynamicPropertiesFromFile);
Map<String, XMLDynamicPropertyDescriptor> dynamicPropertiesFromFile = new LinkedHashMap(propertyParser.getDynamicProperties().size());
dynamicPropertiesFromFile.putAll(propertyParser.getDynamicProperties());
dynamicPropertiesByControllerType.put(propertyParser.getControllerType(), dynamicPropertiesFromFile);
}
Map propertiesTypesFromFile = new LinkedHashMap(parser.getProperties().size());
propertiesTypesFromFile.putAll(parser.getPropertyTypes());
Map propertiesTypesFromFile = new LinkedHashMap(propertyParser.getProperties().size());
propertiesTypesFromFile.putAll(propertyParser.getPropertyTypes());
}
ConfigManager.getInstance().initControllerProperties(controllerType);
......@@ -401,21 +348,18 @@ public class PropertyManager {
// create dynamically a list of properties and create a new xml file
Map propertyNamesAndTypes = servant.getPropertyNamesAndTypes();
PropertyParser parser = new PropertyParser();
String propertiesFile = parser.createPropertyFile(servant.getType(), propertyNamesAndTypes);
String propertiesFile = propertyParser.createPropertyFile(servant.getType(), propertyNamesAndTypes);
if (propertiesFile != null) {
parser.parseXmlFile(propertiesFile);
propertyParser.parseXmlFile(propertiesFile);
LinkedHashMap<String, XMLPropertyDescriptor> propertiesFromFile = new LinkedHashMap<String, XMLPropertyDescriptor>(parser.getProperties().size());
propertiesFromFile.putAll(parser.getProperties());
propertiesByControllerType.put(parser.getControllerType(), propertiesFromFile);
LinkedHashMap<String, XMLPropertyDescriptor> propertiesFromFile = new LinkedHashMap<String, XMLPropertyDescriptor>(propertyParser.getProperties().size());
propertiesFromFile.putAll(propertyParser.getProperties());
propertiesByControllerType.put(propertyParser.getControllerType(), propertiesFromFile);
Map propertiesTypesFromFile = new LinkedHashMap<String, String>(parser.getPropertyTypes().size());
propertiesTypesFromFile.putAll(parser.getPropertyTypes());
Map propertiesTypesFromFile = new LinkedHashMap<String, String>(propertyParser.getPropertyTypes().size());
propertiesTypesFromFile.putAll(propertyParser.getPropertyTypes());
}
parser = null;
}
......@@ -662,12 +606,12 @@ public class PropertyManager {
} else {
hasNext = false;
/*
if (index == 0) {
System.err.println("Dynamic property " + genericPropertyName + " from " + controllerName + " not found in server");
} else {
//System.out.println("Dynamic property " + indexGenericPropertyName + " added from " + controllerName);
}
}*/
}
}
}
......@@ -870,5 +814,4 @@ public class PropertyManager {
public void removePropertyDescriptor(String controllerType) {
propertiesByControllerType.remove(controllerType);
}
}
......@@ -198,7 +198,7 @@ public class PropertyDatabase {
* @return
*/
public int getPropertyIdForServant(int servantId, String propertyName) {
Set propertyIdsForServant = propertiesByServant.get(servantId);
Set<Integer> propertyIdsForServant = propertiesByServant.get(servantId);
if (propertyIdsForServant != null) {
Iterator<Integer> it = propertyIdsForServant.iterator();
while (it.hasNext()) {
......@@ -211,7 +211,7 @@ public class PropertyDatabase {
// trying with dynamic property
if (propertyName.indexOf(".") != -1) {
String parentPropertyName = propertyName.substring(0, propertyName.indexOf("."));
int index = Integer.parseInt(propertyName.substring(propertyName.indexOf(".")+1));
String indexString = propertyName.substring(propertyName.indexOf(".")+1);
Set<DynamicPropertyDescriptor> dynamicPropertyIdsForServant = dynamicPropertiesByServant.get(servantId);
if (dynamicPropertyIdsForServant != null) {
......@@ -220,6 +220,7 @@ public class PropertyDatabase {
DynamicPropertyDescriptor descriptor = it.next();
if (descriptor.getName().equals(parentPropertyName)) {
List<Integer> ids = descriptor.getIds();
int index = Integer.valueOf(indexString);
if (index < ids.size()) {
return ids.get(index);
}
......
......@@ -185,13 +185,13 @@ public class CorbaServantManager {
public void loadWholeConfiguration() throws LoadConfigurationFailure {
System.out.println("getting whole configuration");
//System.out.println("getting whole configuration");
long begin = new Date().getTime();
byte[] pbResult = servantManager.getWholeConfiguration(DATABASE_ID);
long end = new Date().getTime();
System.out.println("got whole configuration PB in " + (end - begin) + "ms");
//System.out.println("got whole configuration PB in " + (end - begin) + "ms");
begin = new Date().getTime();
......@@ -204,13 +204,13 @@ public class CorbaServantManager {
}
end = new Date().getTime();
System.out.println("servant data parsed into " + (end - begin) + "ms");
//System.out.println("servant data parsed into " + (end - begin) + "ms");
begin = new Date().getTime();
initAllMaps(servantData);
end = new Date().getTime();
System.out.println("loaded whole configuration PB in " + (end - begin) + "ms");
//System.out.println("loaded whole configuration PB in " + (end - begin) + "ms");
}
private CorbaServant initAllMaps(ServantDataConfiguration.ServantDescriptor pbServant, boolean driver) {
......
......@@ -247,7 +247,7 @@ public class ConfigManager {
* @return the boolean value that match with the propertyName in the config file
*/
public synchronized boolean getBoolean(String propertyName) {
return Boolean.valueOf(this.properties.getProperty(propertyName));
return Boolean.valueOf(properties.getProperty(propertyName));
}
......@@ -257,7 +257,7 @@ public class ConfigManager {
* @return the integer value that match with the propertyName in the config file
*/
public synchronized int getInt(String propertyName) {
return new Integer(this.properties.getProperty(propertyName)).intValue();
return new Integer(properties.getProperty(propertyName)).intValue();
}
......@@ -267,10 +267,14 @@ public class ConfigManager {
* @return the String value that match with the propertyName in the config file
*/
public synchronized String getString(String propertyName) {
if (this.properties.getProperty(propertyName) == null) {
if (properties.getProperty(propertyName) == null) {
return propertyName;
}
return this.properties.getProperty(propertyName);
String propertyValue = properties.getProperty(propertyName);
if (propertyValue.contains("~")) {
replaceSpecialCharacters(propertyName, propertyValue);
}
return properties.getProperty(propertyName);
}
/**
......@@ -279,21 +283,61 @@ public class ConfigManager {
* @return the String value that match with the propertyName in the config file
*/
public synchronized String getStringOrNothingAtAll(String propertyName) {
if (this.properties.getProperty(propertyName) == null) {
if (properties.getProperty(propertyName) == null) {
return null;
}
return this.properties.getProperty(propertyName);
String propertyValue = properties.getProperty(propertyName);
if (propertyValue.contains("~")) {
replaceSpecialCharacters(propertyName, propertyValue);
}
return properties.getProperty(propertyName);
}
public void replaceSpecialCharacters(String propertyName, String propertyValue) {
propertyValue = propertyValue.replace("~alpha", SpecialCharacter.alpha);
propertyValue = propertyValue.replace("~beta", SpecialCharacter.beta);
propertyValue = propertyValue.replace("~gamma", SpecialCharacter.gamma);
propertyValue = propertyValue.replace("~delta", SpecialCharacter.delta);
propertyValue = propertyValue.replace("~epsilon", SpecialCharacter.epsilon);
propertyValue = propertyValue.replace("~zeta", SpecialCharacter.zeta);
propertyValue = propertyValue.replace("~eta", SpecialCharacter.eta);
propertyValue = propertyValue.replace("~theta", SpecialCharacter.theta);
propertyValue = propertyValue.replace("~iota", SpecialCharacter.iota);
propertyValue = propertyValue.replace("~kappa", SpecialCharacter.kappa);
propertyValue = propertyValue.replace("~lambda", SpecialCharacter.lambda);
propertyValue = propertyValue.replace("~mu", SpecialCharacter.mu);
propertyValue = propertyValue.replace("~xi", SpecialCharacter.xi);
propertyValue = propertyValue.replace("~omicron", SpecialCharacter.omicron);
propertyValue = propertyValue.replace("~pi", SpecialCharacter.pi);
propertyValue = propertyValue.replace("~rho", SpecialCharacter.rho);
propertyValue = propertyValue.replace("~sigma", SpecialCharacter.sigma);
propertyValue = propertyValue.replace("~tau", SpecialCharacter.tau);
propertyValue = propertyValue.replace("~upsilon", SpecialCharacter.upsilon);
propertyValue = propertyValue.replace("~phi", SpecialCharacter.phi);
propertyValue = propertyValue.replace("~chi", SpecialCharacter.chi);
propertyValue = propertyValue.replace("~psi", SpecialCharacter.psi);
propertyValue = propertyValue.replace("~omega", SpecialCharacter.omega);
propertyValue = propertyValue.replace("~Delta", SpecialCharacter.Delta);
propertyValue = propertyValue.replace("~Omega", SpecialCharacter.Omega);
propertyValue = propertyValue.replace("~degree", SpecialCharacter.degree);
propertyValue = propertyValue.replace("~angstrom", SpecialCharacter.angstrom);
propertyValue = propertyValue.replace("~superscriptminus", SpecialCharacter.superscriptminus);
propertyValue = propertyValue.replace("~superscriptone", SpecialCharacter.superscriptone);
propertyValue = propertyValue.replace("~cross", SpecialCharacter.cross);
properties.put(propertyName, propertyValue);
}
/**
* Replace all special characters coded in properties with unicode character
*
*/
*//*
public void replaceSpecialCharacters() {
String key;
String propertyValue;
Iterator it = properties.keySet().iterator();
Iterator it = properties.entrySet().iterator();
while (it.hasNext()) {
key = (String)it.next();
propertyValue = (String)properties.get(key);
......@@ -333,7 +377,7 @@ public class ConfigManager {
properties.put(key, propertyValue);
}
}
*/
public void setProperty(String propertyKey, String propertyValue) {
properties.setProperty(propertyKey, propertyValue);
}
......
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