Removed ClasspathConfig to use the ClasspathResourceLoader and basic ResourceLoaderConfig
Removed FilesystemConfig to use the FileResourceLoader and basic ResourceLoaderConfig
This commit is contained in:
@@ -27,10 +27,8 @@ import io.moquette.interception.HazelcastInterceptHandler;
|
|||||||
import io.moquette.interception.HazelcastMsg;
|
import io.moquette.interception.HazelcastMsg;
|
||||||
import io.moquette.interception.InterceptHandler;
|
import io.moquette.interception.InterceptHandler;
|
||||||
import io.moquette.parser.proto.messages.PublishMessage;
|
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.spi.impl.ProtocolProcessorBootstrapper;
|
||||||
import io.moquette.server.config.FilesystemConfig;
|
|
||||||
import io.moquette.server.config.IConfig;
|
|
||||||
import io.moquette.server.netty.NettyAcceptor;
|
import io.moquette.server.netty.NettyAcceptor;
|
||||||
import io.moquette.spi.impl.ProtocolProcessor;
|
import io.moquette.spi.impl.ProtocolProcessor;
|
||||||
import io.moquette.spi.impl.subscriptions.Subscription;
|
import io.moquette.spi.impl.subscriptions.Subscription;
|
||||||
@@ -85,16 +83,23 @@ public class Server {
|
|||||||
* located at m_config/moquette.conf
|
* located at m_config/moquette.conf
|
||||||
*/
|
*/
|
||||||
public void startServer() throws IOException {
|
public void startServer() throws IOException {
|
||||||
final IConfig config = new FilesystemConfig();
|
IResourceLoader filesystemLoader = new FileResourceLoader(defaultConfigFile());
|
||||||
|
final IConfig config = new ResourceLoaderConfig(filesystemLoader);
|
||||||
startServer(config);
|
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
|
* Starts Moquette bringing the configuration from the given file
|
||||||
*/
|
*/
|
||||||
public void startServer(File configFile) throws IOException {
|
public void startServer(File configFile) throws IOException {
|
||||||
LOG.info("Using m_config file: " + configFile.getAbsolutePath());
|
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);
|
startServer(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+3
-2
@@ -6,11 +6,12 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import io.moquette.BrokerConstants;
|
import io.moquette.BrokerConstants;
|
||||||
|
|
||||||
public class ClasspathConfigTest {
|
public class ClasspathResourceLoaderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetProperties() {
|
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));
|
assertEquals(""+BrokerConstants.PORT,classPathConfig.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
|
||||||
classPathConfig.setProperty(BrokerConstants.PORT_PROPERTY_NAME, "9999");
|
classPathConfig.setProperty(BrokerConstants.PORT_PROPERTY_NAME, "9999");
|
||||||
assertEquals("9999",classPathConfig.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
|
assertEquals("9999",classPathConfig.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
|
||||||
@@ -21,8 +21,7 @@ import io.moquette.interception.messages.*;
|
|||||||
import io.moquette.parser.proto.messages.AbstractMessage;
|
import io.moquette.parser.proto.messages.AbstractMessage;
|
||||||
import io.moquette.parser.proto.messages.PublishMessage;
|
import io.moquette.parser.proto.messages.PublishMessage;
|
||||||
import io.moquette.server.Server;
|
import io.moquette.server.Server;
|
||||||
import io.moquette.server.config.IConfig;
|
import io.moquette.server.config.*;
|
||||||
import io.moquette.server.config.ClasspathConfig;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -40,7 +39,8 @@ import static java.util.Arrays.asList;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException, IOException {
|
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();
|
final Server mqttBroker = new Server();
|
||||||
List<? extends InterceptHandler> userHandlers = asList(new PublisherListener());
|
List<? extends InterceptHandler> userHandlers = asList(new PublisherListener());
|
||||||
|
|||||||
Reference in New Issue
Block a user