Minor change, moved const definition from Constants inside parser-commons to BrokerConstants inside broker project

This commit is contained in:
andsel
2015-12-08 14:04:35 +01:00
parent f41f7dafb9
commit 8c88567c78
16 changed files with 113 additions and 91 deletions
@@ -0,0 +1,44 @@
/*
* 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;
import java.io.File;
/**
* Created by andrea on 08/12/15.
*/
public class BrokerConstants {
public static final String PERSISTENT_STORE_PROPERTY_NAME = "persistent_store";
public static final String AUTOSAVE_INTERVAL_PROPERTY_NAME = "autosave_interval";
public static final String PASSWORD_FILE_PROPERTY_NAME = "password_file";
public static final String PORT_PROPERTY_NAME = "port";
public static final String HOST_PROPERTY_NAME = "host";
public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb";
public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.dir") + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
public static final String WEB_SOCKET_PORT_PROPERTY_NAME = "websocket_port";
public static final String WSS_PORT_PROPERTY_NAME = "secure_websocket_port";
public static final String SSL_PORT_PROPERTY_NAME = "ssl_port";
public static final String JKS_PATH_PROPERTY_NAME = "jks_path";
public static final String KEY_STORE_PASSWORD_PROPERTY_NAME = "key_store_password";
public static final String KEY_MANAGER_PASSWORD_PROPERTY_NAME = "key_manager_password";
public static final String ALLOW_ANONYMOUS_PROPERTY_NAME = "allow_anonymous";
public static final String ACL_FILE_PROPERTY_NAME = "acl_file";
public static final String AUTHORIZATOR_CLASS_NAME = "authorizator_class";
public static final String AUTHENTICATOR_CLASS_NAME = "authenticator_class";
public static final int PORT = 1883;
public static final int WEBSOCKET_PORT = 8080;
public static final String HOST = "0.0.0.0";
}
@@ -15,6 +15,7 @@
*/
package io.moquette.server;
import io.moquette.BrokerConstants;
import io.moquette.interception.InterceptHandler;
import io.moquette.server.config.MemoryConfig;
import io.moquette.spi.impl.SimpleMessaging;
@@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
@@ -106,7 +106,7 @@ public class Server {
if (handlerProp != null) {
config.setProperty("intercept.handler", handlerProp);
}
LOG.info("Persistent store file: " + config.getProperty(io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME));
LOG.info("Persistent store file: " + config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME));
final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers);
m_acceptor = new NettyAcceptor();
@@ -15,7 +15,7 @@
*/
package io.moquette.server.config;
import io.moquette.commons.Constants;
import io.moquette.BrokerConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,14 +42,14 @@ class ConfigurationParser {
}
private void createDefaults() {
m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT));
m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST);
m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT));
m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH);
m_properties.put(Constants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(Constants.AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(Constants.AUTHORIZATOR_CLASS_NAME, "");
m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
}
/**
@@ -15,7 +15,7 @@
*/
package io.moquette.server.config;
import io.moquette.commons.Constants;
import io.moquette.BrokerConstants;
import java.util.Map;
import java.util.Properties;
@@ -37,14 +37,14 @@ public class MemoryConfig implements IConfig {
}
private void createDefaults() {
m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT));
m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST);
m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT));
m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH);
m_properties.put(Constants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(Constants.AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(Constants.AUTHORIZATOR_CLASS_NAME, "");
m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
}
@Override
@@ -15,6 +15,7 @@
*/
package io.moquette.server.netty;
import io.moquette.BrokerConstants;
import io.moquette.commons.Constants;
import io.moquette.parser.netty.MQTTDecoder;
import io.moquette.server.config.IConfig;
@@ -100,8 +101,8 @@ public class NettyAcceptor implements ServerAcceptor {
initializePlainTCPTransport(handler, props);
initializeWebSocketTransport(handler, props);
String sslTcpPortProp = props.getProperty(Constants.SSL_PORT_PROPERTY_NAME);
String wssPortProp = props.getProperty(Constants.WSS_PORT_PROPERTY_NAME);
String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
String wssPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME);
if (sslTcpPortProp != null || wssPortProp != null) {
SslHandlerFactory sslHandlerFactory = initSSLHandlerFactory(props);
if (!sslHandlerFactory.canCreate()) {
@@ -145,8 +146,8 @@ public class NettyAcceptor implements ServerAcceptor {
private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler();
String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
int port = Integer.parseInt(props.getProperty(Constants.PORT_PROPERTY_NAME));
String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
int port = Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
initFactory(host, port, new PipelineInitializer() {
@Override
void init(ChannelPipeline pipeline) {
@@ -163,7 +164,7 @@ public class NettyAcceptor implements ServerAcceptor {
}
private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
String webSocketPortProp = props.getProperty(Constants.WEB_SOCKET_PORT_PROPERTY_NAME);
String webSocketPortProp = props.getProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME);
if (webSocketPortProp == null) {
//Do nothing no WebSocket configured
LOG.info("WebSocket is disabled");
@@ -173,7 +174,7 @@ public class NettyAcceptor implements ServerAcceptor {
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler();
String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
initFactory(host, port, new PipelineInitializer() {
@Override
void init(ChannelPipeline pipeline) {
@@ -195,7 +196,7 @@ public class NettyAcceptor implements ServerAcceptor {
}
private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props, final SslHandlerFactory sslHandlerFactory) throws IOException {
String sslPortProp = props.getProperty(Constants.SSL_PORT_PROPERTY_NAME);
String sslPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
if (sslPortProp == null) {
//Do nothing no SSL configured
LOG.info("SSL is disabled");
@@ -206,7 +207,7 @@ public class NettyAcceptor implements ServerAcceptor {
LOG.info("Starting SSL on port {}", sslPort);
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler();
String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
initFactory(host, sslPort, new PipelineInitializer() {
@Override
void init(ChannelPipeline pipeline) throws Exception {
@@ -224,7 +225,7 @@ public class NettyAcceptor implements ServerAcceptor {
}
private void initializeWSSTransport(final NettyMQTTHandler handler, IConfig props, final SslHandlerFactory sslHandlerFactory) throws IOException {
String sslPortProp = props.getProperty(Constants.WSS_PORT_PROPERTY_NAME);
String sslPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME);
if (sslPortProp == null) {
//Do nothing no SSL configured
LOG.info("SSL is disabled");
@@ -232,7 +233,7 @@ public class NettyAcceptor implements ServerAcceptor {
}
int sslPort = Integer.parseInt(sslPortProp);
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler();
String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
initFactory(host, sslPort, new PipelineInitializer() {
@Override
void init(ChannelPipeline pipeline) throws Exception {
@@ -301,7 +302,7 @@ public class NettyAcceptor implements ServerAcceptor {
return this.sslContext != null;
}
private SSLContext initSSLContext(IConfig props) {
final String jksPath = props.getProperty(Constants.JKS_PATH_PROPERTY_NAME);
final String jksPath = props.getProperty(BrokerConstants.JKS_PATH_PROPERTY_NAME);
LOG.info("Starting SSL using keystore at {}", jksPath);
if (jksPath == null || jksPath.isEmpty()) {
//key_store_password or key_manager_password are empty
@@ -311,8 +312,8 @@ public class NettyAcceptor implements ServerAcceptor {
//if we have the port also the jks then keyStorePassword and keyManagerPassword
//has to be defined
final String keyStorePassword = props.getProperty(Constants.KEY_STORE_PASSWORD_PROPERTY_NAME);
final String keyManagerPassword = props.getProperty(Constants.KEY_MANAGER_PASSWORD_PROPERTY_NAME);
final String keyStorePassword = props.getProperty(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME);
final String keyManagerPassword = props.getProperty(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME);
if (keyStorePassword == null || keyStorePassword.isEmpty()) {
//key_store_password or key_manager_password are empty
LOG.warn("You have configured the SSL port but not the key_store_password, SSL not started");
@@ -15,15 +15,14 @@
*/
package io.moquette.spi.impl;
import io.moquette.BrokerConstants;
import io.moquette.spi.IMessagesStore;
import io.moquette.commons.Constants;
import io.moquette.interception.InterceptHandler;
import io.moquette.server.config.IConfig;
import io.moquette.spi.ISessionsStore;
import io.moquette.spi.impl.security.*;
import io.moquette.spi.impl.subscriptions.SubscriptionsStore;
import io.moquette.spi.persistence.MapDBPersistentStore;
import static io.moquette.commons.Constants.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,7 +88,7 @@ public class SimpleMessaging {
subscriptions.init(sessionsStore);
String configPath = System.getProperty("moquette.path", null);
String authenticatorClassName = props.getProperty(Constants.AUTHENTICATOR_CLASS_NAME, "");
String authenticatorClassName = props.getProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
IAuthenticator authenticator = null;
if (!authenticatorClassName.isEmpty()) {
@@ -98,7 +97,7 @@ public class SimpleMessaging {
}
if (authenticator == null) {
String passwdPath = props.getProperty(PASSWORD_FILE_PROPERTY_NAME, "");
String passwdPath = props.getProperty(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
if (passwdPath.isEmpty()) {
authenticator = new AcceptAllAuthenticator();
} else {
@@ -107,14 +106,14 @@ public class SimpleMessaging {
}
IAuthorizator authorizator = null;
String authorizatorClassName = props.getProperty(Constants.AUTHORIZATOR_CLASS_NAME, "");
String authorizatorClassName = props.getProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
if (!authorizatorClassName.isEmpty()) {
authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class);
LOG.info("Loaded custom authorizator {}", authorizatorClassName);
}
if (authorizator == null) {
String aclFilePath = props.getProperty(ACL_FILE_PROPERTY_NAME, "");
String aclFilePath = props.getProperty(BrokerConstants.ACL_FILE_PROPERTY_NAME, "");
if (aclFilePath != null && !aclFilePath.isEmpty()) {
authorizator = new DenyAllAuthorizator();
File aclFile = new File(configPath, aclFilePath);
@@ -131,7 +130,7 @@ public class SimpleMessaging {
}
boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true"));
boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, "true"));
m_processor.init(subscriptions, messagesStore, sessionsStore, authenticator, allowAnonymous, authorizator, m_interceptor);
return m_processor;
}
@@ -32,8 +32,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME;
import static io.moquette.commons.Constants.AUTOSAVE_INTERVAL_PROPERTY_NAME;
import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
import static io.moquette.BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME;
/**
* MapDB main persistence implementation