diff options
| author | Robert Gemmell <robbie@apache.org> | 2013-03-10 22:31:31 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2013-03-10 22:31:31 +0000 |
| commit | 7fa262ba8294d4292544d6de2166b9658d8dc751 (patch) | |
| tree | 6b98eb884e574b5f364332c2e6576aca22ca1987 /qpid/java/broker/src | |
| parent | 36772ca582304285e39cc5c03360288f32b303fb (diff) | |
| download | qpid-python-7fa262ba8294d4292544d6de2166b9658d8dc751.tar.gz | |
QPID-4390: move the work dir defaulting and configuration fully within BrokerOptions
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1454940 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src')
4 files changed, 166 insertions, 38 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java index 54dcf0543d..5615e1e11b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java @@ -113,16 +113,6 @@ public class Broker String storeLocation = options.getConfigurationStoreLocation(); String storeType = options.getConfigurationStoreType(); - if (storeLocation == null) - { - String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK); - if (qpidWork == null) - { - qpidWork = new File(System.getProperty("user.dir"), "work").getAbsolutePath(); - } - storeLocation = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_FILE + "." + storeType).getAbsolutePath(); - } - CurrentActor.get().message(BrokerMessages.CONFIG(storeLocation)); File logConfigFile = getConfigFile(options.getLogConfigFile(), BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java index 57e401e608..ec2894da55 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java @@ -20,25 +20,30 @@ */ package org.apache.qpid.server; +import java.io.File; + +import org.apache.qpid.server.configuration.BrokerProperties; + public class BrokerOptions { public static final String DEFAULT_STORE_TYPE = "json"; - public static final String DEFAULT_CONFIG_FILE = "config"; + public static final String DEFAULT_CONFIG_NAME_PREFIX = "config"; public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml"; private String _logConfigFile; private Integer _logWatchFrequency = 0; private String _configurationStoreLocation; - private String _configurationStoreType = DEFAULT_STORE_TYPE; + private String _configurationStoreType; private String _initialConfigurationStoreLocation; - private String _initialConfigurationStoreType = DEFAULT_STORE_TYPE; + private String _initialConfigurationStoreType; private boolean _managementMode; private int _managementModeRmiPort; private int _managementModeConnectorPort; private int _managementModeHttpPort; + private String _workingDir; public String getLogConfigFile() { @@ -64,26 +69,6 @@ public class BrokerOptions _logWatchFrequency = logWatchFrequency; } - public String getConfigurationStoreLocation() - { - return _configurationStoreLocation; - } - - public void setConfigurationStoreLocation(String cofigurationStore) - { - _configurationStoreLocation = cofigurationStore; - } - - public String getConfigurationStoreType() - { - return _configurationStoreType; - } - - public void setConfigurationStoreType(String cofigurationStoreType) - { - _configurationStoreType = cofigurationStoreType; - } - public void setInitialConfigurationStoreLocation(String initialConfigurationStore) { _initialConfigurationStoreLocation = initialConfigurationStore; @@ -101,6 +86,11 @@ public class BrokerOptions public String getInitialConfigurationStoreType() { + if(_initialConfigurationStoreType == null) + { + return DEFAULT_STORE_TYPE; + } + return _initialConfigurationStoreType; } @@ -143,4 +133,93 @@ public class BrokerOptions { _managementModeHttpPort = managementModeHttpPort; } -}
\ No newline at end of file + + /** + * Get the broker configuration store type. + * + * @return the previously set store type, or if none was set the default: {@value #DEFAULT_STORE_TYPE} + */ + public String getConfigurationStoreType() + { + if(_configurationStoreType == null) + { + return DEFAULT_STORE_TYPE; + } + + return _configurationStoreType; + } + + /** + * Set the broker configuration store type. + * + * Passing null clears previously set values and returns to the default. + */ + public void setConfigurationStoreType(String cofigurationStoreType) + { + _configurationStoreType = cofigurationStoreType; + } + + /** + * Get the broker configuration store location. + * + * Defaults to {@value #DEFAULT_CONFIG_NAME_PREFIX}.{@literal <store type>} (see {@link BrokerOptions#getConfigurationStoreType()}) within the broker work directory (see {@link BrokerOptions#getWorkDir()}). + * + * @return the previously set configuration store location, or the default location if none was set. + */ + public String getConfigurationStoreLocation() + { + if(_configurationStoreLocation == null) + { + String workDir = getWorkDir(); + String storeType = getConfigurationStoreType(); + + return new File(workDir, DEFAULT_CONFIG_NAME_PREFIX + "." + storeType).getAbsolutePath(); + } + + return _configurationStoreLocation; + } + + /** + * Set the absolute path to use for the broker configuration store. + * + * Passing null clears any previously set value and returns to the default. + */ + public void setConfigurationStoreLocation(String cofigurationStore) + { + _configurationStoreLocation = cofigurationStore; + } + + /** + * Get the broker work directory location. + * + * Defaults to the location set in the "QPID_WORK" system property if it is set, or the 'work' sub-directory + * of the user working directory ("user.dir" property) for the Java process if it is not. + * + * @return the previously set configuration store location, or the default location if none was set. + */ + public String getWorkDir() + { + if(_workingDir == null) + { + String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK); + if (qpidWork == null) + { + return new File(System.getProperty("user.dir"), "work").getAbsolutePath(); + } + + return qpidWork; + } + + return _workingDir; + } + + /** + * Set the absolute path to use for the broker work directory. + * + * Passing null clears any previously set value and returns to the default. + */ + public void setWorkDir(String workingDir) + { + _workingDir = workingDir; + } +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java index 16b459b5d4..9105f5b2e7 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java @@ -20,6 +20,8 @@ */ package org.apache.qpid.server; +import java.io.File; + import org.apache.qpid.test.utils.QpidTestCase; public class BrokerOptionsTest extends QpidTestCase @@ -42,14 +44,39 @@ public class BrokerOptionsTest extends QpidTestCase assertEquals("dby", _options.getConfigurationStoreType()); } - public void testDefaultConfigurationStoreLocation() + public void testDefaultConfigurationStoreLocationWithQpidWork() + { + String qpidWork = "/test/value"; + setTestSystemProperty("QPID_WORK", qpidWork); + + String expectedPath = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + "." + BrokerOptions.DEFAULT_STORE_TYPE).getAbsolutePath(); + assertEquals (expectedPath, _options.getConfigurationStoreLocation()); + } + + public void testDefaultConfigurationStoreLocationWithoutQpidWork() { - assertNull(_options.getConfigurationStoreLocation()); + setTestSystemProperty("QPID_WORK", null); + String userDir = System.getProperty("user.dir"); + + String expectedPath = new File(userDir, "work/" + BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + "." + BrokerOptions.DEFAULT_STORE_TYPE).getAbsolutePath(); + assertEquals (expectedPath, _options.getConfigurationStoreLocation()); + } + + public void testDefaultConfigurationStoreLocationWithQpidWorkAndDifferentStoreType() + { + String qpidWork = "/test/value"; + setTestSystemProperty("QPID_WORK", qpidWork); + + String storeType = "dby"; + _options.setConfigurationStoreType(storeType); + + String expectedPath = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + "." + storeType).getAbsolutePath(); + assertEquals (expectedPath, _options.getConfigurationStoreLocation()); } public void testOverriddenConfigurationStoreLocation() { - final String testConfigFile = "etc/mytestconfig.xml"; + final String testConfigFile = "/my/test/store-location.dby"; _options.setConfigurationStoreLocation(testConfigFile); assertEquals(testConfigFile, _options.getConfigurationStoreLocation()); } @@ -147,4 +174,28 @@ public class BrokerOptionsTest extends QpidTestCase assertEquals(5555, _options.getManagementModeHttpPort()); } + public void testDefaultWorkDirWithQpidWork() + { + String qpidWork = "/test/value"; + setTestSystemProperty("QPID_WORK", qpidWork); + + String expectedPath = new File(qpidWork).getAbsolutePath(); + assertEquals (expectedPath, _options.getWorkDir()); + } + + public void testDefaultWorkDirWithoutQpidWork() + { + setTestSystemProperty("QPID_WORK", null); + String userDir = System.getProperty("user.dir"); + + String expectedPath = new File(userDir, "work").getAbsolutePath(); + assertEquals (expectedPath, _options.getWorkDir()); + } + + public void testOverriddenWorkDir() + { + final String testWorkDir = "/my/test/work/dir"; + _options.setWorkDir(testWorkDir); + assertEquals(testWorkDir, _options.getWorkDir()); + } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java index cab54b1310..6ca9a55d7b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java @@ -20,7 +20,10 @@ */ package org.apache.qpid.server; +import java.io.File; + import org.apache.commons.cli.CommandLine; +import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.test.utils.QpidTestCase; /** @@ -34,8 +37,13 @@ public class MainTest extends QpidTestCase { BrokerOptions options = startDummyMain(""); + String qpidWork = "/qpid/work"; + setTestSystemProperty(BrokerProperties.PROPERTY_QPID_WORK, qpidWork); + + String expectedStorePath = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + ".json").getAbsolutePath(); + assertEquals("json", options.getConfigurationStoreType()); - assertEquals(null, options.getConfigurationStoreLocation()); + assertEquals(expectedStorePath, options.getConfigurationStoreLocation()); assertEquals(null, options.getLogConfigFile()); assertEquals(0, options.getLogWatchFrequency()); assertEquals("json", options.getInitialConfigurationStoreType()); |
