You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2009/08/06 11:34:20 UTC

svn commit: r801567 - in /qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/ broker/src/main/java/org/apache/qpid/server/logging/ broker/src/main/java/org/apache/qpid/server/logging/actors/ broker/src/main/java/org/apache/qpid/server/lo...

Author: ritchiem
Date: Thu Aug  6 09:34:20 2009
New Revision: 801567

URL: http://svn.apache.org/viewvc?rev=801567&view=rev
Log:
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

Added:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
Modified:
    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/registry/ConfigurationFileApplicationRegistry.java

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=801567&r1=801566&r2=801567&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 Aug  6 09:34:20 2009
@@ -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.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 @@
         {
             try
             {
+                CurrentActor.set(new BrokerActor(new StartupRootMessageLogger()));
                 startup();
+                CurrentActor.remove();
             }
             catch (InitException e)
             {
@@ -233,7 +237,7 @@
         }
         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 @@
         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());
-
-        ByteBuffer.setUseDirectBuffers(serverConfig.getEnableDirectBuffers());
 
-        // 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());
-        }
+        // 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);
+
+            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());
 
-        if(serverConfig.getUseBiasedWrites())
-        {
-            System.setProperty("org.apache.qpid.use_write_biased_pool","true");
-        }
+            ByteBuffer.setUseDirectBuffers(serverConfig.getEnableDirectBuffers());
 
-        int port = serverConfig.getPort();
+            // 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());
+            }
 
-        String portStr = commandLine.getOptionValue("p");
-        if (portStr != null)
-        {
-            try
+            if (serverConfig.getUseBiasedWrites())
             {
-                port = Integer.parseInt(portStr);
+                System.setProperty("org.apache.qpid.use_write_biased_pool", "true");
             }
-            catch (NumberFormatException e)
+
+            int port = serverConfig.getPort();
+
+            String portStr = commandLine.getOptionValue("p");
+            if (portStr != null)
             {
-                throw new InitException("Invalid port: " + portStr, e);
+                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);
     }
 
     /**

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java?rev=801567&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java (added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/StartupRootMessageLogger.java Thu Aug  6 09:34:20 2009
@@ -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;
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java?rev=801567&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java (added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/BrokerActor.java Thu Aug  6 09:34:20 2009
@@ -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] ";
+    }
+}

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java?rev=801567&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java (added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/rawloggers/SystemOutMessageLogger.java Thu Aug  6 09:34:20 2009
@@ -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);
+        }
+    }
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java?rev=801567&r1=801566&r2=801567&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java Thu Aug  6 09:34:20 2009
@@ -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.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 @@
     {
         _rootMessageLogger = new RootMessageLoggerImpl(_configuration, 
                                                        new Log4jMessageLogger());
+        // Set the Actor for current log messages
+        CurrentActor.set(new BrokerActor(_rootMessageLogger));
 
         initialiseManagedObjectRegistry();
 
@@ -67,6 +71,8 @@
 
         initialiseVirtualHosts();
 
+        // Startup complete pop the current actor 
+        CurrentActor.remove();
     }
 
     private void initialiseVirtualHosts() throws Exception

Added: 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=801567&view=auto
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java (added)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java Thu Aug  6 09:34:20 2009
@@ -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));
+
+        }
+    }
+
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org