activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1058490 - 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 Thu, 13 Jan 2011 10:36:06 GMT
Author: dejanb
Date: Thu Jan 13 10:36:05 2011
New Revision: 1058490

URL: http://svn.apache.org/viewvc?rev=1058490&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3100 - refactoring to support multiple service factories

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogFactory.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLogFactory.java
      - copied, changed from r1057186, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.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/AuditLogService.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=1058490&r1=1058489&r2=1058490&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
Thu Jan 13 10:36:05 2011
@@ -52,7 +52,7 @@ public class AnnotatedMBean extends Stan
     }
     audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
     if (audit) {
-        auditLog = new AuditLogService();
+        auditLog = AuditLogService.getAuditLog();
     }
   }
   

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogFactory.java?rev=1058490&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogFactory.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogFactory.java
Thu Jan 13 10:36:05 2011
@@ -0,0 +1,25 @@
+/**
+ * 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.activemq.broker.util;
+
+import java.util.List;
+
+public interface AuditLogFactory {
+
+    public List<AuditLog> getAuditLogs();
+
+}

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java?rev=1058490&r1=1058489&r2=1058490&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
Thu Jan 13 10:36:05 2011
@@ -16,26 +16,37 @@
  */
 package org.apache.activemq.broker.util;
 
-import java.util.ArrayList;
-import java.util.ServiceLoader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class AuditLogService {
 
-    private ArrayList<AuditLog> auditLogs = new ArrayList<AuditLog>();
+    private static final Log LOG = LogFactory.getLog(AuditLogService.class);
 
-    public AuditLogService() {
-        ServiceLoader<AuditLog> logs = ServiceLoader.load(AuditLog.class);
-        for (AuditLog log : logs) {
-            auditLogs.add(log);
+    private AuditLogFactory factory;
+
+    private static AuditLogService auditLog;
+
+    public static AuditLogService getAuditLog() {
+        if (auditLog == null) {
+            auditLog = new AuditLogService();
         }
-        // add default audit log if non was found
-        if (auditLogs.size() == 0) {
-            auditLogs.add(new DefaultAuditLog());
+        return auditLog;
+    }
+
+    private AuditLogService() {
+	   String auditLogFactory = System.getProperty("org.apache.activemq.audit.factory", "org.apache.activemq.broker.util.DefaultAuditLogFactory");
+       try {
+           factory = (AuditLogFactory) Class.forName(auditLogFactory).newInstance();
+       } catch (Exception e) {
+           LOG.warn("Cannot instantiate audit log factory '" + auditLogFactory + "', using
default audit log factory", e);
+           factory = new DefaultAuditLogFactory();
         }
+
     }
 
     public void log(String message) {
-        for (AuditLog log : auditLogs) {
+        for (AuditLog log : factory.getAuditLogs()) {
             log.log(message);
         }
     }

Copied: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLogFactory.java
(from r1057186, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLogFactory.java?p2=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLogFactory.java&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java&r1=1057186&r2=1058490&rev=1058490&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLogFactory.java
Thu Jan 13 10:36:05 2011
@@ -17,26 +17,28 @@
 package org.apache.activemq.broker.util;
 
 import java.util.ArrayList;
+import java.util.List;
 import java.util.ServiceLoader;
 
-public class AuditLogService {
+public class DefaultAuditLogFactory implements AuditLogFactory {
 
     private ArrayList<AuditLog> auditLogs = new ArrayList<AuditLog>();
 
-    public AuditLogService() {
+    public DefaultAuditLogFactory() {
         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());
         }
     }
 
-    public void log(String message) {
-        for (AuditLog log : auditLogs) {
-            log.log(message);
-        }
+    @Override
+    public List<AuditLog> getAuditLogs() {
+       return auditLogs;
     }
 }

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=1058490&r1=1058489&r2=1058490&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 Thu
Jan 13 10:36:05 2011
@@ -36,7 +36,9 @@ public class AuditFilter implements Filt
 
     public void init(FilterConfig filterConfig) throws ServletException {
         audit = "true".equalsIgnoreCase(System.getProperty("org.apache.activemq.audit"));
-        auditLog = new AuditLogService();
+        if (audit) {
+            auditLog = AuditLogService.getAuditLog();
+        }
     }
 
     public void destroy() {



Mime
View raw message