activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1052501 - in /activemq/trunk: activemq-core/src/main/java/org/apache/activemq/broker/jmx/ activemq-core/src/main/java/org/apache/activemq/broker/util/ activemq-web/src/main/java/org/apache/activemq/web/
Date Fri, 24 Dec 2010 13:09:27 GMT
Author: dejanb
Date: Fri Dec 24 13:09:27 2010
New Revision: 1052501

URL: http://svn.apache.org/viewvc?rev=1052501&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3100 - refactoring to use ServiceLoader

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
      - copied, changed from r1052261, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
    activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java?rev=1052501&r1=1052500&r2=1052501&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
Fri Dec 24 13:09:27 2010
@@ -17,6 +17,7 @@
 package org.apache.activemq.broker.jmx;
 
 import org.apache.activemq.broker.util.AuditLog;
+import org.apache.activemq.broker.util.AuditLogService;
 import org.apache.activemq.broker.util.DefaultAuditLog;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -42,7 +43,7 @@ public class AnnotatedMBean extends Stan
   private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
 
   private static boolean audit;
-  private static AuditLog auditLog;
+  private static AuditLogService auditLog;
 
   static {
     Class<?>[] p = { byte.class, short.class, int.class, long.class, float.class, double.class,
char.class, boolean.class, };
@@ -50,7 +51,9 @@ public class AnnotatedMBean extends Stan
       primitives.put(c.getName(), c);
     }
     audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
-    auditLog = DefaultAuditLog.getAuditLog();
+    if (audit) {
+        auditLog = new AuditLogService();
+    }
   }
   
   @SuppressWarnings("unchecked")

Copied: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
(from r1052261, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java?p2=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java&r1=1052261&r2=1052501&rev=1052501&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
Fri Dec 24 13:09:27 2010
@@ -16,26 +16,27 @@
  */
 package org.apache.activemq.broker.util;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.util.ArrayList;
+import java.util.ServiceLoader;
 
-public class DefaultAuditLog implements AuditLog {
+public class AuditLogService {
 
-    private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
+    private ArrayList<AuditLog> auditLogs = new ArrayList<AuditLog>();
 
-    public static AuditLog getAuditLog() {
-        String auditLogClass = System.getProperty("org.apache.activemq.audit.class", "org.apache.activemq.broker.util.DefaultAuditLog");
-        AuditLog log;
-        try {
-            log = (AuditLog) Class.forName(auditLogClass).newInstance();
-        } catch (Exception e) {
-            LOG.warn("Cannot instantiate audit log class '" + auditLogClass + "', using default
audit log", e);
-            log = new DefaultAuditLog();
+    public AuditLogService() {
+        ServiceLoader<AuditLog> logs = ServiceLoader.load(AuditLog.class);
+        for (AuditLog log : logs) {
+            auditLogs.add(log);
+        }
+        // add default audit log if non was found
+        if (auditLogs.size() == 0) {
+            auditLogs.add(new DefaultAuditLog());
         }
-        return log;
     }
 
     public void log(String message) {
-         LOG.info(message);
+        for (AuditLog log : auditLogs) {
+            log.log(message);
+        }
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java?rev=1052501&r1=1052500&r2=1052501&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
Fri Dec 24 13:09:27 2010
@@ -23,18 +23,6 @@ public class DefaultAuditLog implements 
 
     private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
 
-    public static AuditLog getAuditLog() {
-        String auditLogClass = System.getProperty("org.apache.activemq.audit.class", "org.apache.activemq.broker.util.DefaultAuditLog");
-        AuditLog log;
-        try {
-            log = (AuditLog) Class.forName(auditLogClass).newInstance();
-        } catch (Exception e) {
-            LOG.warn("Cannot instantiate audit log class '" + auditLogClass + "', using default
audit log", e);
-            log = new DefaultAuditLog();
-        }
-        return log;
-    }
-
     public void log(String message) {
          LOG.info(message);
     }

Modified: activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java?rev=1052501&r1=1052500&r2=1052501&view=diff
==============================================================================
--- activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java (original)
+++ activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java Fri
Dec 24 13:09:27 2010
@@ -17,6 +17,7 @@
 package org.apache.activemq.web;
 
 import org.apache.activemq.broker.util.AuditLog;
+import org.apache.activemq.broker.util.AuditLogService;
 import org.apache.activemq.broker.util.DefaultAuditLog;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -31,11 +32,11 @@ public class AuditFilter implements Filt
     private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
 
     private boolean audit;
-    private AuditLog auditLog;
+    private AuditLogService auditLog;
 
     public void init(FilterConfig filterConfig) throws ServletException {
         audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
-        auditLog = DefaultAuditLog.getAuditLog();
+        auditLog = new AuditLogService();
     }
 
     public void destroy() {



Mime
View raw message