activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1081502 - in /activemq/trunk: activemq-core/src/main/java/org/apache/activemq/broker/ activemq-core/src/main/java/org/apache/activemq/network/ activemq-core/src/main/java/org/apache/activemq/thread/ activemq-core/src/main/java/org/apache/a...
Date Mon, 14 Mar 2011 18:24:21 GMT
Author: dejanb
Date: Mon Mar 14 18:24:21 2011
New Revision: 1081502

URL: http://svn.apache.org/viewvc?rev=1081502&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3219 - add basic support for MDC and enable broker
name to appear in log entries

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DedicatedTaskRunner.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DeterministicTaskRunner.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/PooledTaskRunner.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
    activemq/trunk/activemq-core/src/test/resources/log4j.properties
    activemq/trunk/assembly/src/release/conf/log4j.properties

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Mon Mar 14 18:24:21 2011
@@ -95,6 +95,8 @@ import org.apache.activemq.usage.SystemU
 import org.apache.activemq.util.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
 /**
  * Manages the lifecycle of an ActiveMQ Broker. A BrokerService consists of a
  * number of transport connectors, network connectors and a bunch of properties
@@ -471,6 +473,9 @@ public class BrokerService implements Se
             // throw new IllegalStateException("Allready started.");
             return;
         }
+
+        MDC.put("broker", brokerName);
+
         try {
         	if (systemExitOnShutdown && useShutdownHook) {
         		throw new ConfigurationException("'useShutdownHook' property cannot be be used
with 'systemExitOnShutdown', please turn it off (useShutdownHook=false)");
@@ -537,6 +542,8 @@ public class BrokerService implements Se
                 LOG.warn("Failed to stop broker after failure in start ", ex);
             }
             throw e;
+        } finally {
+            MDC.remove("broker");
         }
     }
 
@@ -550,7 +557,9 @@ public class BrokerService implements Se
         if (!started.get()) {
             return;
         }
-        
+
+        MDC.put("broker", brokerName);
+
         if (systemExitOnShutdown) {
         	new Thread() {
         		@Override
@@ -559,7 +568,7 @@ public class BrokerService implements Se
         		}
         	}.start();
         }
-        
+
         LOG.info("ActiveMQ Message Broker (" + getBrokerName() + ", " + brokerId + ") is
shutting down");
         removeShutdownHook();
         ServiceStopper stopper = new ServiceStopper();
@@ -578,7 +587,7 @@ public class BrokerService implements Se
             stopper.stop(broker);
             broker = null;
         }
-        
+
         if (tempDataStore != null) {
             tempDataStore.stop();
             tempDataStore = null;
@@ -624,10 +633,10 @@ public class BrokerService implements Se
             this.executor.shutdownNow();
             this.executor = null;
         }
-        
+
         this.destinationInterceptors = null;
         this.destinationFactory = null;
-        
+
         LOG.info("ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId + ")
stopped");
         synchronized (shutdownHooks) {
             for (Runnable hook : shutdownHooks) {
@@ -638,7 +647,9 @@ public class BrokerService implements Se
                 }
             }
         }
-        
+
+        MDC.remove("broker");
+
         stopper.throwFirstException();
     }
     
@@ -2100,9 +2111,11 @@ public class BrokerService implements Se
                         connector.setBrokerURL(getDefaultSocketURIString());
                     }
                     if (networkConnectorStartExecutor != null) {
+                        final Map context = MDCHelper.getCopyOfContextMap();
                         networkConnectorStartExecutor.execute(new Runnable() {
                             public void run() {
                                 try {
+                                    MDCHelper.setContextMap(context);
                                     LOG.info("Async start of " + connector);
                                     connector.start();
                                 } catch(Exception e) {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
Mon Mar 14 18:24:21 2011
@@ -90,10 +90,7 @@ import org.apache.activemq.transport.Res
 import org.apache.activemq.transport.Transport;
 import org.apache.activemq.transport.TransportDisposedIOException;
 import org.apache.activemq.transport.TransportFactory;
-import org.apache.activemq.util.IntrospectionSupport;
-import org.apache.activemq.util.MarshallingSupport;
-import org.apache.activemq.util.ServiceSupport;
-import org.apache.activemq.util.URISupport;
+import org.apache.activemq.util.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -946,10 +943,12 @@ public class TransportConnection impleme
                 cs.getContext().getStopping().set(true);
             }
             try {
+                final Map context = MDCHelper.getCopyOfContextMap();
                 getDefaultTaskRunnerFactory().execute(new Runnable(){
                     public void run() {
                         serviceLock.writeLock().lock();
                         try {
+                            MDCHelper.setContextMap(context);
                             doStop();
                         } catch (Throwable e) {
                             LOG.debug("Error occured while shutting down a connection to
'" + transport.getRemoteAddress()

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
Mon Mar 14 18:24:21 2011
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.regex.Pattern;
@@ -38,6 +39,7 @@ import org.apache.activemq.transport.Tra
 import org.apache.activemq.transport.TransportServer;
 import org.apache.activemq.transport.discovery.DiscoveryAgent;
 import org.apache.activemq.transport.discovery.DiscoveryAgentFactory;
+import org.apache.activemq.util.MDCHelper;
 import org.apache.activemq.util.ServiceStopper;
 import org.apache.activemq.util.ServiceSupport;
 import org.slf4j.Logger;
@@ -207,11 +209,13 @@ public class TransportConnector implemen
         brokerInfo.setPeerBrokerInfos(broker.getPeerBrokerInfos());
         brokerInfo.setFaultTolerantConfiguration(broker.isFaultTolerantConfiguration());
         brokerInfo.setBrokerURL(getServer().getConnectURI().toString());
+        final Map context = MDCHelper.getCopyOfContextMap();
         getServer().setAcceptListener(new TransportAcceptListener() {
             public void onAccept(final Transport transport) {
                 try {
                     getDefaultTaskRunnerFactory().execute(new Runnable() {
                         public void run() {
+                            MDCHelper.setContextMap(context);
                             try {
                                 Connection connection = createConnection(transport);
                                 connection.start();

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
Mon Mar 14 18:24:21 2011
@@ -19,10 +19,7 @@ package org.apache.activemq.network;
 import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -75,14 +72,10 @@ import org.apache.activemq.transport.Tra
 import org.apache.activemq.transport.TransportFilter;
 import org.apache.activemq.transport.TransportListener;
 import org.apache.activemq.transport.tcp.SslTransport;
-import org.apache.activemq.util.IdGenerator;
-import org.apache.activemq.util.IntrospectionSupport;
-import org.apache.activemq.util.LongSequenceGenerator;
-import org.apache.activemq.util.MarshallingSupport;
-import org.apache.activemq.util.ServiceStopper;
-import org.apache.activemq.util.ServiceSupport;
+import org.apache.activemq.util.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 /**
  * A useful base class for implementing demand forwarding bridges.
@@ -243,8 +236,10 @@ public abstract class DemandForwardingBr
     }
 
     protected void triggerLocalStartBridge() throws IOException {
+        final Map context = MDCHelper.getCopyOfContextMap();
         asyncTaskRunner.execute(new Runnable() {
             public void run() {
+                MDCHelper.setContextMap(context);
                 final String originalName = Thread.currentThread().getName();
                 Thread.currentThread().setName("StartLocalBridge: localBroker=" + localBroker);
                 try {
@@ -259,8 +254,10 @@ public abstract class DemandForwardingBr
     }
 
     protected void triggerRemoteStartBridge() throws IOException {
+        final Map context = MDCHelper.getCopyOfContextMap();
         asyncTaskRunner.execute(new Runnable() {
             public void run() {
+                MDCHelper.setContextMap(context);
                 final String originalName = Thread.currentThread().getName();
                 Thread.currentThread().setName("StartRemotelBridge: localBroker=" + localBroker);
                 try {
@@ -391,9 +388,11 @@ public abstract class DemandForwardingBr
                 try {
                     remoteBridgeStarted.set(false);
                     final CountDownLatch sendShutdown = new CountDownLatch(1);
+                    final Map map = MDCHelper.getCopyOfContextMap();
                     asyncTaskRunner.execute(new Runnable() {
                         public void run() {
                             try {
+                                MDCHelper.setContextMap(map);
                                 localBroker.oneway(new ShutdownInfo());
                                 sendShutdown.countDown();
                                 remoteBroker.oneway(new ShutdownInfo());
@@ -435,8 +434,10 @@ public abstract class DemandForwardingBr
                 LOG.warn("Network connection between " + localBroker + " and " + remoteBroker
+ " shutdown due to a remote error: " + error);
             }
             LOG.debug("The remote Exception was: " + error, error);
+            final Map map = MDCHelper.getCopyOfContextMap();
             asyncTaskRunner.execute(new Runnable() {
                 public void run() {
+                    MDCHelper.setContextMap(map);
                     ServiceSupport.dispose(getControllingService());
                 }
             });
@@ -651,8 +652,10 @@ public abstract class DemandForwardingBr
         if (!disposed.get()) {
             LOG.info("Network connection between " + localBroker + " and " + remoteBroker
+ " shutdown due to a local error: " + error);
             LOG.debug("The local Exception was:" + error, error);
+            final Map map = MDCHelper.getCopyOfContextMap();
             asyncTaskRunner.execute(new Runnable() {
                 public void run() {
+                    MDCHelper.setContextMap(map);
                     ServiceSupport.dispose(getControllingService());
                 }
             });
@@ -678,8 +681,10 @@ public abstract class DemandForwardingBr
             subscriptionMapByLocalId.remove(sub.getLocalInfo().getConsumerId());
 
             // continue removal in separate thread to free up this thread for outstanding
responses
+            final Map map = MDCHelper.getCopyOfContextMap();
             asyncTaskRunner.execute(new Runnable() {
                 public void run() {
+                    MDCHelper.setContextMap(map);
                     sub.waitForCompletion();
                     try {
                         localBroker.oneway(sub.getLocalInfo().createRemoveCommand());

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DedicatedTaskRunner.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DedicatedTaskRunner.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DedicatedTaskRunner.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DedicatedTaskRunner.java
Mon Mar 14 18:24:21 2011
@@ -16,6 +16,10 @@
  */
 package org.apache.activemq.thread;
 
