This closes #888

This commit is contained in:
Martyn Taylor 2016-11-16 14:41:19 +00:00
commit 53b00e1dd5
9 changed files with 126 additions and 0 deletions

View File

@ -438,6 +438,8 @@ public final class ActiveMQDefaultConfiguration {
public static final int DEFAULT_DISK_SCAN = 5000;
public static final String DEFAULT_SYSTEM_PROPERTY_PREFIX = "brokerconfig.";
/**
* If true then the ActiveMQ Artemis Server will make use of any Protocol Managers that are in available on the classpath. If false then only the core protocol will be available, unless in Embedded mode where users can inject their own Protocol Managers.
*/
@ -1175,4 +1177,8 @@ public final class ActiveMQDefaultConfiguration {
public static int getDefaultDiskScanPeriod() {
return DEFAULT_DISK_SCAN;
}
public static String getDefaultSystemPropertyPrefix() {
return DEFAULT_SYSTEM_PROPERTY_PREFIX;
}
}

View File

@ -20,6 +20,7 @@ import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
@ -49,6 +50,30 @@ public interface Configuration {
*/
Configuration setName(String name);
/**
* We use Bean-utils to pass in System.properties that start with {@link #setSystemPropertyPrefix(String)}.
* The default should be 'brokerconfig.' (Including the ".").
* For example if you want to set clustered through a system property you must do:
*
* -Dbrokerconfig.clustered=true
*
* The prefix is configured here.
* @param systemPropertyPrefix
* @return
*/
Configuration setSystemPropertyPrefix(String systemPropertyPrefix);
/**
* See doc at {@link #setSystemPropertyPrefix(String)}.
* @return
*/
String getSystemPropertyPrefix();
Configuration parseSystemProperties() throws Exception;
Configuration parseSystemProperties(Properties properties) throws Exception;
/**
* Returns whether this server is clustered. <br>
* {@code true} if {@link #getClusterConfigurations()} is not empty.

View File

@ -36,6 +36,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
@ -63,10 +64,14 @@ import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
import org.apache.activemq.artemis.uri.AcceptorTransportConfigurationParser;
import org.apache.activemq.artemis.uri.ConnectorTransportConfigurationParser;
import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.jboss.logging.Logger;
public class ConfigurationImpl implements Configuration, Serializable {
// Constants ------------------------------------------------------------------------------
private static final Logger logger = Logger.getLogger(ConfigurationImpl.class);
public static final JournalType DEFAULT_JOURNAL_TYPE = JournalType.ASYNCIO;
private static final long serialVersionUID = 4077088945050267843L;
@ -254,6 +259,8 @@ public class ConfigurationImpl implements Configuration, Serializable {
private int diskScanPeriod = ActiveMQDefaultConfiguration.getDefaultDiskScanPeriod();
private String systemPropertyPrefix = ActiveMQDefaultConfiguration.getDefaultSystemPropertyPrefix();
/**
* Parent folder for all data folders.
*/
@ -261,6 +268,46 @@ public class ConfigurationImpl implements Configuration, Serializable {
// Public -------------------------------------------------------------------------
@Override
public Configuration setSystemPropertyPrefix(String systemPropertyPrefix) {
this.systemPropertyPrefix = systemPropertyPrefix;
return this;
}
@Override
public String getSystemPropertyPrefix() {
return systemPropertyPrefix;
}
@Override
public Configuration parseSystemProperties() throws Exception {
parseSystemProperties(System.getProperties());
return this;
}
@Override
public Configuration parseSystemProperties(Properties properties) throws Exception {
Map<String, Object> beanProperties = new HashMap<>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (entry.getKey().toString().startsWith(systemPropertyPrefix)) {
String key = entry.getKey().toString().substring(systemPropertyPrefix.length());
logger.debug("Setting up config, " + key + "=" + entry.getValue());
beanProperties.put(key, entry.getValue());
}
}
if (!beanProperties.isEmpty()) {
BeanSupport.setData(this, beanProperties);
}
return this;
}
@Override
public boolean isClustered() {
return !getClusterConfigurations().isEmpty();

View File

@ -56,6 +56,8 @@ public final class FileConfiguration extends ConfigurationImpl implements Deploy
setConfigurationUrl(url);
parseSystemProperties();
parsed = true;
}

View File

@ -217,6 +217,8 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
config.setName(getString(e, "name", config.getName(), Validators.NO_CHECK));
config.setSystemPropertyPrefix(getString(e, "system-property-prefix", config.getSystemPropertyPrefix(), Validators.NOT_NULL_OR_EMPTY));
NodeList haPolicyNodes = e.getElementsByTagName("ha-policy");
if (haPolicyNodes.getLength() > 0) {

View File

@ -435,6 +435,8 @@ public class ActiveMQServerImpl implements ActiveMQServer {
return;
}
configuration.parseSystemProperties();
startDate = new Date();
state = SERVER_STATE.STARTING;

View File

@ -34,6 +34,14 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="system-property-prefix" type="xsd:string" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
This defines the prefix which we will use to parse System properties for the configuration. Default=
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="resolve-protocols" type="xsd:boolean" default="true" maxOccurs="1"
minOccurs="0">
<xsd:annotation>

View File

@ -17,6 +17,7 @@
package org.apache.activemq.artemis.core.config.impl;
import java.io.File;
import java.util.Properties;
import org.apache.activemq.artemis.ArtemisConstants;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
@ -543,6 +544,20 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
}
@Test
public void testSetSystemProperty() throws Throwable {
ConfigurationImpl configuration = new ConfigurationImpl();
Properties properties = new Properties();
properties.put(configuration.getSystemPropertyPrefix() + "fileDeployerScanPeriod", "1234");
properties.put(configuration.getSystemPropertyPrefix() + "globalMaxSize", "4321");
configuration.parseSystemProperties(properties);
Assert.assertEquals(1234, configuration.getFileDeployerScanPeriod());
Assert.assertEquals(4321, configuration.getGlobalMaxSize());
}
@Override
@Before
public void setUp() throws Exception {

View File

@ -15,6 +15,24 @@ This is the main core server configuration file which contains to elements
The 'core' element contains the main server configuration while the 'jms'
element is used by the server side JMS service to load JMS Queues, Topics
# System properties
It is possible to use System properties to replace some of the configuration properties. If you define a System property starting with "brokerconfig." that will be passed along to Bean Utils and the configuration would be replaced.
To define global-max-size=1000000 using a system property you would have to define this property, for example through java arguments:
```
java -Dbrokerconfig.globalMaxSize=1000000
```
You can also change the prefix through the broker.xml by setting:
```
<system-property-prefix>yourprefix</system-property-prefix>
```
This is to help you customize artemis on embedded systems.
# The core configuration
This describes the root of the XML configuration. You will see here also multiple sub-types listed.
@ -87,6 +105,7 @@ Name | Description
[scheduled-thread-pool-max-size](thread-pooling.md#server.scheduled.thread.pool "Server Scheduled Thread Pool")| Maximum number of threads to use for the scheduled thread pool. Default=5
[security-enabled](security.md "Security") | true means that security is enabled. Default=true
[security-invalidation-interval](security.md "Security") | how long (in ms) to wait before invalidating the security cache. Default=10000
system-property-prefix | Prefix for replacing configuration settings using Bean Utils.
[populate-validated-user](security.md "Security") | whether or not to add the name of the validated user to the messages that user sends. Default=false
[security-settings](security.md "Role based security for addresses") | [a list of security-setting](#security-setting-type)
[thread-pool-max-size](thread-pooling.md "Server Scheduled Thread Pool") | Maximum number of threads to use for the thread pool. -1 means 'no limits'.. Default=30