Timothy Bish 2014-01-31 17:23:21 -05:00
parent f4e768760f
commit da3775302c
2 changed files with 16 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import java.util.Set;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.management.ObjectName; import javax.management.ObjectName;
import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFilter; import org.apache.activemq.broker.BrokerFilter;
@ -80,6 +81,7 @@ public class StatisticsBroker extends BrokerFilter {
* @see org.apache.activemq.broker.BrokerFilter#send(org.apache.activemq.broker.ProducerBrokerExchange, * @see org.apache.activemq.broker.BrokerFilter#send(org.apache.activemq.broker.ProducerBrokerExchange,
* org.apache.activemq.command.Message) * org.apache.activemq.command.Message)
*/ */
@Override
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception {
ActiveMQDestination msgDest = messageSend.getDestination(); ActiveMQDestination msgDest = messageSend.getDestination();
ActiveMQDestination replyTo = messageSend.getReplyTo(); ActiveMQDestination replyTo = messageSend.getReplyTo();
@ -206,11 +208,13 @@ public class StatisticsBroker extends BrokerFilter {
return this.brokerView; return this.brokerView;
} }
@Override
public void start() throws Exception { public void start() throws Exception {
super.start(); super.start();
LOG.info("Starting StatisticsBroker"); LOG.info("Starting StatisticsBroker");
} }
@Override
public void stop() throws Exception { public void stop() throws Exception {
super.stop(); super.stop();
} }
@ -249,6 +253,8 @@ public class StatisticsBroker extends BrokerFilter {
protected void sendStats(ConnectionContext context, ActiveMQMapMessage msg, ActiveMQDestination replyTo) protected void sendStats(ConnectionContext context, ActiveMQMapMessage msg, ActiveMQDestination replyTo)
throws Exception { throws Exception {
msg.setPersistent(false); msg.setPersistent(false);
msg.setTimestamp(System.currentTimeMillis());
msg.setPriority((byte) javax.jms.Message.DEFAULT_PRIORITY);
msg.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE); msg.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE);
msg.setMessageId(new MessageId(this.advisoryProducerId, this.messageIdGenerator.getNextSequenceId())); msg.setMessageId(new MessageId(this.advisoryProducerId, this.messageIdGenerator.getNextSequenceId()));
msg.setDestination(replyTo); msg.setDestination(replyTo);

View File

@ -59,6 +59,8 @@ public class BrokerStatisticsPluginTest extends TestCase{
MapMessage reply = (MapMessage) consumer.receive(10*1000); MapMessage reply = (MapMessage) consumer.receive(10*1000);
assertNotNull(reply); assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements()); assertTrue(reply.getMapNames().hasMoreElements());
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
/* /*
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) { for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString(); String name = e.nextElement().toString();
@ -93,6 +95,8 @@ public class BrokerStatisticsPluginTest extends TestCase{
assertNotNull(reply); assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements()); assertTrue(reply.getMapNames().hasMoreElements());
assertEquals(0, reply.getLong("enqueueCount")); assertEquals(0, reply.getLong("enqueueCount"));
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
} }
public void testDestinationStats() throws Exception{ public void testDestinationStats() throws Exception{
@ -111,6 +115,8 @@ public class BrokerStatisticsPluginTest extends TestCase{
MapMessage reply = (MapMessage) consumer.receive(); MapMessage reply = (MapMessage) consumer.receive();
assertNotNull(reply); assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements()); assertTrue(reply.getMapNames().hasMoreElements());
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
/* /*
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) { for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString(); String name = e.nextElement().toString();
@ -137,6 +143,8 @@ public class BrokerStatisticsPluginTest extends TestCase{
MapMessage reply = (MapMessage) consumer.receive(); MapMessage reply = (MapMessage) consumer.receive();
assertNotNull(reply); assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements()); assertTrue(reply.getMapNames().hasMoreElements());
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
/*for (Enumeration e = reply.getMapNames();e.hasMoreElements();) { /*for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString(); String name = e.nextElement().toString();
@ -144,6 +152,7 @@ public class BrokerStatisticsPluginTest extends TestCase{
}*/ }*/
} }
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
broker = createBroker(); broker = createBroker();
ConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectorURIsAsMap().get("tcp")); ConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectorURIsAsMap().get("tcp"));
@ -151,6 +160,7 @@ public class BrokerStatisticsPluginTest extends TestCase{
connection.start(); connection.start();
} }
@Override
protected void tearDown() throws Exception{ protected void tearDown() throws Exception{
if (this.connection != null) { if (this.connection != null) {
this.connection.close(); this.connection.close();