+import org.apache.activemq.util.MDCHelper;
+
+import java.util.Map;
+
 /**
  * 
  */
@@ -31,8 +35,10 @@ class DedicatedTaskRunner implements Tas
 
     public DedicatedTaskRunner(Task task, String name, int priority, boolean daemon) {
         this.task = task;
+        final Map context = MDCHelper.getCopyOfContextMap();
         thread = new Thread(name) {
             public void run() {
+                MDCHelper.setContextMap(context);
                 runTask();
             }
         };

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DeterministicTaskRunner.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DeterministicTaskRunner.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DeterministicTaskRunner.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/DeterministicTaskRunner.java
Mon Mar 14 18:24:21 2011
@@ -16,6 +16,10 @@
  */
 package org.apache.activemq.thread;
 
+import org.apache.activemq.util.MDCHelper;
+import org.slf4j.MDC;
+
+import java.util.Map;
 import java.util.concurrent.Executor;
 
 /**
@@ -35,9 +39,13 @@ public class DeterministicTaskRunner imp
     public DeterministicTaskRunner(Executor executor, Task task) {
         this.executor = executor;
         this.task = task;
+        final Map context = MDCHelper.getCopyOfContextMap();
         this.runable = new Runnable() {
             public void run() {
                 Thread.currentThread();
+                if (context != null) {
+                    MDCHelper.setContextMap(context);
+                }
                 runTask();
             }
         };

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/PooledTaskRunner.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/PooledTaskRunner.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/PooledTaskRunner.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/PooledTaskRunner.java
Mon Mar 14 18:24:21 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.activemq.thread;
 
+import org.apache.activemq.util.MDCHelper;
+
+import java.util.Map;
 import java.util.concurrent.Executor;
 
 /**
@@ -36,8 +39,10 @@ class PooledTaskRunner implements TaskRu
         this.executor = executor;
         this.maxIterationsPerRun = maxIterationsPerRun;
         this.task = task;
+        final Map context = MDCHelper.getCopyOfContextMap();
         runable = new Runnable() {
             public void run() {
+                MDCHelper.setContextMap(context);
                 runningThread = Thread.currentThread();
                 try {
                     runTask();

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
Mon Mar 14 18:24:21 2011
@@ -18,6 +18,7 @@ package org.apache.activemq.transport.di
 
 import java.io.IOException;
 import java.net.URI;
+import java.util.Map;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -28,6 +29,7 @@ import org.apache.activemq.command.Disco
 import org.apache.activemq.thread.DefaultThreadPools;
 import org.apache.activemq.transport.discovery.DiscoveryAgent;
 import org.apache.activemq.transport.discovery.DiscoveryListener;
+import org.apache.activemq.util.MDCHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -110,9 +112,12 @@ public class SimpleDiscoveryAgent implem
         if (event.failed.compareAndSet(false, true)) {
 
             listener.onServiceRemove(event);
+            final Map context = MDCHelper.getCopyOfContextMap();
             DefaultThreadPools.getDefaultTaskRunnerFactory().execute(new Runnable() {
                 public void run() {
 
+                    MDCHelper.setContextMap(context);
+
                     // We detect a failed connection attempt because the service
                     // fails right
                     // away.

Modified: activemq/trunk/activemq-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/log4j.properties?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/log4j.properties (original)
+++ activemq/trunk/activemq-core/src/test/resources/log4j.properties Mon Mar 14 18:24:21 2011
@@ -30,11 +30,11 @@ log4j.rootLogger=INFO, out, stdout
 # CONSOLE appender not used by default
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-10.10X{broker} - %-5p %-30.30c{1}
- %m%n
 
 # File appender
 log4j.appender.out=org.apache.log4j.FileAppender
 log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-10.10X{broker} - %-5p %-30.30c{1}
- %m%n
 log4j.appender.out.file=target/activemq-test.log
 log4j.appender.out.append=true

Modified: activemq/trunk/assembly/src/release/conf/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/trunk/assembly/src/release/conf/log4j.properties?rev=1081502&r1=1081501&r2=1081502&view=diff
==============================================================================
--- activemq/trunk/assembly/src/release/conf/log4j.properties (original)
+++ activemq/trunk/assembly/src/release/conf/log4j.properties Mon Mar 14 18:24:21 2011
@@ -39,6 +39,8 @@ log4j.logger.org.apache.camel=INFO
 log4j.appender.console=org.apache.log4j.ConsoleAppender
 log4j.appender.console.layout=org.apache.log4j.PatternLayout
 log4j.appender.console.layout.ConversionPattern=%5p | %m%n
+# use the pattern below if you want to see mdc data, like broker name, etc
+#log4j.appender.console.layout.ConversionPattern=%5p | %-10.10X{broker} | %m%n
 log4j.appender.console.threshold=INFO
 
 # File appender
@@ -49,6 +51,8 @@ log4j.appender.logfile.maxBackupIndex=5
 log4j.appender.logfile.append=true
 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
 log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
+# use the pattern below if you want to see mdc data, like broker name, etc
+#log4j.appender.logfile.layout.ConversionPattern=%d | %-10.10X{broker} | %-5p | %m | %c |
%t%n
 
 ###########
 # Audit log



Mime
View raw message