2015-08-22 15:35:11 +02:00
|
|
|
/*
|
2018-04-27 20:17:47 +02:00
|
|
|
* Copyright (c) 2012-2018 The original author or authors
|
2015-08-22 15:35:11 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2017-02-01 15:24:59 +01:00
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.server.config;
|
2015-08-22 15:35:11 +02:00
|
|
|
|
2016-04-25 11:51:57 +02:00
|
|
|
import io.moquette.BrokerConstants;
|
|
|
|
|
|
2015-08-22 15:35:11 +02:00
|
|
|
/**
|
|
|
|
|
* Base interface for all configuration implementations (filesystem, memory or classpath)
|
|
|
|
|
*/
|
2016-04-25 11:51:57 +02:00
|
|
|
public abstract class IConfig {
|
2017-02-01 15:24:59 +01:00
|
|
|
|
2016-12-26 15:59:19 +02:00
|
|
|
public static final String DEFAULT_CONFIG = "config/moquette.conf";
|
|
|
|
|
|
2016-04-25 11:51:57 +02:00
|
|
|
public abstract void setProperty(String name, String value);
|
2015-08-22 15:35:11 +02:00
|
|
|
|
2018-04-27 13:48:53 +02:00
|
|
|
/**
|
|
|
|
|
* Same semantic of Properties
|
2018-11-10 18:31:51 +01:00
|
|
|
*
|
|
|
|
|
* @param name property name.
|
|
|
|
|
* @return property value.
|
2018-04-27 13:48:53 +02:00
|
|
|
* */
|
2016-04-25 11:51:57 +02:00
|
|
|
public abstract String getProperty(String name);
|
2015-08-22 15:35:11 +02:00
|
|
|
|
2018-04-27 13:48:53 +02:00
|
|
|
/**
|
|
|
|
|
* Same semantic of Properties
|
2018-11-10 18:31:51 +01:00
|
|
|
*
|
|
|
|
|
* @param name property name.
|
|
|
|
|
* @param defaultValue default value to return in case the property doesn't exists.
|
|
|
|
|
* @return property value.
|
2018-04-27 13:48:53 +02:00
|
|
|
* */
|
2016-04-25 11:51:57 +02:00
|
|
|
public abstract String getProperty(String name, String defaultValue);
|
|
|
|
|
|
|
|
|
|
void assignDefaults() {
|
|
|
|
|
setProperty(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
|
|
|
|
|
setProperty(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
|
2017-02-01 15:24:59 +01:00
|
|
|
// setProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME,
|
|
|
|
|
// Integer.toString(BrokerConstants.WEBSOCKET_PORT));
|
2016-04-25 11:51:57 +02:00
|
|
|
setProperty(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
|
2017-02-01 15:24:59 +01:00
|
|
|
// setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME,
|
|
|
|
|
// BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
2016-04-25 11:51:57 +02:00
|
|
|
setProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, Boolean.TRUE.toString());
|
|
|
|
|
setProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
|
|
|
|
|
setProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
|
2018-02-09 09:55:29 +01:00
|
|
|
setProperty(BrokerConstants.NETTY_MAX_BYTES_PROPERTY_NAME,
|
|
|
|
|
String.valueOf(BrokerConstants.DEFAULT_NETTY_MAX_BYTES_IN_MESSAGE));
|
2016-04-25 11:51:57 +02:00
|
|
|
}
|
2016-12-26 15:59:19 +02:00
|
|
|
|
|
|
|
|
public abstract IResourceLoader getResourceLoader();
|
|
|
|
|
|
2018-04-27 13:48:53 +02:00
|
|
|
public int intProp(String propertyName, int defaultValue) {
|
|
|
|
|
String propertyValue = getProperty(propertyName);
|
|
|
|
|
if (propertyValue == null) {
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
return Integer.parseInt(propertyValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean boolProp(String propertyName, boolean defaultValue) {
|
|
|
|
|
String propertyValue = getProperty(propertyName);
|
|
|
|
|
if (propertyValue == null) {
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
return Boolean.parseBoolean(propertyValue);
|
|
|
|
|
}
|
2015-08-22 15:35:11 +02:00
|
|
|
}
|