diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 09:34:20 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 09:34:20 +0000 |
| commit | 5d8692eb57c42ddc403bfa04559464f4c8465b22 (patch) | |
| tree | c82b6bfc8a4cba421833dec28b5e8e32099c491c /qpid | |
| parent | bb4f5e794da724e2d971a6c2813c71dbdfe747cc (diff) | |
| download | qpid-python-5d8692eb57c42ddc403bfa04559464f4c8465b22.tar.gz | |
QPID-2002, QPID-2012 : Provide Broker Startup Logging using a SystemOutMessageLogger until we have loaded the main configuration and then re-initialise with that configuration
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@801567 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid')
6 files changed, 291 insertions, 48 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java index e402dd6956..34125ae25a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java @@ -20,14 +20,6 @@ */ package org.apache.qpid.server; -import java.io.File; -import java.io.IOException; -import java.net.BindException; -import java.net.InetAddress; -import java.net.InetSocketAddress; - -import javax.management.NotCompliantMBeanException; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; @@ -51,12 +43,22 @@ import org.apache.qpid.pool.ReadWriteThreadModel; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.configuration.management.ConfigurationManagementMBean; import org.apache.qpid.server.information.management.ServerInformationMBean; +import org.apache.qpid.server.logging.StartupRootMessageLogger; +import org.apache.qpid.server.logging.actors.BrokerActor; +import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.management.LoggingManagementMBean; +import org.apache.qpid.server.logging.messages.BrokerMessages; import org.apache.qpid.server.protocol.AMQPFastProtocolHandler; import org.apache.qpid.server.protocol.AMQPProtocolProvider; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; +import java.io.File; +import java.io.IOException; +import java.net.BindException; +import java.net.InetAddress; +import java.net.InetSocketAddress; + /** * Main entry point for AMQPD. * @@ -191,7 +193,9 @@ public class Main { try { + CurrentActor.set(new BrokerActor(new StartupRootMessageLogger())); startup(); + CurrentActor.remove(); } catch (InitException e) { @@ -233,7 +237,7 @@ public class Main } else { - System.out.println("Using configuration file " + configFile.getAbsolutePath()); + CurrentActor.get().message(BrokerMessages.BRK_1006(configFile.getAbsolutePath())); } String logConfig = commandLine.getOptionValue("l"); @@ -268,52 +272,62 @@ public class Main updateManagementPort(serverConfig, commandLine.getOptionValue("m")); ApplicationRegistry.initialise(config); - - configureLoggingManagementMBean(logConfigFile, logWatchTime); - ConfigurationManagementMBean configMBean = new ConfigurationManagementMBean(); - configMBean.register(); - - ServerInformationMBean sysInfoMBean = - new ServerInformationMBean(QpidProperties.getBuildVersion(), QpidProperties.getReleaseVersion()); - sysInfoMBean.register(); - - //fixme .. use QpidProperties.getVersionString when we have fixed the classpath issues - // that are causing the broker build to pick up the wrong properties file and hence say - // Starting Qpid Client - _brokerLogger.info("Starting Qpid Broker " + QpidProperties.getReleaseVersion() - + " build: " + QpidProperties.getBuildVersion()); + // AR.initialise() sets its own actor so we now need to set the actor + // for the remainder of the startup + CurrentActor.set(new BrokerActor(config.getRootMessageLogger())); + try{ + configureLoggingManagementMBean(logConfigFile, logWatchTime); - ByteBuffer.setUseDirectBuffers(serverConfig.getEnableDirectBuffers()); + ConfigurationManagementMBean configMBean = new ConfigurationManagementMBean(); + configMBean.register(); - // the MINA default is currently to use the pooled allocator although this may change in future - // once more testing of the performance of the simple allocator has been done - if (!serverConfig.getEnablePooledAllocator()) - { - ByteBuffer.setAllocator(new FixedSizeByteBufferAllocator()); - } + ServerInformationMBean sysInfoMBean = + new ServerInformationMBean(QpidProperties.getBuildVersion(), QpidProperties.getReleaseVersion()); + sysInfoMBean.register(); - if(serverConfig.getUseBiasedWrites()) - { - System.setProperty("org.apache.qpid.use_write_biased_pool","true"); - } + //fixme .. use QpidProperties.getVersionString when we have fixed the classpath issues + // that are causing the broker build to pick up the wrong properties file and hence say + // Starting Qpid Client + _brokerLogger.info("Starting Qpid Broker " + QpidProperties.getReleaseVersion() + + " build: " + QpidProperties.getBuildVersion()); - int port = serverConfig.getPort(); + ByteBuffer.setUseDirectBuffers(serverConfig.getEnableDirectBuffers()); - String portStr = commandLine.getOptionValue("p"); - if (portStr != null) - { - try + // the MINA default is currently to use the pooled allocator although this may change in future + // once more testing of the performance of the simple allocator has been done + if (!serverConfig.getEnablePooledAllocator()) { - port = Integer.parseInt(portStr); + ByteBuffer.setAllocator(new FixedSizeByteBufferAllocator()); } - catch (NumberFormatException e) + + if (serverConfig.getUseBiasedWrites()) { - throw new InitException("Invalid port: " + portStr, e); + System.setProperty("org.apache.qpid.use_write_biased_pool", "true"); } + + int port = serverConfig.getPort(); + + String portStr = commandLine.getOptionValue("p"); + if (portStr != null) + { + try + { + port = Integer.parseInt(portStr); + } + catch (NumberFormatException e) + { + throw new InitException("Invalid port: " + portStr, e); + } + } + + bind(port, serverConfig); + } + finally + { + // Startup is complete so remove the AR initialised Startup actor + CurrentActor.remove(); } - - bind(port, serverConfig); } /** diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java new file mode 100644 index 0000000000..0dffde50fa --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java @@ -0,0 +1,42 @@ +/* + * + * 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.logging; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.logging.rawloggers.SystemOutMessageLogger; + +public class StartupRootMessageLogger extends RootMessageLoggerImpl +{ + public StartupRootMessageLogger() throws ConfigurationException + { + super(new ServerConfiguration(new PropertiesConfiguration()), + new SystemOutMessageLogger()); + } + + @Override + public boolean isMessageEnabled(LogActor actor, LogSubject subject) + { + return true; + } + +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java new file mode 100644 index 0000000000..9b928accc0 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java @@ -0,0 +1,39 @@ +/* + * + * 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.logging.actors; + +import org.apache.qpid.server.logging.RootMessageLogger; + +public class BrokerActor extends AbstractActor +{ + + /** + * Create a new BrokerActor + * + * @param logger + */ + public BrokerActor(RootMessageLogger logger) + { + super(logger); + + _logString = "[Broker] "; + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java new file mode 100644 index 0000000000..b9f0532d05 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java @@ -0,0 +1,40 @@ +/* + * + * 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.logging.rawloggers; + +import org.apache.qpid.server.logging.RawMessageLogger; + +public class SystemOutMessageLogger implements RawMessageLogger +{ + public void rawMessage(String message) + { + rawMessage(message, null); + } + + public void rawMessage(String message, Throwable throwable) + { + System.out.println(message); + if (throwable != null) + { + throwable.printStackTrace(System.out); + } + } +} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java index 31a85b878a..043c048f51 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java @@ -20,11 +20,13 @@ */ package org.apache.qpid.server.registry; -import java.io.File; - import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.AMQException; import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.logging.RootMessageLoggerImpl; +import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.logging.actors.BrokerActor; +import org.apache.qpid.server.logging.rawloggers.Log4jMessageLogger; import org.apache.qpid.server.management.JMXManagedObjectRegistry; import org.apache.qpid.server.management.NoopManagedObjectRegistry; import org.apache.qpid.server.plugins.PluginManager; @@ -33,8 +35,8 @@ import org.apache.qpid.server.security.auth.database.ConfigurationFilePrincipalD import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; -import org.apache.qpid.server.logging.RootMessageLoggerImpl; -import org.apache.qpid.server.logging.rawloggers.Log4jMessageLogger; + +import java.io.File; public class ConfigurationFileApplicationRegistry extends ApplicationRegistry { @@ -48,6 +50,8 @@ public class ConfigurationFileApplicationRegistry extends ApplicationRegistry { _rootMessageLogger = new RootMessageLoggerImpl(_configuration, new Log4jMessageLogger()); + // Set the Actor for current log messages + CurrentActor.set(new BrokerActor(_rootMessageLogger)); initialiseManagedObjectRegistry(); @@ -67,6 +71,8 @@ public class ConfigurationFileApplicationRegistry extends ApplicationRegistry initialiseVirtualHosts(); + // Startup complete pop the current actor + CurrentActor.remove(); } private void initialiseVirtualHosts() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java new file mode 100644 index 0000000000..210702ff75 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java @@ -0,0 +1,102 @@ + /* + * + * 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.logging; + +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.util.LogMonitor; + +import java.io.File; +import java.util.List; + +public class BrokerLoggingTest extends AbstractTestLogging +{ + LogMonitor _monitor; + + public void setUp() throws Exception + { + // set QPID_WORK to be [QPID_WORK|io.tmpdir]/<testName> + setSystemProperty("QPID_WORK", + System.getProperty("QPID_WORK", + System.getProperty("java.io.tmpdir")) + + File.separator + getName()); + +// makeVirtualHostPersistent("test"); + + _monitor = new LogMonitor(_outputFile); + + //We explicitly do not call super.setUp as starting up the broker is + //part of the test case. + } + + /** + * Description: + * On startup the broker must report the active configuration file. The + * logging system must output this so that we can know what configuration + * is being used for this broker instance. + * + * Input: + * The value of -c specified on the command line. + * Output: + * <date> MESSAGE BRK-1006 : Using configuration : <config file> + * Constraints: + * This MUST BE the first BRK log message. + * + * Validation Steps: + * 1. This is first BRK log message. + * 2. The BRK ID is correct + * 3. The config file is the full path to the file specified on + * the commandline. + * + * @throws Exception caused by broker startup + */ + public void testBrokerStartupConfiguration() throws Exception + { + // This logging model only applies to the Java broker + if (isJavaBroker() && isExternalBroker()) + { + startBroker(); + + String configFilePath = _configFile.toString(); + + List<String> results = _monitor.findMatches("BRK-"); + + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + String log = getLog(results.get(0)); + + //1 + validateMessageID("BRK-1006",log); + + //2 + results = _monitor.findMatches("BRK-1006"); + assertEquals("More than one configuration message found.", + 1, results.size()); + + //3 + assertTrue("Config file details not correctly logged", + log.endsWith(configFilePath)); + + } + } + +} |
