From commits-return-15093-apmail-qpid-commits-archive=qpid.apache.org@qpid.apache.org Thu Jul 7 15:13:00 2011 Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B43B04191 for ; Thu, 7 Jul 2011 15:13:00 +0000 (UTC) Received: (qmail 19769 invoked by uid 500); 7 Jul 2011 15:13:00 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 19745 invoked by uid 500); 7 Jul 2011 15:13:00 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 19738 invoked by uid 99); 7 Jul 2011 15:13:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 15:13:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 15:12:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5C7D423889E1 for ; Thu, 7 Jul 2011 15:12:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1143870 [1/2] - in /qpid/trunk/qpid/java: broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/ broker/src/main/java/org/apache/qpid/server/ broker/src/main/java/org/apache/qpid/server/configuration/ broker/src/test... Date: Thu, 07 Jul 2011 15:12:27 -0000 To: commits@qpid.apache.org From: robbie@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110707151228.5C7D423889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: robbie Date: Thu Jul 7 15:12:26 2011 New Revision: 1143870 URL: http://svn.apache.org/viewvc?rev=1143870&view=rev Log: QPID-2815: refactor broker startup to present a clean interface interface for starting the broker within an existing application Applied patch by Keith Wall and myself Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerHolder.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java - copied, changed from r1143869, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java qpid/trunk/qpid/java/test-profiles/internal.testprofile - copied, changed from r1143869, qpid/trunk/qpid/java/test-profiles/java.testprofile Removed: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/RunBrokerWithCommand.java Modified: qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java qpid/trunk/qpid/java/test-profiles/default.testprofile qpid/trunk/qpid/java/test-profiles/java.testprofile Modified: qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java (original) +++ qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java Thu Jul 7 15:12:26 2011 @@ -34,6 +34,13 @@ import org.apache.qpid.test.utils.QpidTe public class FirewallConfigurationTest extends QpidTestCase { + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + ApplicationRegistry.remove(); + } + public void testFirewallConfiguration() throws Exception { // Write out config @@ -43,18 +50,11 @@ public class FirewallConfigurationTest e // Load config ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - try - { - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg); - // Test config - assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.1.2.3", 65535))); - } - finally - { - ApplicationRegistry.remove(); - } + // Test config + assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); + assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.1.2.3", 65535))); } public void testCombinedConfigurationFirewall() throws Exception @@ -112,17 +112,10 @@ public class FirewallConfigurationTest e // Load config ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - try - { - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg); - // Test config - assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - } - finally - { - ApplicationRegistry.remove(); - } + // Test config + assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); } public void testConfigurationFirewallReload() throws Exception @@ -135,24 +128,17 @@ public class FirewallConfigurationTest e // Load config ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - try - { - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg); - // Test config - assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); + // Test config + assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - // Switch to deny the connection - writeConfigFile(mainFile, true); + // Switch to deny the connection + writeConfigFile(mainFile, true); - reg.getConfiguration().reparseConfigFileSecuritySections(); + reg.getConfiguration().reparseConfigFileSecuritySections(); - assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - } - finally - { - ApplicationRegistry.remove(); - } + assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); } public void testCombinedConfigurationFirewallReload() throws Exception @@ -209,47 +195,40 @@ public class FirewallConfigurationTest e // Load config ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); - try - { - ApplicationRegistry.initialise(reg); + ApplicationRegistry.initialise(reg); - // Test config - assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); + // Test config + assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - RandomAccessFile fileBRandom = new RandomAccessFile(fileB, "rw"); - fileBRandom.setLength(0); - fileBRandom.seek(0); - fileBRandom.close(); + RandomAccessFile fileBRandom = new RandomAccessFile(fileB, "rw"); + fileBRandom.setLength(0); + fileBRandom.seek(0); + fileBRandom.close(); - out = new FileWriter(fileB); - out.write("\n"); - out.write("\t"); - out.write("\n"); - out.close(); + out = new FileWriter(fileB); + out.write("\n"); + out.write("\t"); + out.write("\n"); + out.close(); - reg.getConfiguration().reparseConfigFileSecuritySections(); + reg.getConfiguration().reparseConfigFileSecuritySections(); - assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); + assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - fileBRandom = new RandomAccessFile(fileB, "rw"); - fileBRandom.setLength(0); - fileBRandom.seek(0); - fileBRandom.close(); + fileBRandom = new RandomAccessFile(fileB, "rw"); + fileBRandom.setLength(0); + fileBRandom.seek(0); + fileBRandom.close(); - out = new FileWriter(fileB); - out.write("\n"); - out.write("\t"); - out.write("\n"); - out.close(); + out = new FileWriter(fileB); + out.write("\n"); + out.write("\t"); + out.write("\n"); + out.close(); - reg.getConfiguration().reparseConfigFileSecuritySections(); + reg.getConfiguration().reparseConfigFileSecuritySections(); - assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); - } - finally - { - ApplicationRegistry.remove(); - } + assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535))); } private void writeFirewallVhostsFile(File vhostsFile, boolean allow) throws IOException @@ -335,7 +314,7 @@ public class FirewallConfigurationTest e // Load config ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); ApplicationRegistry.initialise(reg); - + // Test config VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry(); VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test"); Modified: qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java (original) +++ qpid/trunk/qpid/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java Thu Jul 7 15:12:26 2011 @@ -27,12 +27,15 @@ import java.net.SocketAddress; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.security.Result; import org.apache.qpid.server.security.access.plugins.Firewall; import org.apache.qpid.server.security.access.plugins.FirewallConfiguration; -import org.apache.qpid.server.util.InternalBrokerBaseCase; +import org.apache.qpid.server.util.TestApplicationRegistry; +import org.apache.qpid.test.utils.QpidTestCase; -public class FirewallPluginTest extends InternalBrokerBaseCase +public class FirewallPluginTest extends QpidTestCase { public class RuleInfo { @@ -73,15 +76,23 @@ public class FirewallPluginTest extends // IP address private SocketAddress _address; + private ServerConfiguration _serverConfig; @Override - public void setUp() throws Exception + protected void setUp() throws Exception { super.setUp(); - + _serverConfig = new ServerConfiguration(new XMLConfiguration()); + ApplicationRegistry.initialise(new TestApplicationRegistry(_serverConfig)); _address = new InetSocketAddress("127.0.0.1", 65535); } + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + ApplicationRegistry.remove(); + } private Firewall initialisePlugin(String defaultAction, RuleInfo[] rules) throws IOException, ConfigurationException { // Create sample config file @@ -108,7 +119,7 @@ public class FirewallPluginTest extends } buf.write(""); buf.close(); - + // Configure plugin FirewallConfiguration config = new FirewallConfiguration(); config.setConfiguration("", new XMLConfiguration(confFile)); Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java?rev=1143870&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java (added) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java Thu Jul 7 15:12:26 2011 @@ -0,0 +1,420 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server; + +import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import org.apache.log4j.PropertyConfigurator; +import org.apache.log4j.xml.QpidLog4JConfigurator; +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.configuration.ServerNetworkTransportConfiguration; +import org.apache.qpid.server.configuration.management.ConfigurationManagementMBean; +import org.apache.qpid.server.information.management.ServerInformationMBean; +import org.apache.qpid.server.logging.SystemOutMessageLogger; +import org.apache.qpid.server.logging.actors.BrokerActor; +import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.logging.actors.GenericActor; +import org.apache.qpid.server.logging.management.LoggingManagementMBean; +import org.apache.qpid.server.logging.messages.BrokerMessages; +import org.apache.qpid.server.protocol.AMQProtocolEngineFactory; +import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory; +import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory.VERSION; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; +import org.apache.qpid.server.transport.QpidAcceptor; +import org.apache.qpid.ssl.SSLContextFactory; +import org.apache.qpid.transport.NetworkTransportConfiguration; +import org.apache.qpid.transport.network.IncomingNetworkTransport; +import org.apache.qpid.transport.network.Transport; +import org.apache.qpid.transport.network.mina.MinaNetworkTransport; + +public class Broker +{ + private static final int IPV4_ADDRESS_LENGTH = 4; + private static final char IPV4_LITERAL_SEPARATOR = '.'; + + protected static class InitException extends RuntimeException + { + private static final long serialVersionUID = 1L; + + InitException(String msg, Throwable cause) + { + super(msg, cause); + } + } + + public void shutdown() + { + ApplicationRegistry.remove(); + } + + public void startup() throws Exception + { + startup(new BrokerOptions()); + } + + public void startup(BrokerOptions options) throws Exception + { + try + { + CurrentActor.set(new BrokerActor(new SystemOutMessageLogger())); + startupImpl(options); + } + finally + { + CurrentActor.remove(); + } + } + + private void startupImpl(final BrokerOptions options) throws Exception + { + final String qpidHome = options.getQpidHome(); + final File configFile = getConfigFile(options.getConfigFile(), + BrokerOptions.DEFAULT_CONFIG_FILE, qpidHome, true); + + CurrentActor.get().message(BrokerMessages.CONFIG(configFile.getAbsolutePath())); + + File logConfigFile = getConfigFile(options.getLogConfigFile(), + BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false); + + configureLogging(logConfigFile, options.getLogWatchFrequency()); + + ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile); + ServerConfiguration serverConfig = config.getConfiguration(); + updateManagementPort(serverConfig, options.getJmxPort()); + + ApplicationRegistry.initialise(config); + + // We have already loaded the BrokerMessages class by this point so we + // need to refresh the locale setting incase we had a different value in + // the configuration. + BrokerMessages.reload(); + + // AR.initialise() sets and removes its own actor so we now need to set the actor + // for the remainder of the startup, and the default actor if the stack is empty + CurrentActor.set(new BrokerActor(config.getCompositeStartupMessageLogger())); + CurrentActor.setDefault(new BrokerActor(config.getRootMessageLogger())); + GenericActor.setDefaultMessageLogger(config.getRootMessageLogger()); + + try + { + configureLoggingManagementMBean(logConfigFile, options.getLogWatchFrequency()); + + ConfigurationManagementMBean configMBean = new ConfigurationManagementMBean(); + configMBean.register(); + + ServerInformationMBean sysInfoMBean = new ServerInformationMBean(config); + sysInfoMBean.register(); + + Set ports = new HashSet(options.getPorts()); + if(ports.isEmpty()) + { + parsePortList(ports, serverConfig.getPorts()); + } + + Set sslPorts = new HashSet(options.getSSLPorts()); + if(sslPorts.isEmpty()) + { + parsePortList(sslPorts, serverConfig.getSSLPorts()); + } + + Set exclude_0_10 = new HashSet(options.getExcludedPorts(ProtocolExclusion.v0_10)); + if(exclude_0_10.isEmpty()) + { + parsePortList(exclude_0_10, serverConfig.getPortExclude010()); + } + + Set exclude_0_9_1 = new HashSet(options.getExcludedPorts(ProtocolExclusion.v0_9_1)); + if(exclude_0_9_1.isEmpty()) + { + parsePortList(exclude_0_9_1, serverConfig.getPortExclude091()); + } + + Set exclude_0_9 = new HashSet(options.getExcludedPorts(ProtocolExclusion.v0_9)); + if(exclude_0_9.isEmpty()) + { + parsePortList(exclude_0_9, serverConfig.getPortExclude09()); + } + + Set exclude_0_8 = new HashSet(options.getExcludedPorts(ProtocolExclusion.v0_8)); + if(exclude_0_8.isEmpty()) + { + parsePortList(exclude_0_8, serverConfig.getPortExclude08()); + } + + String bindAddr = options.getBind(); + if (bindAddr == null) + { + bindAddr = serverConfig.getBind(); + } + + InetAddress bindAddress = null; + if (bindAddr.equals(WILDCARD_ADDRESS)) + { + bindAddress = new InetSocketAddress(0).getAddress(); + } + else + { + bindAddress = InetAddress.getByAddress(parseIP(bindAddr)); + } + String hostName = bindAddress.getCanonicalHostName(); + + if (!serverConfig.getSSLOnly()) + { + for(int port : ports) + { + Set supported = EnumSet.allOf(VERSION.class); + + if(exclude_0_10.contains(port)) + { + supported.remove(VERSION.v0_10); + } + + if(exclude_0_9_1.contains(port)) + { + supported.remove(VERSION.v0_9_1); + } + if(exclude_0_9.contains(port)) + { + supported.remove(VERSION.v0_9); + } + if(exclude_0_8.contains(port)) + { + supported.remove(VERSION.v0_8); + } + + NetworkTransportConfiguration settings = + new ServerNetworkTransportConfiguration(serverConfig, port, bindAddress.getHostName(), Transport.TCP); + + IncomingNetworkTransport transport = new MinaNetworkTransport(); + MultiVersionProtocolEngineFactory protocolEngineFactory = + new MultiVersionProtocolEngineFactory(hostName, supported); + + transport.accept(settings, protocolEngineFactory, null); + ApplicationRegistry.getInstance().addAcceptor(new InetSocketAddress(bindAddress, port), + new QpidAcceptor(transport,"TCP")); + CurrentActor.get().message(BrokerMessages.LISTENING("TCP", port)); + } + } + + if (serverConfig.getEnableSSL()) + { + String keystorePath = serverConfig.getKeystorePath(); + String keystorePassword = serverConfig.getKeystorePassword(); + String certType = serverConfig.getCertType(); + SSLContextFactory sslFactory = + new SSLContextFactory(keystorePath, keystorePassword, certType); + + for(int sslPort : sslPorts) + { + NetworkTransportConfiguration settings = + new ServerNetworkTransportConfiguration(serverConfig, sslPort, bindAddress.getHostName(), Transport.TCP); + + IncomingNetworkTransport transport = new MinaNetworkTransport(); + + transport.accept(settings, new AMQProtocolEngineFactory(), sslFactory); + + ApplicationRegistry.getInstance().addAcceptor(new InetSocketAddress(bindAddress, sslPort), + new QpidAcceptor(transport,"TCP")); + CurrentActor.get().message(BrokerMessages.LISTENING("TCP/SSL", sslPort)); + } + } + + CurrentActor.get().message(BrokerMessages.READY()); + } + finally + { + // Startup is complete so remove the AR initialised Startup actor + CurrentActor.remove(); + } + } + + private File getConfigFile(final String fileName, + final String defaultFileName, + final String qpidHome, boolean throwOnFileNotFound) throws InitException + { + File configFile = null; + if (fileName != null) + { + configFile = new File(fileName); + } + else + { + configFile = new File(qpidHome, defaultFileName); + } + + if (!configFile.exists() && throwOnFileNotFound) + { + String error = "File " + fileName + " could not be found. Check the file exists and is readable."; + + if (qpidHome == null) + { + error = error + "\nNote: " + BrokerOptions.QPID_HOME + " is not set."; + } + + throw new InitException(error, null); + } + + return configFile; + } + + public static void parsePortList(Set output, List ports) throws InitException + { + if(ports != null) + { + for(Object o : ports) + { + try + { + output.add(Integer.parseInt(String.valueOf(o))); + } + catch (NumberFormatException e) + { + throw new InitException("Invalid port: " + o, e); + } + } + } + } + + /** + * Update the configuration data with the management port. + * @param configuration + * @param managementPort The string from the command line + */ + private void updateManagementPort(ServerConfiguration configuration, Integer managementPort) + { + if (managementPort != null) + { + try + { + configuration.setJMXManagementPort(managementPort); + } + catch (NumberFormatException e) + { + throw new InitException("Invalid management port: " + managementPort, null); + } + } + } + + private byte[] parseIP(String address) throws Exception + { + char[] literalBuffer = address.toCharArray(); + int byteCount = 0; + int currByte = 0; + byte[] ip = new byte[IPV4_ADDRESS_LENGTH]; + for (int i = 0; i < literalBuffer.length; i++) + { + char currChar = literalBuffer[i]; + if ((currChar >= '0') && (currChar <= '9')) + { + currByte = (currByte * 10) + (Character.digit(currChar, 10) & 0xFF); + } + + if (currChar == IPV4_LITERAL_SEPARATOR || (i + 1 == literalBuffer.length)) + { + ip[byteCount++] = (byte) currByte; + currByte = 0; + } + } + + if (byteCount != 4) + { + throw new Exception("Invalid IP address: " + address); + } + return ip; + } + + private void configureLogging(File logConfigFile, long logWatchTime) throws InitException, IOException + { + if (logConfigFile.exists() && logConfigFile.canRead()) + { + CurrentActor.get().message(BrokerMessages.LOG_CONFIG(logConfigFile.getAbsolutePath())); + + if (logWatchTime > 0) + { + System.out.println("log file " + logConfigFile.getAbsolutePath() + " will be checked for changes every " + + logWatchTime + " seconds"); + // log4j expects the watch interval in milliseconds + try + { + QpidLog4JConfigurator.configureAndWatch(logConfigFile.getPath(), logWatchTime); + } + catch (Exception e) + { + throw new InitException(e.getMessage(),e); + } + } + else + { + try + { + QpidLog4JConfigurator.configure(logConfigFile.getPath()); + } + catch (Exception e) + { + throw new InitException(e.getMessage(),e); + } + } + } + else + { + System.err.println("Logging configuration error: unable to read file " + logConfigFile.getAbsolutePath()); + System.err.println("Using the fallback internal log4j.properties configuration"); + + InputStream propsFile = this.getClass().getResourceAsStream("/log4j.properties"); + if(propsFile == null) + { + throw new IOException("Unable to load the fallback internal log4j.properties configuration file"); + } + else + { + try + { + Properties fallbackProps = new Properties(); + fallbackProps.load(propsFile); + PropertyConfigurator.configure(fallbackProps); + } + finally + { + propsFile.close(); + } + } + } + } + + private void configureLoggingManagementMBean(File logConfigFile, int logWatchTime) throws Exception + { + LoggingManagementMBean blm = new LoggingManagementMBean(logConfigFile.getPath(),logWatchTime); + + blm.register(); + } +} Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java?rev=1143870&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java (added) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java Thu Jul 7 15:12:26 2011 @@ -0,0 +1,160 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class BrokerOptions +{ + /** serialVersionUID */ + private static final long serialVersionUID = 8051825964945442234L; + + public static final String DEFAULT_CONFIG_FILE = "etc/config.xml"; + public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml"; + public static final String QPID_HOME = "QPID_HOME"; + + public static final String PORTS = "p"; + public static final String SSL_PORTS = "s"; + public static final String BIND = "b"; + public static final String MANAGEMENT = "m"; + public static final String LOG4J = "l"; + public static final String WATCH = "w"; + public static final String CONFIG = "c"; + public static final String PROTOCOL = "protocol"; + + private final Set _ports = new HashSet(); + private final Set _sslPorts = new HashSet(); + private final Map> _exclusionMap = new HashMap>(); + + private String _configFile; + private String _logConfigFile; + private String _bind; + private String _transport = Transport.TCP; + private Integer _jmxPort; + + private Integer _logWatchFrequency = 0; + + public void addPort(final int port) + { + _ports.add(port); + } + + public void addSSLPort(final int sslPort) + { + _sslPorts.add(sslPort); + } + + public Set getPorts() + { + return Collections.unmodifiableSet(_ports); + } + + public Set getSSLPorts() + { + return Collections.unmodifiableSet(_sslPorts); + } + + public String getConfigFile() + { + return _configFile; + } + + public void setConfigFile(final String configFile) + { + _configFile = configFile; + } + + public String getLogConfigFile() + { + return _logConfigFile; + } + + public void setLogConfigFile(final String logConfigFile) + { + _logConfigFile = logConfigFile; + } + + public Integer getJmxPort() + { + return _jmxPort; + } + + public void setJmxPort(final int jmxPort) + { + _jmxPort = jmxPort; + } + + public String getQpidHome() + { + return System.getProperty(QPID_HOME); + } + + public Set getExcludedPorts(final ProtocolExclusion excludeProtocol) + { + final Set excludedPorts = _exclusionMap.get(excludeProtocol); + return excludedPorts == null ? Collections.emptySet() : excludedPorts; + } + + public void addExcludedPort(final ProtocolExclusion excludeProtocol, final int port) + { + if (!_exclusionMap.containsKey(excludeProtocol)) + { + _exclusionMap.put(excludeProtocol, new HashSet()); + } + + Set ports = _exclusionMap.get(excludeProtocol); + ports.add(port); + } + + public String getBind() + { + return _bind; + } + + public void setBind(final String bind) + { + _bind = bind; + } + + public int getLogWatchFrequency() + { + return _logWatchFrequency; + } + + public void setLogWatchFrequency(final int logWatchFrequency) + { + _logWatchFrequency = logWatchFrequency; + } + + public String getTransport() + { + return _transport; + } + + public void setTransport(final String transport) + { + _transport = transport; + } +} \ No newline at end of file Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java Thu Jul 7 15:12:26 2011 @@ -20,19 +20,6 @@ */ package org.apache.qpid.server; -import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; @@ -41,32 +28,9 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; -import org.apache.log4j.xml.QpidLog4JConfigurator; -import org.apache.qpid.common.QpidProperties; -import org.apache.qpid.framing.ProtocolVersion; -import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.configuration.ServerNetworkTransportConfiguration; -import org.apache.qpid.server.configuration.management.ConfigurationManagementMBean; -import org.apache.qpid.server.information.management.ServerInformationMBean; -import org.apache.qpid.server.logging.SystemOutMessageLogger; -import org.apache.qpid.server.logging.actors.BrokerActor; -import org.apache.qpid.server.logging.actors.CurrentActor; -import org.apache.qpid.server.logging.actors.GenericActor; -import org.apache.qpid.server.logging.management.LoggingManagementMBean; -import org.apache.qpid.server.logging.messages.BrokerMessages; -import org.apache.qpid.server.protocol.AMQProtocolEngineFactory; -import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory; -import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory.VERSION; +import org.apache.qpid.server.Broker.InitException; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; -import org.apache.qpid.server.transport.QpidAcceptor; -import org.apache.qpid.ssl.SSLContextFactory; -import org.apache.qpid.transport.ConnectionSettings; -import org.apache.qpid.transport.NetworkTransportConfiguration; -import org.apache.qpid.transport.network.IncomingNetworkTransport; -import org.apache.qpid.transport.network.Transport; -import org.apache.qpid.transport.network.mina.MinaNetworkTransport; + /** * Main entry point for AMQPD. @@ -76,35 +40,38 @@ public class Main { private static Logger _logger; - private static final String DEFAULT_CONFIG_FILE = "etc/config.xml"; - - public static final String DEFAULT_LOG_CONFIG_FILENAME = "log4j.xml"; - public static final String QPID_HOME = "QPID_HOME"; - private static final int IPV4_ADDRESS_LENGTH = 4; + protected final static Options options = new Options(); + protected static CommandLine commandLine; - private static final char IPV4_LITERAL_SEPARATOR = '.'; - - protected static class InitException extends Exception + public static void main(String[] args) { - InitException(String msg, Throwable cause) + //if the -Dlog4j.configuration property has not been set, enable the init override + //to stop Log4J wondering off and picking up the first log4j.xml/properties file it + //finds from the classpath when we get the first Loggers + if(System.getProperty("log4j.configuration") == null) { - super(msg, cause); + System.setProperty("log4j.defaultInitOverride", "true"); } - } - - protected final Options options = new Options(); - protected CommandLine commandLine; - protected Main(String[] args) - { + //now that the override status is know, we can instantiate the Loggers + _logger = Logger.getLogger(Main.class); setOptions(options); if (parseCommandline(args)) { - execute(); + try + { + execute(); + } + catch(Exception e) + { + System.err.println("Exception during startup: " + e); + e.printStackTrace(); + shutdown(1); + } } } - protected boolean parseCommandline(String[] args) + protected static boolean parseCommandline(String[] args) { try { @@ -122,8 +89,7 @@ public class Main } } - @SuppressWarnings("static-access") - protected void setOptions(Options options) + protected static void setOptions(Options options) { Option help = new Option("h", "help", false, "print this message"); Option version = new Option("v", "version", false, "print the version information and exit"); @@ -171,7 +137,7 @@ public class Main Option logconfig = OptionBuilder.withArgName("logconfig").hasArg() .withDescription("use the specified log4j xml configuration file. By " - + "default looks for a file named " + DEFAULT_LOG_CONFIG_FILENAME + + "default looks for a file named " + BrokerOptions.DEFAULT_LOG_CONFIG_FILE + " in the same directory as the configuration file").withLongOpt("logconfig").create("l"); Option logwatchconfig = OptionBuilder.withArgName("logwatch").hasArg() @@ -198,445 +164,110 @@ public class Main options.addOption(sslport); } - protected void execute() + protected static void execute() throws Exception { - // note this understands either --help or -h. If an option only has a long name you can use that but if - // an option has a short name and a long name you must use the short name here. - if (commandLine.hasOption("h")) + BrokerOptions options = new BrokerOptions(); + String configFile = commandLine.getOptionValue(BrokerOptions.CONFIG); + if(configFile != null) { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("Qpid", options, true); + options.setConfigFile(configFile); } - else if (commandLine.hasOption("v")) - { - String ver = QpidProperties.getVersionString(); - - StringBuilder protocol = new StringBuilder("AMQP version(s) [major.minor]: "); - boolean first = true; - for (ProtocolVersion pv : ProtocolVersion.getSupportedProtocolVersions()) - { - if (first) - { - first = false; - } - else - { - protocol.append(", "); - } - - protocol.append(pv.getMajorVersion()).append('-').append(pv.getMinorVersion()); - - } - - System.out.println(ver + " (" + protocol + ")"); - } - else + String logWatchConfig = commandLine.getOptionValue(BrokerOptions.WATCH); + if(logWatchConfig != null) { - try - { - CurrentActor.set(new BrokerActor(new SystemOutMessageLogger())); - startup(); - CurrentActor.remove(); - } - catch (InitException e) - { - System.out.println("Initialisation Error : " + e.getMessage()); - shutdown(1); - } - catch (Throwable e) - { - System.out.println("Error initialising message broker: " + e); - e.printStackTrace(); - shutdown(1); - } + options.setLogWatchFrequency(Integer.parseInt(logWatchConfig) * 1000); } - } - protected void shutdown(int status) - { - ApplicationRegistry.remove(); - System.exit(status); - } - - protected void startup() throws Exception - { - final String QpidHome = System.getProperty(QPID_HOME); - final File defaultConfigFile = new File(QpidHome, DEFAULT_CONFIG_FILE); - final File configFile = new File(commandLine.getOptionValue("c", defaultConfigFile.getPath())); - if (!configFile.exists()) + String logConfig = commandLine.getOptionValue(BrokerOptions.LOG4J); + if(logConfig != null) { - String error = "File " + configFile + " could not be found. Check the file exists and is readable."; - - if (QpidHome == null) - { - error = error + "\nNote: " + QPID_HOME + " is not set."; - } - - throw new InitException(error, null); + options.setLogConfigFile(logConfig); } - else - { - CurrentActor.get().message(BrokerMessages.CONFIG(configFile.getAbsolutePath())); - } - - String logConfig = commandLine.getOptionValue("l"); - String logWatchConfig = commandLine.getOptionValue("w", "0"); - int logWatchTime = 0; - try + String jmxPort = commandLine.getOptionValue(BrokerOptions.MANAGEMENT); + if(jmxPort != null) { - logWatchTime = Integer.parseInt(logWatchConfig); - } - catch (NumberFormatException e) - { - System.err.println("Log watch configuration value of " + logWatchConfig + " is invalid. Must be " - + "a non-negative integer. Using default of zero (no watching configured"); + options.setJmxPort(Integer.parseInt(jmxPort)); } - File logConfigFile; - if (logConfig != null) - { - logConfigFile = new File(logConfig); - configureLogging(logConfigFile, logWatchTime); - } - else + String bindAddr = commandLine.getOptionValue(BrokerOptions.BIND); + if (bindAddr != null) { - File configFileDirectory = configFile.getParentFile(); - logConfigFile = new File(configFileDirectory, DEFAULT_LOG_CONFIG_FILENAME); - configureLogging(logConfigFile, logWatchTime); + options.setBind(bindAddr); } - ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile); - ServerConfiguration serverConfig = config.getConfiguration(); - updateManagementPort(serverConfig, commandLine.getOptionValue("m")); - - ApplicationRegistry.initialise(config); - - // We have already loaded the BrokerMessages class by this point so we - // need to refresh the locale setting incase we had a different value in - // the configuration. - BrokerMessages.reload(); - - // AR.initialise() sets and removes its own actor so we now need to set the actor - // for the remainder of the startup, and the default actor if the stack is empty - CurrentActor.set(new BrokerActor(config.getCompositeStartupMessageLogger())); - CurrentActor.setDefault(new BrokerActor(config.getRootMessageLogger())); - GenericActor.setDefaultMessageLogger(config.getRootMessageLogger()); - - - try + String[] portStr = commandLine.getOptionValues(BrokerOptions.PORTS); + if(portStr != null) { - configureLoggingManagementMBean(logConfigFile, logWatchTime); - - ConfigurationManagementMBean configMBean = new ConfigurationManagementMBean(); - configMBean.register(); - - ServerInformationMBean sysInfoMBean = new ServerInformationMBean(config); - sysInfoMBean.register(); - - - String[] portStr = commandLine.getOptionValues("p"); - - Set ports = new HashSet(); - Set exclude_0_10 = new HashSet(); - Set exclude_0_9_1 = new HashSet(); - Set exclude_0_9 = new HashSet(); - Set exclude_0_8 = new HashSet(); - - if(portStr == null || portStr.length == 0) - { - - parsePortList(ports, serverConfig.getPorts()); - parsePortList(exclude_0_10, serverConfig.getPortExclude010()); - parsePortList(exclude_0_9_1, serverConfig.getPortExclude091()); - parsePortList(exclude_0_9, serverConfig.getPortExclude09()); - parsePortList(exclude_0_8, serverConfig.getPortExclude08()); - - } - else - { - parsePortArray(ports, portStr); - parsePortArray(exclude_0_10, commandLine.getOptionValues("exclude-0-10")); - parsePortArray(exclude_0_9_1, commandLine.getOptionValues("exclude-0-9-1")); - parsePortArray(exclude_0_9, commandLine.getOptionValues("exclude-0-9")); - parsePortArray(exclude_0_8, commandLine.getOptionValues("exclude-0-8")); - - } - - - - - String bindAddr = commandLine.getOptionValue("b"); - if (bindAddr == null) + parsePortArray(options, portStr, false); + for(ProtocolExclusion pe : ProtocolExclusion.values()) { - bindAddr = serverConfig.getBind(); - } - InetAddress bindAddress = null; - - - - if (bindAddr.equals(WILDCARD_ADDRESS)) - { - bindAddress = new InetSocketAddress(0).getAddress(); - } - else - { - bindAddress = InetAddress.getByAddress(parseIP(bindAddr)); - } - - String hostName = bindAddress.getCanonicalHostName(); - - - String keystorePath = serverConfig.getKeystorePath(); - String keystorePassword = serverConfig.getKeystorePassword(); - String certType = serverConfig.getCertType(); - SSLContextFactory sslFactory = null; - - if (!serverConfig.getSSLOnly()) - { - - for(int port : ports) - { - Set supported = EnumSet.allOf(VERSION.class); - - if(exclude_0_10.contains(port)) - { - supported.remove(VERSION.v0_10); - } - - if(exclude_0_9_1.contains(port)) - { - supported.remove(VERSION.v0_9_1); - } - if(exclude_0_9.contains(port)) - { - supported.remove(VERSION.v0_9); - } - if(exclude_0_8.contains(port)) - { - supported.remove(VERSION.v0_8); - } - - NetworkTransportConfiguration settings = - new ServerNetworkTransportConfiguration(serverConfig, port, bindAddress.getHostName(), Transport.TCP); - - IncomingNetworkTransport transport = new MinaNetworkTransport(); - MultiVersionProtocolEngineFactory protocolEngineFactory = - new MultiVersionProtocolEngineFactory(hostName, supported); - - transport.accept(settings, protocolEngineFactory, sslFactory); - ApplicationRegistry.getInstance().addAcceptor(new InetSocketAddress(bindAddress, port), - new QpidAcceptor(transport, Transport.TCP)); - CurrentActor.get().message(BrokerMessages.LISTENING("TCP", port)); - } - + parsePortArray(options, commandLine.getOptionValues(pe.getExcludeName()), pe); } + } - if (serverConfig.getEnableSSL()) + String[] sslPortStr = commandLine.getOptionValues(BrokerOptions.SSL_PORTS); + if(sslPortStr != null) + { + parsePortArray(options, sslPortStr, true); + for(ProtocolExclusion pe : ProtocolExclusion.values()) { - String sslPort = commandLine.getOptionValue("s"); - int port = 0; - if (null != sslPort) - { - port = Integer.parseInt(sslPort); - } - else - { - port = serverConfig.getSSLPort(); - } - - NetworkTransportConfiguration settings = - new ServerNetworkTransportConfiguration(serverConfig, port, bindAddress.getHostName(), Transport.TCP); - - sslFactory = new SSLContextFactory(keystorePath, keystorePassword, certType); - - IncomingNetworkTransport transport = new MinaNetworkTransport(); - - transport.accept(settings, new AMQProtocolEngineFactory(), sslFactory); - - ApplicationRegistry.getInstance().addAcceptor(new InetSocketAddress(bindAddress, port), - new QpidAcceptor(transport,"TCP")); - CurrentActor.get().message(BrokerMessages.LISTENING("TCP/SSL", port)); + parsePortArray(options, commandLine.getOptionValues(pe.getExcludeName()), pe); } - - CurrentActor.get().message(BrokerMessages.READY()); - - } - finally - { - // Startup is complete so remove the AR initialised Startup actor - CurrentActor.remove(); } - - - + + Broker broker = new Broker(); + broker.startup(options); } - private void parsePortArray(Set ports, String[] portStr) - throws InitException + protected static void shutdown(int status) { - if(portStr != null) - { - for(int i = 0; i < portStr.length; i++) - { - try - { - ports.add(Integer.parseInt(portStr[i])); - } - catch (NumberFormatException e) - { - throw new InitException("Invalid port: " + portStr[i], e); - } - } - } + ApplicationRegistry.remove(); + System.exit(status); } - private void parsePortList(Set output, List input) - throws InitException + private static void parsePortArray(BrokerOptions options, Object[] ports, boolean ssl) throws InitException { - if(input != null) + if(ports != null) { - for(Object port : input) + for(int i = 0; i < ports.length; i++) { try { - output.add(Integer.parseInt(String.valueOf(port))); + if(ssl) + { + options.addSSLPort(Integer.parseInt(String.valueOf(ports[i]))); + } + else + { + options.addPort(Integer.parseInt(String.valueOf(ports[i]))); + } } catch (NumberFormatException e) { - throw new InitException("Invalid port: " + port, e); + throw new InitException("Invalid port: " + ports[i], e); } } } } - /** - * Update the configuration data with the management port. - * @param configuration - * @param managementPort The string from the command line - */ - private void updateManagementPort(ServerConfiguration configuration, String managementPort) - { - if (managementPort != null) - { - try - { - configuration.setJMXManagementPort(Integer.parseInt(managementPort)); - } - catch (NumberFormatException e) - { - _logger.warn("Invalid management port: " + managementPort + " will use:" + configuration.getJMXManagementPort(), e); - } - } - } - - public static void main(String[] args) - { - //if the -Dlog4j.configuration property has not been set, enable the init override - //to stop Log4J wondering off and picking up the first log4j.xml/properties file it - //finds from the classpath when we get the first Loggers - if(System.getProperty("log4j.configuration") == null) - { - System.setProperty("log4j.defaultInitOverride", "true"); - } - - //now that the override status is know, we can instantiate the Loggers - _logger = Logger.getLogger(Main.class); - - new Main(args); - } - - private byte[] parseIP(String address) throws Exception - { - char[] literalBuffer = address.toCharArray(); - int byteCount = 0; - int currByte = 0; - byte[] ip = new byte[IPV4_ADDRESS_LENGTH]; - for (int i = 0; i < literalBuffer.length; i++) - { - char currChar = literalBuffer[i]; - if ((currChar >= '0') && (currChar <= '9')) - { - currByte = (currByte * 10) + (Character.digit(currChar, 10) & 0xFF); - } - - if (currChar == IPV4_LITERAL_SEPARATOR || (i + 1 == literalBuffer.length)) - { - ip[byteCount++] = (byte) currByte; - currByte = 0; - } - } - - if (byteCount != 4) - { - throw new Exception("Invalid IP address: " + address); - } - return ip; - } - - private void configureLogging(File logConfigFile, int logWatchTime) throws InitException, IOException + private static void parsePortArray(BrokerOptions options, Object[] ports, ProtocolExclusion excludedProtocol) throws InitException { - if (logConfigFile.exists() && logConfigFile.canRead()) + if(ports != null) { - CurrentActor.get().message(BrokerMessages.LOG_CONFIG(logConfigFile.getAbsolutePath())); - - if (logWatchTime > 0) - { - System.out.println("log file " + logConfigFile.getAbsolutePath() + " will be checked for changes every " - + logWatchTime + " seconds"); - // log4j expects the watch interval in milliseconds - try - { - QpidLog4JConfigurator.configureAndWatch(logConfigFile.getPath(), logWatchTime * 1000); - } - catch (Exception e) - { - throw new InitException(e.getMessage(),e); - } - } - else + for(int i = 0; i < ports.length; i++) { try { - QpidLog4JConfigurator.configure(logConfigFile.getPath()); + options.addExcludedPort(excludedProtocol, + Integer.parseInt(String.valueOf(ports[i]))); } - catch (Exception e) - { - throw new InitException(e.getMessage(),e); - } - } - } - else - { - System.err.println("Logging configuration error: unable to read file " + logConfigFile.getAbsolutePath()); - System.err.println("Using the fallback internal log4j.properties configuration"); - - InputStream propsFile = this.getClass().getResourceAsStream("/log4j.properties"); - if(propsFile == null) - { - throw new IOException("Unable to load the fallback internal log4j.properties configuration file"); - } - else - { - try - { - Properties fallbackProps = new Properties(); - fallbackProps.load(propsFile); - PropertyConfigurator.configure(fallbackProps); - } - finally + catch (NumberFormatException e) { - propsFile.close(); + throw new InitException("Invalid port for exclusion: " + ports[i], e); } } } } - - private void configureLoggingManagementMBean(File logConfigFile, int logWatchTime) throws Exception - { - LoggingManagementMBean blm = new LoggingManagementMBean(logConfigFile.getPath(),logWatchTime); - - blm.register(); - } } Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java?rev=1143870&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java (added) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java Thu Jul 7 15:12:26 2011 @@ -0,0 +1,73 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server; + +import java.util.HashMap; +import java.util.Map; + +public enum ProtocolExclusion +{ + v0_8("exclude-0-8","--exclude-0-8"), + v0_9("exclude-0-9", "--exclude-0-9"), + v0_9_1("exclude-0-9-1", "--exclude-0-9-1"), + v0_10("exclude-0-10", "--exclude-0-10"); + + private static final Map MAP = new HashMap(); + + static + { + for(ProtocolExclusion pe : ProtocolExclusion.values()) + { + MAP.put(pe.getArg(), pe); + } + } + + private String _arg; + private String _excludeName; + + private ProtocolExclusion(final String excludeName, final String arg) + { + _excludeName = excludeName; + _arg = arg; + } + + public String getArg() + { + return _arg; + } + + public String getExcludeName() + { + return _excludeName; + } + + public static ProtocolExclusion lookup(final String arg) + { + ProtocolExclusion ex = MAP.get(arg); + + if(ex == null) + { + throw new IllegalArgumentException(arg + " is not a valid protocol exclusion"); + } + + return ex; + } +} Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java Thu Jul 7 15:12:26 2011 @@ -638,7 +638,7 @@ public class ServerConfiguration extends public List getPorts() { - return getListValue("connector.port", Collections.singletonList(DEFAULT_PORT)); + return getListValue("connector.port", Collections.singletonList(DEFAULT_PORT)); } public List getPortExclude010() @@ -696,9 +696,9 @@ public class ServerConfiguration extends return getBooleanValue("connector.ssl.sslOnly"); } - public int getSSLPort() + public List getSSLPorts() { - return getIntValue("connector.ssl.port", DEFAULT_SSL_PORT); + return getListValue("connector.ssl.port", Collections.singletonList(DEFAULT_SSL_PORT)); } public String getKeystorePath() Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java?rev=1143870&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java (added) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java Thu Jul 7 15:12:26 2011 @@ -0,0 +1,210 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server; + +import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; +import static org.apache.qpid.transport.network.Transport.TCP; +import static org.apache.qpid.transport.network.Transport.VM; +import static org.apache.qpid.server.configuration.ServerConfiguration.DEFAULT_PORT; +import static org.apache.qpid.server.configuration.ServerConfiguration.DEFAULT_JMXPORT; + +import java.util.Collections; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + + +import org.apache.qpid.test.utils.QpidTestCase; + + +public class BrokerOptionsTest extends QpidTestCase +{ + private BrokerOptions _options; + + private static final int TEST_PORT1 = 6789; + private static final int TEST_PORT2 = 6790; + + + protected void setUp() + { + _options = new BrokerOptions(); + } + + public void testDefaultPort() + { + assertEquals(Collections.emptySet(), _options.getPorts()); + } + + public void testOverriddenPort() + { + _options.addPort(TEST_PORT1); + assertEquals(Collections.singleton(TEST_PORT1), _options.getPorts()); + } + + public void testManyOverriddenPorts() + { + _options.addPort(TEST_PORT1); + _options.addPort(TEST_PORT2); + final Set expectedPorts = new HashSet(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); + assertEquals(expectedPorts, _options.getPorts()); + } + + public void testDuplicateOverriddenPortsAreSilentlyIgnored() + { + _options.addPort(TEST_PORT1); + _options.addPort(TEST_PORT2); + _options.addPort(TEST_PORT1); // duplicate - should be silently ignored + final Set expectedPorts = new HashSet(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); + assertEquals(expectedPorts, _options.getPorts()); + } + + public void testDefaultSSLPort() + { + assertEquals(Collections.emptySet(), _options.getSSLPorts()); + } + + public void testOverriddenSSLPort() + { + _options.addSSLPort(TEST_PORT1); + assertEquals(Collections.singleton(TEST_PORT1), _options.getSSLPorts()); + } + + public void testManyOverriddenSSLPorts() + { + _options.addSSLPort(TEST_PORT1); + _options.addSSLPort(TEST_PORT2); + final Set expectedPorts = new HashSet(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); + assertEquals(expectedPorts, _options.getSSLPorts()); + } + + public void testDuplicateOverriddenSSLPortsAreSilentlyIgnored() + { + _options.addSSLPort(TEST_PORT1); + _options.addSSLPort(TEST_PORT2); + _options.addSSLPort(TEST_PORT1); // duplicate - should be silently ignored + final Set expectedPorts = new HashSet(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); + assertEquals(expectedPorts, _options.getSSLPorts()); + } + + public void testDefaultConfigFile() + { + assertNull(_options.getConfigFile()); + } + + public void testOverriddenConfigFile() + { + final String testConfigFile = "etc/mytestconfig.xml"; + _options.setConfigFile(testConfigFile); + assertEquals(testConfigFile, _options.getConfigFile()); + } + + public void testDefaultLogConfigFile() + { + assertNull(_options.getLogConfigFile()); + } + + public void testOverriddenLogConfigFile() + { + final String testLogConfigFile = "etc/mytestlog4j.xml"; + _options.setLogConfigFile(testLogConfigFile); + assertEquals(testLogConfigFile, _options.getLogConfigFile()); + } + + public void testDefaultJmxPort() + { + assertNull(_options.getJmxPort()); + } + + public void testJmxPort() + { + _options.setJmxPort(TEST_PORT1); + assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPort()); + } + + public void testQpidHomeExposesSysProperty() + { + assertEquals(System.getProperty("QPID_HOME"), _options.getQpidHome()); + } + + public void testDefaultExcludesPortFor0_10() + { + assertEquals(Collections.EMPTY_SET, _options.getExcludedPorts(ProtocolExclusion.v0_10)); + } + + public void testOverriddenExcludesPortFor0_10() + { + _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1); + assertEquals(Collections.singleton(TEST_PORT1), _options.getExcludedPorts(ProtocolExclusion.v0_10)); + } + + public void testManyOverriddenExcludedPortFor0_10() + { + _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1); + _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2); + final Set expectedPorts = new HashSet(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); + assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10)); + } + + public void testDuplicatedOverriddenExcludedPortFor0_10AreSilentlyIgnored() + { + _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1); + _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2); + final Set expectedPorts = new HashSet(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2})); + assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10)); + } + + public void testDefaultBind() + { + assertNull(_options.getBind()); + } + + public void testOverriddenBind() + { + final String bind = "192.168.0.1"; + _options.setBind(bind); + assertEquals(bind, _options.getBind()); + } + + public void testDefaultLogWatchFrequency() + { + assertEquals(0L, _options.getLogWatchFrequency()); + } + + public void testOverridenLogWatchFrequency() + { + final int myFreq = 10 * 1000; + + _options.setLogWatchFrequency(myFreq); + assertEquals(myFreq, _options.getLogWatchFrequency()); + } + + public void testDefaultTransport() + { + assertEquals(TCP, _options.getTransport()); + } + + public void testOverriddenTransport() + { + _options.setTransport(VM); + + assertEquals(VM, _options.getTransport()); + } +} Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java Thu Jul 7 15:12:26 2011 @@ -59,8 +59,6 @@ public class ServerConfigurationTest ext ApplicationRegistry.remove(); } - - public void testSetJMXManagementPort() throws ConfigurationException { _serverConfig.initialise(); @@ -453,7 +451,7 @@ public class ServerConfigurationTest ext assertEquals(10, _serverConfig.getConnectorProcessors()); } - public void testGetPort() throws ConfigurationException + public void testGetPorts() throws ConfigurationException { // Check default _serverConfig.initialise(); @@ -562,17 +560,22 @@ public class ServerConfigurationTest ext assertEquals(true, _serverConfig.getSSLOnly()); } - public void testGetSSLPort() throws ConfigurationException + public void testGetSSLPorts() throws ConfigurationException { // Check default _serverConfig.initialise(); - assertEquals(8672, _serverConfig.getSSLPort()); + assertNotNull(_serverConfig.getSSLPorts()); + assertEquals(1, _serverConfig.getSSLPorts().size()); + assertEquals(ServerConfiguration.DEFAULT_SSL_PORT, _serverConfig.getSSLPorts().get(0)); + // Check value we set - _config.setProperty("connector.ssl.port", 23); + _config.setProperty("connector.ssl.port", "10"); _serverConfig = new ServerConfiguration(_config); _serverConfig.initialise(); - assertEquals(23, _serverConfig.getSSLPort()); + assertNotNull(_serverConfig.getSSLPorts()); + assertEquals(1, _serverConfig.getSSLPorts().size()); + assertEquals("10", _serverConfig.getSSLPorts().get(0)); } public void testGetKeystorePath() throws ConfigurationException @@ -651,7 +654,7 @@ public class ServerConfigurationTest ext out.close(); ServerConfiguration conf = new ServerConfiguration(fileA); conf.initialise(); - assertEquals(4235, conf.getSSLPort()); + assertEquals("4235", conf.getSSLPorts().get(0)); } public void testCombinedConfiguration() throws IOException, ConfigurationException @@ -681,7 +684,7 @@ public class ServerConfigurationTest ext ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile()); config.initialise(); - assertEquals(4235, config.getSSLPort()); // From first file, not + assertEquals("4235", config.getSSLPorts().get(0)); // From first file, not // overriden by second assertNotNull(config.getPorts()); assertEquals(1, config.getPorts().size()); Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java Thu Jul 7 15:12:26 2011 @@ -22,19 +22,29 @@ package org.apache.qpid.server.util; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.logging.NullRootMessageLogger; +import org.apache.qpid.server.logging.actors.BrokerActor; +import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabaseManager; import java.util.Properties; - public class TestApplicationRegistry extends ApplicationRegistry { + public TestApplicationRegistry(ServerConfiguration config) throws ConfigurationException { super(config); } + @Override + public void initialise() throws Exception + { + CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger())); + super.initialise(); + } + protected void createDatabaseManager(ServerConfiguration configuration) throws Exception { Properties users = new Properties(); Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java Thu Jul 7 15:12:26 2011 @@ -40,7 +40,7 @@ public class MultipleJCAProviderRegistra public void setUp() throws Exception { - _broker = VM; + _brokerType = VM; super.setUp(); } Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java Thu Jul 7 15:12:26 2011 @@ -55,7 +55,7 @@ public class MessageStatisticsConfigurat assertEquals("Incorrect vhost data", 0, vhost.getTotalDataReceived()); assertFalse("Vhost statistics should not be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 5, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 1000, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -83,7 +83,7 @@ public class MessageStatisticsConfigurat assertEquals("Incorrect vhost data", 1000, vhost.getTotalDataReceived()); assertTrue("Vhost statistics should be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 0, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 0, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -111,7 +111,7 @@ public class MessageStatisticsConfigurat assertEquals("Incorrect vhost data", 0, vhost.getTotalDataReceived()); assertFalse("Vhost statistics should not be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 0, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 0, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -139,7 +139,7 @@ public class MessageStatisticsConfigurat assertEquals("Incorrect vhost data", 1000, vhost.getTotalDataReceived()); assertTrue("Vhost statistics should be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 5, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 1000, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -167,7 +167,7 @@ public class MessageStatisticsConfigurat assertEquals("Incorrect vhost data", 1000, vhost.getTotalDataReceived()); assertTrue("Vhost statistics should be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 5, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 1000, _jmxUtils.getServerInformation().getTotalDataReceived()); Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java Thu Jul 7 15:12:26 2011 @@ -66,7 +66,7 @@ public class MessageStatisticsTest exten assertEquals("Incorrect connection total", 45, total); assertEquals("Incorrect connection data", 4500, data); } - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total", 45, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server data", 4500, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -147,7 +147,7 @@ public class MessageStatisticsTest exten assertEquals("Incorrect active connection total", 20, total); assertEquals("Incorrect active connection data", 2000, data); } - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total", 30, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server data", 3000, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -187,7 +187,7 @@ public class MessageStatisticsTest exten assertApprox("Incorrect dev vhost peak messages", 0.2d, 2.0d, dev.getPeakMessageReceiptRate()); assertApprox("Incorrect dev vhost peak data", 0.2d, 20.0d, dev.getPeakDataReceiptRate()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertApprox("Incorrect server peak messages", 0.2d, 2.0d, _jmxUtils.getServerInformation().getPeakMessageReceiptRate()); assertApprox("Incorrect server peak data", 0.2d, 20.0d, _jmxUtils.getServerInformation().getPeakDataReceiptRate()); @@ -211,7 +211,7 @@ public class MessageStatisticsTest exten assertEquals("Incorrect dev vhost total messages", 10, dev.getTotalMessagesReceived()); assertEquals("Incorrect dev vhost total data", 100, dev.getTotalDataReceived()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 20, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 200, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -224,7 +224,7 @@ public class MessageStatisticsTest exten assertEquals("Incorrect dev vhost total messages", 10, dev.getTotalMessagesReceived()); assertEquals("Incorrect dev vhost total data", 100, dev.getTotalDataReceived()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 20, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 200, _jmxUtils.getServerInformation().getTotalDataReceived()); Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java Thu Jul 7 15:12:26 2011 @@ -70,13 +70,13 @@ public class BrokerStartupTest extends A { // This logging startup code only occurs when you run a Java broker, // that broker must be started via Main so not an InVM broker. - if (isJavaBroker() && isExternalBroker()) + if (isJavaBroker() && isExternalBroker() && !isInternalBroker()) { //Remove test Log4j config from the commandline - _broker = _broker.substring(0, _broker.indexOf("-l")); + _brokerCommand = _brokerCommand.substring(0, _brokerCommand.indexOf("-l")); // Add an invalid value - _broker += " -l invalid"; + _brokerCommand += " -l invalid"; // The broker has a built in default log4j configuration set up // so if the the broker cannot load the -l value it will use default Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java Thu Jul 7 15:12:26 2011 @@ -21,6 +21,8 @@ package org.apache.qpid.server.logging; import junit.framework.AssertionFailedError; + +import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.Main; import org.apache.qpid.transport.ConnectionException; import org.apache.qpid.util.LogMonitor; @@ -151,12 +153,12 @@ public class BrokerLoggingTest extends A { // This logging startup code only occurs when you run a Java broker, // that broker must be started via Main so not an InVM broker. - if (isJavaBroker() && isExternalBroker()) + if (isJavaBroker() && isExternalBroker() && !isInternalBroker()) { String TESTID = "BRK-1007"; //Remove test Log4j config from the commandline - _broker = _broker.substring(0, _broker.indexOf("-l")); + _brokerCommand = _brokerCommand.substring(0, _brokerCommand.indexOf("-l")); startBroker(); @@ -203,7 +205,7 @@ public class BrokerLoggingTest extends A 1, findMatches(TESTID).size()); //3 - String defaultLog4j = _configFile.getParent() + "/" + Main.DEFAULT_LOG_CONFIG_FILENAME; + String defaultLog4j = System.getProperty(QPID_HOME) + "/" + BrokerOptions.DEFAULT_LOG_CONFIG_FILE; assertTrue("Log4j file(" + defaultLog4j + ") details not correctly logged:" + getMessageString(log), getMessageString(log).endsWith(defaultLog4j)); @@ -240,12 +242,11 @@ public class BrokerLoggingTest extends A */ public void testBrokerStartupCustomLog4j() throws Exception { - // This logging startup code only occurs when you run a Java broker, - // that broker must be started via Main so not an InVM broker. + // This logging startup code only occurs when you run a Java broker if (isJavaBroker() && isExternalBroker()) { // Get custom -l value used during testing for the broker startup - String customLog4j = _broker.substring(_broker.indexOf("-l") + 2); + String customLog4j = _brokerCommand.substring(_brokerCommand.indexOf("-l") + 2); String TESTID = "BRK-1007"; Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java?rev=1143870&r1=1143869&r2=1143870&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java Thu Jul 7 15:12:26 2011 @@ -80,7 +80,7 @@ public class NoLocalAfterRecoveryTest ex // Due to the problem with SingleServer delaying on all connection // attempts. So using a high retry value. - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { // Local testing suggests InVM restart takes under a second details.setProperty(BrokerDetails.OPTIONS_RETRY, "5"); --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscribe@qpid.apache.org