Update for default configs

Update to allow for default config properties if some are not specified
with the start server and properties passed in.  Updated the tests to
match and also moved a few more things into the Constants.java file.
This commit is contained in:
swarwick
2015-03-14 16:37:41 +01:00
committed by andrea
parent 8aad95525c
commit 6cc5b0edb9
11 changed files with 61 additions and 71 deletions
@@ -22,7 +22,9 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.text.ParseException;
import java.util.Map.Entry;
import java.util.Properties;
import org.eclipse.moquette.commons.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,11 +44,24 @@ class ConfigurationParser {
private Properties m_properties = new Properties();
ConfigurationParser() {
createDefaults();
}
ConfigurationParser(Properties properties) {
createDefaults();
for (Entry<Object, Object> entrySet : m_properties.entrySet()) {
if (properties.containsKey(entrySet.getKey())) {
entrySet.setValue(properties.get(entrySet.getKey()));
}
}
}
private void createDefaults() {
m_properties.put("port", Integer.toString(Constants.PORT));
m_properties.put("host", Constants.HOST);
m_properties.put("websocket_port", Integer.toString(Constants.WEBSOCKET_PORT));
m_properties.put("password_file", "");
m_properties.put("persistent_store", System.getProperty("user.home") + File.separator + "moquette_store.mapdb");
m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH);
}
/**
@@ -19,6 +19,8 @@ import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.Properties;
import org.eclipse.moquette.commons.Constants;
import org.eclipse.moquette.spi.impl.SimpleMessaging;
import org.eclipse.moquette.server.netty.NettyAcceptor;
import org.slf4j.Logger;
@@ -33,6 +35,7 @@ public class Server {
private ServerAcceptor m_acceptor;
SimpleMessaging messaging;
Properties m_properties;
public static void main(String[] args) throws IOException {
final Server server = new Server();
@@ -68,26 +71,28 @@ public class Server {
} catch (ParseException pex) {
LOG.warn("An error occurred in parsing configuration, fallback on default configuration", pex);
}
Properties configProps = confParser.getProperties();
startServer(configProps);
m_properties = confParser.getProperties();
startServer(m_properties);
}
/**
* Starts the server with the given properties.
*
* Its need at least the following properties:
* Its suggested to at least have the following properties:
* <ul>
* <li>port</li>
* <li>password_file</li>
* </ul>
*/
public void startServer(Properties configProps) throws IOException {
LOG.info("Persistent store file: " + configProps.get("persistent_store"));
ConfigurationParser confParser = new ConfigurationParser(configProps);
m_properties = confParser.getProperties();
LOG.info("Persistent store file: " + m_properties.get(Constants.PERSISTENT_STORE_PROPERTY_NAME));
messaging = SimpleMessaging.getInstance();
messaging.init(configProps);
messaging.init(m_properties);
m_acceptor = new NettyAcceptor();
m_acceptor.initialize(messaging, configProps);
m_acceptor.initialize(messaging, m_properties);
}
public void stopServer() {
@@ -96,4 +101,8 @@ public class Server {
m_acceptor.close();
System.out.println("Server stopped");
}
public Properties getProperties() {
return m_properties;
}
}