From 4029ddd2b1fa69df1d42bc6322e19da1dbad34f0 Mon Sep 17 00:00:00 2001 From: andsel Date: Sat, 31 Dec 2016 19:21:12 +0100 Subject: [PATCH] Removed ClasspathConfig to use the ClasspathResourceLoader and basic ResourceLoaderConfig Removed FilesystemConfig to use the FileResourceLoader and basic ResourceLoaderConfig --- .../main/java/io/moquette/server/Server.java | 15 ++++--- .../server/config/ClasspathConfig.java | 29 -------------- .../server/config/FilesystemConfig.java | 40 ------------------- ....java => ClasspathResourceLoaderTest.java} | 5 ++- .../testembedded/EmbeddedLauncher.java | 6 +-- 5 files changed, 16 insertions(+), 79 deletions(-) delete mode 100644 broker/src/main/java/io/moquette/server/config/ClasspathConfig.java delete mode 100644 broker/src/main/java/io/moquette/server/config/FilesystemConfig.java rename broker/src/test/java/io/moquette/server/config/{ClasspathConfigTest.java => ClasspathResourceLoaderTest.java} (71%) diff --git a/broker/src/main/java/io/moquette/server/Server.java b/broker/src/main/java/io/moquette/server/Server.java index d9bb8c73..1bd63904 100644 --- a/broker/src/main/java/io/moquette/server/Server.java +++ b/broker/src/main/java/io/moquette/server/Server.java @@ -27,10 +27,8 @@ import io.moquette.interception.HazelcastInterceptHandler; import io.moquette.interception.HazelcastMsg; import io.moquette.interception.InterceptHandler; import io.moquette.parser.proto.messages.PublishMessage; -import io.moquette.server.config.MemoryConfig; +import io.moquette.server.config.*; import io.moquette.spi.impl.ProtocolProcessorBootstrapper; -import io.moquette.server.config.FilesystemConfig; -import io.moquette.server.config.IConfig; import io.moquette.server.netty.NettyAcceptor; import io.moquette.spi.impl.ProtocolProcessor; import io.moquette.spi.impl.subscriptions.Subscription; @@ -85,16 +83,23 @@ public class Server { * located at m_config/moquette.conf */ public void startServer() throws IOException { - final IConfig config = new FilesystemConfig(); + IResourceLoader filesystemLoader = new FileResourceLoader(defaultConfigFile()); + final IConfig config = new ResourceLoaderConfig(filesystemLoader); startServer(config); } + private static File defaultConfigFile() { + String configPath = System.getProperty("moquette.path", null); + return new File(configPath, IConfig.DEFAULT_CONFIG); + } + /** * Starts Moquette bringing the configuration from the given file */ public void startServer(File configFile) throws IOException { LOG.info("Using m_config file: " + configFile.getAbsolutePath()); - final IConfig config = new FilesystemConfig(configFile); + IResourceLoader filesystemLoader = new FileResourceLoader(configFile); + final IConfig config = new ResourceLoaderConfig(filesystemLoader); startServer(config); } diff --git a/broker/src/main/java/io/moquette/server/config/ClasspathConfig.java b/broker/src/main/java/io/moquette/server/config/ClasspathConfig.java deleted file mode 100644 index 53015220..00000000 --- a/broker/src/main/java/io/moquette/server/config/ClasspathConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2012-2015 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.moquette.server.config; - -/** - * Configuration that loads file from the classpath - * - * @author andrea - */ -public class ClasspathConfig extends ResourceLoaderConfig { - - public ClasspathConfig() { - super(new ClasspathResourceLoader()); - } - -} diff --git a/broker/src/main/java/io/moquette/server/config/FilesystemConfig.java b/broker/src/main/java/io/moquette/server/config/FilesystemConfig.java deleted file mode 100644 index dd8d7547..00000000 --- a/broker/src/main/java/io/moquette/server/config/FilesystemConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2012-2015 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.moquette.server.config; - -import java.io.File; - -/** - * Configuration that loads file from the file system - * - * @author andrea - */ -public class FilesystemConfig extends ResourceLoaderConfig { - - public FilesystemConfig(File file) { - super(new FileResourceLoader(file)); - } - - public FilesystemConfig() { - this(defaultConfigFile()); - } - - private static File defaultConfigFile() { - String configPath = System.getProperty("moquette.path", null); - return new File(configPath, IConfig.DEFAULT_CONFIG); - } - -} diff --git a/broker/src/test/java/io/moquette/server/config/ClasspathConfigTest.java b/broker/src/test/java/io/moquette/server/config/ClasspathResourceLoaderTest.java similarity index 71% rename from broker/src/test/java/io/moquette/server/config/ClasspathConfigTest.java rename to broker/src/test/java/io/moquette/server/config/ClasspathResourceLoaderTest.java index 3f3cb66a..1c8985bb 100644 --- a/broker/src/test/java/io/moquette/server/config/ClasspathConfigTest.java +++ b/broker/src/test/java/io/moquette/server/config/ClasspathResourceLoaderTest.java @@ -6,11 +6,12 @@ import org.junit.Test; import io.moquette.BrokerConstants; -public class ClasspathConfigTest { +public class ClasspathResourceLoaderTest { @Test public void testSetProperties() { - final IConfig classPathConfig = new ClasspathConfig(); + IResourceLoader classpathLoader = new ClasspathResourceLoader(); + final IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader); assertEquals(""+BrokerConstants.PORT,classPathConfig.getProperty(BrokerConstants.PORT_PROPERTY_NAME)); classPathConfig.setProperty(BrokerConstants.PORT_PROPERTY_NAME, "9999"); assertEquals("9999",classPathConfig.getProperty(BrokerConstants.PORT_PROPERTY_NAME)); diff --git a/embedding_moquette/src/main/java/io/moquette/testembedded/EmbeddedLauncher.java b/embedding_moquette/src/main/java/io/moquette/testembedded/EmbeddedLauncher.java index 91446d35..ebfbd093 100644 --- a/embedding_moquette/src/main/java/io/moquette/testembedded/EmbeddedLauncher.java +++ b/embedding_moquette/src/main/java/io/moquette/testembedded/EmbeddedLauncher.java @@ -21,8 +21,7 @@ import io.moquette.interception.messages.*; import io.moquette.parser.proto.messages.AbstractMessage; import io.moquette.parser.proto.messages.PublishMessage; import io.moquette.server.Server; -import io.moquette.server.config.IConfig; -import io.moquette.server.config.ClasspathConfig; +import io.moquette.server.config.*; import java.io.IOException; import java.nio.ByteBuffer; @@ -40,7 +39,8 @@ import static java.util.Arrays.asList; } public static void main(String[] args) throws InterruptedException, IOException { - final IConfig classPathConfig = new ClasspathConfig(); + IResourceLoader classpathLoader = new ClasspathResourceLoader(); + final IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader); final Server mqttBroker = new Server(); List userHandlers = asList(new PublisherListener());