mirror of https://github.com/apache/activemq.git
added a helper class to make writing new broker plugins easier (its just one POJO) together with adding a simple LoggingBrokerPlugin
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@412801 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
51daeeeeda
commit
bf310ef475
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Some utility Broker Plugins
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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 -->
|
Loading…
Reference in New Issue