Author: jstrachan
Date: Thu Jun 8 10:01:53 2006
New Revision: 412801
URL: http://svn.apache.org/viewvc?rev=412801&view=rev
Log:
added a helper class to make writing new broker plugins easier (its just one
POJO) together with adding a simple LoggingBrokerPlugin
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
(with props)
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
(with props)
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
(with props)
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
(with props)
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
(with props)
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java?rev=412801&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
(added)
+++
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
Thu Jun 8 10:01:53 2006
@@ -0,0 +1,35 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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;
+
+/**
+ * A useful base class for implementing broker plugins.
+ *
+ * @version $Revision$
+ */
+public abstract class BrokerPluginSupport extends MutableBrokerFilter
implements BrokerPlugin {
+
+ public BrokerPluginSupport() {
+ super(null);
+ }
+
+ public Broker installPlugin(Broker broker) throws Exception {
+ setNext(broker);
+ return this;
+ }
+
+}
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerPluginSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java?rev=412801&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
(added)
+++
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
Thu Jun 8 10:01:53 2006
@@ -0,0 +1,95 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.activemq.broker.BrokerPluginSupport;
+import org.apache.activemq.broker.ConnectionContext;
+import org.apache.activemq.command.Message;
+import org.apache.activemq.command.MessageAck;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A simple Broker interceptor which allows you to enable/disable logging.
+ *
+ * @org.apache.xbean.XBean
+ *
+ * @version $Revision$
+ */
+public class LoggingBrokerPlugin extends BrokerPluginSupport {
+
+ private Log log = LogFactory.getLog(LoggingBrokerPlugin.class);
+ private Log sendLog;
+ private Log ackLog;
+
+ public void send(ConnectionContext context, Message messageSend) throws
Exception {
+ if (sendLog == null) {
+ sendLog = createLog("Send");
+ }
+ if (sendLog.isInfoEnabled()) {
+ sendLog.info("Sending: " + messageSend);
+ }
+ super.send(context, messageSend);
+ }
+
+ public void acknowledge(ConnectionContext context, MessageAck ack) throws
Exception {
+ if (ackLog == null) {
+ ackLog = createLog("Ack");
+ }
+ if (ackLog.isInfoEnabled()) {
+ ackLog.info("Acknowledge: " + ack);
+ }
+ super.acknowledge(context, ack);
+ }
+
+ // Properties
+ //
-------------------------------------------------------------------------
+ public Log getAckLog() {
+ return ackLog;
+ }
+
+ public void setAckLog(Log ackLog) {
+ this.ackLog = ackLog;
+ }
+
+ public Log getLog() {
+ return log;
+ }
+
+ public void setLog(Log log) {
+ this.log = log;
+ }
+
+ public Log getSendLog() {
+ return sendLog;
+ }
+
+ public void setSendLog(Log sendLog) {
+ this.sendLog = sendLog;
+ }
+
+ // Implementation methods
+ //
-------------------------------------------------------------------------
+
+ /**
+ * Lazily creates a new child log
+ */
+ protected Log createLog(String name) {
+ return LogFactory.getLog(log.toString() + "." + name);
+ }
+
+}
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html?rev=412801&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
(added)
+++
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
Thu Jun 8 10:01:53 2006
@@ -0,0 +1,9 @@
+<html>
+<head>
+</head>
+<body>
+
+Some utility Broker Plugins
+
+</body>
+</html>
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/package.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added:
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java?rev=412801&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
(added)
+++
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
Thu Jun 8 10:01:53 2006
@@ -0,0 +1,55 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.test.JmsTopicSendReceiveTest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.net.URI;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class LoggingBrokerTest extends JmsTopicSendReceiveTest {
+ private static final Log log = LogFactory.getLog(LoggingBrokerTest.class);
+ private BrokerService broker;
+
+ protected void setUp() throws Exception {
+ broker = createBroker();
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (broker != null) {
+ broker.stop();
+ }
+ }
+
+ protected BrokerService createBroker() throws Exception {
+ return createBroker("org/apache/activemq/util/logging-broker.xml");
+ }
+
+ protected BrokerService createBroker(String uri) throws Exception {
+ log.info("Loading broker configuration from the classpath with URI: "
+ uri);
+ return BrokerFactory.createBroker(new URI("xbean:" + uri));
+ }
+}
Propchange:
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/util/LoggingBrokerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml?rev=412801&view=auto
==============================================================================
---
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
(added)
+++
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
Thu Jun 8 10:01:53 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2005-2006 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!-- this file can only be parsed using the xbean-spring library -->
+<!-- START SNIPPET: xbean -->
+<beans>
+ <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <broker useJmx="false" persistent="false"
xmlns="http://activemq.org/config/1.0">
+
+ <plugins>
+
+ <!-- lets enable detailed logging in the broker -->
+ <loggingBrokerPlugin/>
+
+ </plugins>
+ </broker>
+
+</beans>
+<!-- END SNIPPET: xbean -->
Propchange:
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/util/logging-broker.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml