mirror of https://github.com/apache/activemq.git
Added mbeans for Subscribers
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@381927 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
33b73ac71d
commit
3601e813f3
|
@ -866,7 +866,7 @@ public class BrokerService implements Service {
|
||||||
|
|
||||||
if (isUseJmx()) {
|
if (isUseJmx()) {
|
||||||
ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
|
ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
|
||||||
BrokerViewMBean view = new BrokerView(broker, managedBroker.getDestinationStatistics(), getMemoryManager());
|
BrokerViewMBean view = new BrokerView(managedBroker, getMemoryManager());
|
||||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||||
ObjectName objectName = getBrokerObjectName();
|
ObjectName objectName = getBrokerObjectName();
|
||||||
mbeanServer.registerMBean(view, objectName);
|
mbeanServer.registerMBean(view, objectName);
|
||||||
|
|
|
@ -16,19 +16,18 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.jmx;
|
package org.apache.activemq.broker.jmx;
|
||||||
|
|
||||||
|
import javax.management.ObjectName;
|
||||||
import org.apache.activemq.broker.Broker;
|
import org.apache.activemq.broker.Broker;
|
||||||
import org.apache.activemq.broker.region.DestinationStatistics;
|
import org.apache.activemq.broker.region.DestinationStatistics;
|
||||||
import org.apache.activemq.memory.UsageManager;
|
import org.apache.activemq.memory.UsageManager;
|
||||||
|
|
||||||
public class BrokerView implements BrokerViewMBean {
|
public class BrokerView implements BrokerViewMBean {
|
||||||
|
|
||||||
private final Broker broker;
|
private final ManagedRegionBroker broker;
|
||||||
private final DestinationStatistics destinationStatistics;
|
|
||||||
private final UsageManager usageManager;
|
private final UsageManager usageManager;
|
||||||
|
|
||||||
public BrokerView(Broker broker, DestinationStatistics destinationStatistics, UsageManager usageManager) {
|
public BrokerView(ManagedRegionBroker broker, UsageManager usageManager) {
|
||||||
this.broker = broker;
|
this.broker = broker;
|
||||||
this.destinationStatistics = destinationStatistics;
|
|
||||||
this.usageManager = usageManager;
|
this.usageManager = usageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,19 +48,19 @@ public class BrokerView implements BrokerViewMBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTotalEnqueueCount() {
|
public long getTotalEnqueueCount() {
|
||||||
return destinationStatistics.getEnqueues().getCount();
|
return broker.getDestinationStatistics().getEnqueues().getCount();
|
||||||
}
|
}
|
||||||
public long getTotalDequeueCount() {
|
public long getTotalDequeueCount() {
|
||||||
return destinationStatistics.getDequeues().getCount();
|
return broker.getDestinationStatistics().getDequeues().getCount();
|
||||||
}
|
}
|
||||||
public long getTotalConsumerCount() {
|
public long getTotalConsumerCount() {
|
||||||
return destinationStatistics.getConsumers().getCount();
|
return broker.getDestinationStatistics().getConsumers().getCount();
|
||||||
}
|
}
|
||||||
public long getTotalMessages() {
|
public long getTotalMessages() {
|
||||||
return destinationStatistics.getMessages().getCount();
|
return broker.getDestinationStatistics().getMessages().getCount();
|
||||||
}
|
}
|
||||||
public long getTotalMessagesCached() {
|
public long getTotalMessagesCached() {
|
||||||
return destinationStatistics.getMessagesCached().getCount();
|
return broker.getDestinationStatistics().getMessagesCached().getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMemoryPercentageUsed() {
|
public int getMemoryPercentageUsed() {
|
||||||
|
@ -75,11 +74,47 @@ public class BrokerView implements BrokerViewMBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetStatistics() {
|
public void resetStatistics() {
|
||||||
destinationStatistics.reset();
|
broker.getDestinationStatistics().reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void terminateJVM(int exitCode) {
|
public void terminateJVM(int exitCode) {
|
||||||
System.exit(exitCode);
|
System.exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getTopics(){
|
||||||
|
return broker.getTopics();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getQueues(){
|
||||||
|
return broker.getQueues();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getTemporaryTopics(){
|
||||||
|
return broker.getTemporaryTopics();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getTemporaryQueues(){
|
||||||
|
return broker.getTemporaryQueues();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getTopicSubscribers(){
|
||||||
|
return broker.getTemporaryTopicSubscribers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getDurableTopicSubscribers(){
|
||||||
|
return broker.getDurableTopicSubscribers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getQueueSubscribers(){
|
||||||
|
return broker.getQueueSubscribers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getTemporaryTopicSubscribers(){
|
||||||
|
return broker.getTemporaryTopicSubscribers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectName[] getTemporaryQueueSubscribers(){
|
||||||
|
return broker.getTemporaryQueueSubscribers();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.jmx;
|
package org.apache.activemq.broker.jmx;
|
||||||
|
|
||||||
|
import javax.management.ObjectName;
|
||||||
import org.apache.activemq.Service;
|
import org.apache.activemq.Service;
|
||||||
|
|
||||||
public interface BrokerViewMBean extends Service {
|
public interface BrokerViewMBean extends Service {
|
||||||
|
@ -37,4 +38,16 @@ public interface BrokerViewMBean extends Service {
|
||||||
|
|
||||||
public void terminateJVM(int exitCode);
|
public void terminateJVM(int exitCode);
|
||||||
|
|
||||||
|
public ObjectName[] getTopics();
|
||||||
|
public ObjectName[] getQueues();
|
||||||
|
public ObjectName[] getTemporaryTopics();
|
||||||
|
public ObjectName[] getTemporaryQueues();
|
||||||
|
|
||||||
|
public ObjectName[] getTopicSubscribers();
|
||||||
|
public ObjectName[] getDurableTopicSubscribers();
|
||||||
|
public ObjectName[] getQueueSubscribers();
|
||||||
|
public ObjectName[] getTemporaryTopicSubscribers();
|
||||||
|
public ObjectName[] getTemporaryQueueSubscribers();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.jmx;
|
||||||
|
|
||||||
|
import javax.management.openmbean.CompositeData;
|
||||||
|
import javax.management.openmbean.OpenDataException;
|
||||||
|
import javax.management.openmbean.TabularData;
|
||||||
|
import org.apache.activemq.broker.region.Subscription;
|
||||||
|
/**
|
||||||
|
* @version $Revision: 1.5 $
|
||||||
|
*/
|
||||||
|
public class DurableSubscriptionView extends SubscriptionView implements DurableSubscriptionViewMBean {
|
||||||
|
|
||||||
|
protected String subscriptionName;
|
||||||
|
public DurableSubscriptionView(Subscription sub){
|
||||||
|
super(sub);
|
||||||
|
this.subscriptionName = sub.getConsumerInfo().getSubcriptionName();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return name of the durable consumer
|
||||||
|
*/
|
||||||
|
public String getSubscriptionName(){
|
||||||
|
return subscriptionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse messages for this durable subscriber
|
||||||
|
*
|
||||||
|
* @return messages
|
||||||
|
* @throws OpenDataException
|
||||||
|
*/
|
||||||
|
public CompositeData[] browse() throws OpenDataException{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse messages for this durable subscriber
|
||||||
|
*
|
||||||
|
* @return messages
|
||||||
|
* @throws OpenDataException
|
||||||
|
*/
|
||||||
|
public TabularData browseAsTable() throws OpenDataException{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.jmx;
|
||||||
|
|
||||||
|
import javax.management.openmbean.CompositeData;
|
||||||
|
import javax.management.openmbean.OpenDataException;
|
||||||
|
import javax.management.openmbean.TabularData;
|
||||||
|
/**
|
||||||
|
* @version $Revision: 1.5 $
|
||||||
|
*/
|
||||||
|
public interface DurableSubscriptionViewMBean extends SubscriptionViewMBean{
|
||||||
|
/**
|
||||||
|
* @return name of the durable consumer
|
||||||
|
*/
|
||||||
|
public String getSubscriptionName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse messages for this durable subscriber
|
||||||
|
*
|
||||||
|
* @return messages
|
||||||
|
* @throws OpenDataException
|
||||||
|
*/
|
||||||
|
public CompositeData[] browse() throws OpenDataException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse messages for this durable subscriber
|
||||||
|
*
|
||||||
|
* @return messages
|
||||||
|
* @throws OpenDataException
|
||||||
|
*/
|
||||||
|
public TabularData browseAsTable() throws OpenDataException;
|
||||||
|
}
|
|
@ -1,21 +1,24 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2005-2006 The Apache Software Foundation
|
* Copyright 2005-2006 The Apache Software Foundation
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||||
* you may not use this file except in compliance with the License.
|
* the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
*
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* specific language governing permissions and limitations under the License.
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.jmx;
|
package org.apache.activemq.broker.jmx;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.ObjectName;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.region.Destination;
|
import org.apache.activemq.broker.region.Destination;
|
||||||
import org.apache.activemq.broker.region.Queue;
|
import org.apache.activemq.broker.region.Queue;
|
||||||
|
@ -25,78 +28,207 @@ import org.apache.activemq.broker.region.Subscription;
|
||||||
import org.apache.activemq.broker.region.Topic;
|
import org.apache.activemq.broker.region.Topic;
|
||||||
import org.apache.activemq.broker.region.policy.PolicyMap;
|
import org.apache.activemq.broker.region.policy.PolicyMap;
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
import org.apache.activemq.command.ConsumerInfo;
|
||||||
import org.apache.activemq.memory.UsageManager;
|
import org.apache.activemq.memory.UsageManager;
|
||||||
import org.apache.activemq.store.PersistenceAdapter;
|
import org.apache.activemq.store.PersistenceAdapter;
|
||||||
import org.apache.activemq.thread.TaskRunnerFactory;
|
import org.apache.activemq.thread.TaskRunnerFactory;
|
||||||
import org.apache.activemq.util.JMXSupport;
|
import org.apache.activemq.util.JMXSupport;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
import javax.management.MBeanServer;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import javax.management.ObjectName;
|
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
|
||||||
|
public class ManagedRegionBroker extends RegionBroker{
|
||||||
import java.io.IOException;
|
private static final Log log=LogFactory.getLog(ManagedRegionBroker.class);
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
public class ManagedRegionBroker extends RegionBroker {
|
|
||||||
|
|
||||||
private final MBeanServer mbeanServer;
|
private final MBeanServer mbeanServer;
|
||||||
private final ObjectName brokerObjectName;
|
private final ObjectName brokerObjectName;
|
||||||
|
private final Map topics=new ConcurrentHashMap();
|
||||||
|
private final Map queues=new ConcurrentHashMap();
|
||||||
|
private final Map temporaryQueues=new ConcurrentHashMap();
|
||||||
|
private final Map temporaryTopics=new ConcurrentHashMap();
|
||||||
|
private final Map queueSubscribers=new ConcurrentHashMap();
|
||||||
|
private final Map topicSubscribers=new ConcurrentHashMap();
|
||||||
|
private final Map durableTopicSubscribers=new ConcurrentHashMap();
|
||||||
|
private final Map temporaryQueueSubscribers=new ConcurrentHashMap();
|
||||||
|
private final Map temporaryTopicSubscribers=new ConcurrentHashMap();
|
||||||
|
|
||||||
public ManagedRegionBroker(BrokerService brokerService,MBeanServer mbeanServer, ObjectName brokerObjectName, TaskRunnerFactory taskRunnerFactory, UsageManager memoryManager, PersistenceAdapter adapter, PolicyMap policyMap) throws IOException {
|
public ManagedRegionBroker(BrokerService brokerService,MBeanServer mbeanServer,ObjectName brokerObjectName,
|
||||||
super(brokerService,taskRunnerFactory, memoryManager, adapter, policyMap);
|
TaskRunnerFactory taskRunnerFactory,UsageManager memoryManager,PersistenceAdapter adapter,
|
||||||
this.mbeanServer = mbeanServer;
|
PolicyMap policyMap) throws IOException{
|
||||||
this.brokerObjectName = brokerObjectName;
|
super(brokerService,taskRunnerFactory,memoryManager,adapter,policyMap);
|
||||||
|
this.mbeanServer=mbeanServer;
|
||||||
|
this.brokerObjectName=brokerObjectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Region createQueueRegion(UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory, PersistenceAdapter adapter, PolicyMap policyMap) {
|
protected Region createQueueRegion(UsageManager memoryManager,TaskRunnerFactory taskRunnerFactory,
|
||||||
return new ManagedQueueRegion(this, destinationStatistics, memoryManager, taskRunnerFactory, adapter, policyMap);
|
PersistenceAdapter adapter,PolicyMap policyMap){
|
||||||
}
|
return new ManagedQueueRegion(this,destinationStatistics,memoryManager,taskRunnerFactory,adapter,policyMap);
|
||||||
|
|
||||||
protected Region createTempQueueRegion(UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory) {
|
|
||||||
return new ManagedTempQueueRegion(this, destinationStatistics, memoryManager, taskRunnerFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Region createTempTopicRegion(UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory) {
|
|
||||||
return new ManagedTempTopicRegion(this, destinationStatistics, memoryManager, taskRunnerFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Region createTopicRegion(UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory, PersistenceAdapter adapter, PolicyMap policyMap) {
|
|
||||||
return new ManagedTopicRegion(this, destinationStatistics, memoryManager, taskRunnerFactory, adapter, policyMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(ActiveMQDestination destName, Destination destination) throws Throwable {
|
protected Region createTempQueueRegion(UsageManager memoryManager,TaskRunnerFactory taskRunnerFactory){
|
||||||
|
return new ManagedTempQueueRegion(this,destinationStatistics,memoryManager,taskRunnerFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Region createTempTopicRegion(UsageManager memoryManager,TaskRunnerFactory taskRunnerFactory){
|
||||||
|
return new ManagedTempTopicRegion(this,destinationStatistics,memoryManager,taskRunnerFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Region createTopicRegion(UsageManager memoryManager,TaskRunnerFactory taskRunnerFactory,
|
||||||
|
PersistenceAdapter adapter,PolicyMap policyMap){
|
||||||
|
return new ManagedTopicRegion(this,destinationStatistics,memoryManager,taskRunnerFactory,adapter,policyMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(ActiveMQDestination destName,Destination destination){
|
||||||
// Build the object name for the destination
|
// Build the object name for the destination
|
||||||
Hashtable map = new Hashtable(brokerObjectName.getKeyPropertyList());
|
Hashtable map=new Hashtable(brokerObjectName.getKeyPropertyList());
|
||||||
map.put("Type",JMXSupport.encodeObjectNamePart(destName.getDestinationTypeAsString()));
|
map.put("Type",JMXSupport.encodeObjectNamePart(destName.getDestinationTypeAsString()));
|
||||||
map.put("Destination", JMXSupport.encodeObjectNamePart(destName.getPhysicalName()));
|
map.put("Destination",JMXSupport.encodeObjectNamePart(destName.getPhysicalName()));
|
||||||
ObjectName destObjectName= new ObjectName(brokerObjectName.getDomain(), map);
|
try{
|
||||||
|
ObjectName destObjectName=new ObjectName(brokerObjectName.getDomain(),map);
|
||||||
Object view;
|
DestinationView view;
|
||||||
if( destination instanceof Queue ) {
|
if(destination instanceof Queue){
|
||||||
view = new QueueView((Queue) destination);
|
view=new QueueView((Queue) destination);
|
||||||
} else {
|
}else{
|
||||||
view = new TopicView((Topic) destination);
|
view=new TopicView((Topic) destination);
|
||||||
|
}
|
||||||
|
registerDestination(destObjectName,destName,view);
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("Failed to register destination "+destName,e);
|
||||||
}
|
}
|
||||||
|
|
||||||
mbeanServer.registerMBean(view, destObjectName);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister(ActiveMQDestination destName) throws Throwable {
|
public void unregister(ActiveMQDestination destName){
|
||||||
// Build the object name for the destination
|
// Build the object name for the destination
|
||||||
Hashtable map = new Hashtable(brokerObjectName.getKeyPropertyList());
|
Hashtable map=new Hashtable(brokerObjectName.getKeyPropertyList());
|
||||||
map.put("Type",JMXSupport.encodeObjectNamePart(destName.getDestinationTypeAsString()));
|
map.put("Type",JMXSupport.encodeObjectNamePart(destName.getDestinationTypeAsString()));
|
||||||
map.put("Destination", JMXSupport.encodeObjectNamePart(destName.getPhysicalName()));
|
map.put("Destination",JMXSupport.encodeObjectNamePart(destName.getPhysicalName()));
|
||||||
ObjectName destObjectName= new ObjectName(brokerObjectName.getDomain(), map);
|
try{
|
||||||
|
ObjectName destObjectName=new ObjectName(brokerObjectName.getDomain(),map);
|
||||||
mbeanServer.unregisterMBean(destObjectName);
|
unregisterDestination(destObjectName);
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("Failed to unregister "+destName,e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSubscription(Subscription sub) {
|
public void registerSubscription(Subscription sub){
|
||||||
// TODO: Use this to expose subscriptions to the JMX bus for management
|
Hashtable map=new Hashtable(brokerObjectName.getKeyPropertyList());
|
||||||
|
map.put("Type",JMXSupport.encodeObjectNamePart("Subscription"));
|
||||||
|
map.put("name",JMXSupport.encodeObjectNamePart(sub.getConsumerInfo().toString()));
|
||||||
|
try{
|
||||||
|
ObjectName objectName=new ObjectName(brokerObjectName.getDomain(),map);
|
||||||
|
SubscriptionView view;
|
||||||
|
if(sub.getConsumerInfo().isDurable()){
|
||||||
|
view=new DurableSubscriptionView(sub);
|
||||||
|
}else{
|
||||||
|
view=new SubscriptionView(sub);
|
||||||
|
}
|
||||||
|
registerSubscription(objectName,sub.getConsumerInfo(),view);
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("Failed to register subscription "+sub,e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterSubscription(Subscription sub) {
|
public void unregisterSubscription(Subscription sub){
|
||||||
// TODO: Use this to expose subscriptions to the JMX bus for management
|
Hashtable map=new Hashtable(brokerObjectName.getKeyPropertyList());
|
||||||
|
map.put("Type",JMXSupport.encodeObjectNamePart("Subscription"));
|
||||||
|
map.put("name",JMXSupport.encodeObjectNamePart(sub.getConsumerInfo().toString()));
|
||||||
|
try{
|
||||||
|
ObjectName objectName=new ObjectName(brokerObjectName.getDomain(),map);
|
||||||
|
unregisterSubscription(objectName);
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("Failed to unregister subscription "+sub,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerDestination(ObjectName key,ActiveMQDestination dest,DestinationView view) throws Exception{
|
||||||
|
if(dest.isQueue()){
|
||||||
|
if(dest.isTemporary()){
|
||||||
|
temporaryQueues.put(key,view);
|
||||||
|
}else{
|
||||||
|
queues.put(key,view);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(dest.isTemporary()){
|
||||||
|
temporaryTopics.put(key,view);
|
||||||
|
}else{
|
||||||
|
topics.put(key,view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mbeanServer.registerMBean(view,key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unregisterDestination(ObjectName key) throws Exception{
|
||||||
|
topics.remove(key);
|
||||||
|
queues.remove(key);
|
||||||
|
temporaryQueues.remove(key);
|
||||||
|
temporaryTopics.remove(key);
|
||||||
|
mbeanServer.unregisterMBean(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerSubscription(ObjectName key,ConsumerInfo info,SubscriptionView view) throws Exception{
|
||||||
|
ActiveMQDestination dest=info.getDestination();
|
||||||
|
if(dest.isQueue()){
|
||||||
|
if(dest.isTemporary()){
|
||||||
|
temporaryQueueSubscribers.put(key,view);
|
||||||
|
}else{
|
||||||
|
queueSubscribers.put(key,view);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(dest.isTemporary()){
|
||||||
|
temporaryTopicSubscribers.put(key,view);
|
||||||
|
}else{
|
||||||
|
if(info.isDurable()){
|
||||||
|
durableTopicSubscribers.put(key,view);
|
||||||
|
}else{
|
||||||
|
topicSubscribers.put(key,view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mbeanServer.registerMBean(view,key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unregisterSubscription(ObjectName key) throws Exception{
|
||||||
|
queueSubscribers.remove(key);
|
||||||
|
topicSubscribers.remove(key);
|
||||||
|
durableTopicSubscribers.remove(key);
|
||||||
|
temporaryQueueSubscribers.remove(key);
|
||||||
|
temporaryTopicSubscribers.remove(key);
|
||||||
|
mbeanServer.unregisterMBean(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ObjectName[] getTopics(){
|
||||||
|
Set set = topics.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getQueues(){
|
||||||
|
Set set = queues.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getTemporaryTopics(){
|
||||||
|
Set set = temporaryTopics.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getTemporaryQueues(){
|
||||||
|
Set set = temporaryQueues.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ObjectName[] getTopicSubscribers(){
|
||||||
|
Set set = topicSubscribers.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getDurableTopicSubscribers(){
|
||||||
|
Set set = durableTopicSubscribers.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getQueueSubscribers(){
|
||||||
|
Set set = queueSubscribers.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getTemporaryTopicSubscribers(){
|
||||||
|
Set set = temporaryTopicSubscribers.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
|
}
|
||||||
|
protected ObjectName[] getTemporaryQueueSubscribers(){
|
||||||
|
Set set = temporaryQueueSubscribers.keySet();
|
||||||
|
return (ObjectName[])set.toArray(new ObjectName[set.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
154
activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java
Executable file
154
activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java
Executable file
|
@ -0,0 +1,154 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.jmx;
|
||||||
|
|
||||||
|
import org.apache.activemq.broker.region.Subscription;
|
||||||
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
import org.apache.activemq.command.ConsumerInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version $Revision: 1.5 $
|
||||||
|
*/
|
||||||
|
public class SubscriptionView implements SubscriptionViewMBean {
|
||||||
|
|
||||||
|
|
||||||
|
protected final Subscription subscription;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructior
|
||||||
|
* @param subs
|
||||||
|
*/
|
||||||
|
public SubscriptionView(Subscription subs){
|
||||||
|
this.subscription = subs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id of the Connection the Subscription is on
|
||||||
|
*/
|
||||||
|
public String getConnectionId(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
return info.getConsumerId().getConnectionId();
|
||||||
|
}
|
||||||
|
return "NOTSET";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id of the Session the subscription is on
|
||||||
|
*/
|
||||||
|
public long getSessionId(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
return info.getConsumerId().getSessionId();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id of the Subscription
|
||||||
|
*/
|
||||||
|
public long getSubcriptionId(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
return info.getConsumerId().getValue();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the destination name
|
||||||
|
*/
|
||||||
|
public String getDestinationName(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
ActiveMQDestination dest = info.getDestination();
|
||||||
|
return dest.getPhysicalName();
|
||||||
|
}
|
||||||
|
return "NOTSET";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the destination is a Queue
|
||||||
|
*/
|
||||||
|
public boolean isDestinationQueue(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
ActiveMQDestination dest = info.getDestination();
|
||||||
|
return dest.isQueue();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true of the destination is a Topic
|
||||||
|
*/
|
||||||
|
public boolean isDestinationTopic(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
ActiveMQDestination dest = info.getDestination();
|
||||||
|
return dest.isTopic();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the destination is temporary
|
||||||
|
*/
|
||||||
|
public boolean isDestinationTemporary(){
|
||||||
|
ConsumerInfo info = subscription.getConsumerInfo();
|
||||||
|
if (info != null){
|
||||||
|
ActiveMQDestination dest = info.getDestination();
|
||||||
|
return dest.isTemporary();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subscription should release as may references as it can to help the garbage collector
|
||||||
|
* reclaim memory.
|
||||||
|
*/
|
||||||
|
public void gc(){
|
||||||
|
subscription.gc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages pending delivery
|
||||||
|
*/
|
||||||
|
public int getPending(){
|
||||||
|
return subscription.pending();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages dispatched
|
||||||
|
*/
|
||||||
|
public int getDispatched(){
|
||||||
|
return subscription.dispatched();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages delivered
|
||||||
|
*/
|
||||||
|
public int getDelivered(){
|
||||||
|
return subscription.delivered();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.jmx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version $Revision: 1.5 $
|
||||||
|
*/
|
||||||
|
public interface SubscriptionViewMBean{
|
||||||
|
/**
|
||||||
|
* @return the id of the Connection the Subscription is on
|
||||||
|
*/
|
||||||
|
public String getConnectionId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id of the Session the subscription is on
|
||||||
|
*/
|
||||||
|
public long getSessionId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id of the Subscription
|
||||||
|
*/
|
||||||
|
public long getSubcriptionId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the destination name
|
||||||
|
*/
|
||||||
|
public String getDestinationName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the destination is a Queue
|
||||||
|
*/
|
||||||
|
public boolean isDestinationQueue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true of the destination is a Topic
|
||||||
|
*/
|
||||||
|
public boolean isDestinationTopic();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the destination is temporary
|
||||||
|
*/
|
||||||
|
public boolean isDestinationTemporary();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subscription should release as may references as it can to help the garbage collector reclaim memory.
|
||||||
|
*/
|
||||||
|
public void gc();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages pending delivery
|
||||||
|
*/
|
||||||
|
public int getPending();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages dispatched
|
||||||
|
*/
|
||||||
|
public int getDispatched();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages delivered
|
||||||
|
*/
|
||||||
|
public int getDelivered();
|
||||||
|
}
|
|
@ -122,6 +122,16 @@ public class DurableTopicSubscription extends PrefetchSubscription {
|
||||||
super.add(node);
|
super.add(node);
|
||||||
node.decrementReferenceCount();
|
node.decrementReferenceCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int pending(){
|
||||||
|
if (active){
|
||||||
|
return super.pending();
|
||||||
|
}
|
||||||
|
//TODO: need to get from store
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean canDispatch(MessageReference node) {
|
protected boolean canDispatch(MessageReference node) {
|
||||||
return active;
|
return active;
|
||||||
|
|
|
@ -225,6 +225,18 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
|
||||||
protected boolean isFull(){
|
protected boolean isFull(){
|
||||||
return dispatched.size()-delivered>=info.getPrefetchSize()||preLoadSize>preLoadLimit;
|
return dispatched.size()-delivered>=info.getPrefetchSize()||preLoadSize>preLoadLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int pending(){
|
||||||
|
return matched.size() - dispatched.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int dispatched(){
|
||||||
|
return dispatched.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int delivered(){
|
||||||
|
return delivered;
|
||||||
|
}
|
||||||
|
|
||||||
protected void dispatchMatched() throws IOException{
|
protected void dispatchMatched() throws IOException{
|
||||||
if(!dispatching){
|
if(!dispatching){
|
||||||
|
|
|
@ -100,4 +100,19 @@ public interface Subscription {
|
||||||
*/
|
*/
|
||||||
boolean isSlaveBroker();
|
boolean isSlaveBroker();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages pending delivery
|
||||||
|
*/
|
||||||
|
int pending();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages dispatched
|
||||||
|
*/
|
||||||
|
int dispatched();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return number of messages delivered
|
||||||
|
*/
|
||||||
|
int delivered();
|
||||||
|
|
||||||
}
|
}
|
|
@ -110,6 +110,18 @@ public class TopicSubscription extends AbstractSubscription {
|
||||||
throw new JMSException("Invalid acknowledgment: "+ack);
|
throw new JMSException("Invalid acknowledgment: "+ack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int pending(){
|
||||||
|
return matched.size() - dispatched;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int dispatched(){
|
||||||
|
return dispatched;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int delivered(){
|
||||||
|
return delivered;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isFull() {
|
private boolean isFull() {
|
||||||
return dispatched-delivered >= info.getPrefetchSize();
|
return dispatched-delivered >= info.getPrefetchSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,15 +104,15 @@ class TopicBridge extends DestinationBridge{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the consumerName.
|
* @return Returns the subscriptionName.
|
||||||
*/
|
*/
|
||||||
public String getConsumerName(){
|
public String getConsumerName(){
|
||||||
return consumerName;
|
return consumerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param consumerName
|
* @param subscriptionName
|
||||||
* The consumerName to set.
|
* The subscriptionName to set.
|
||||||
*/
|
*/
|
||||||
public void setConsumerName(String consumerName){
|
public void setConsumerName(String consumerName){
|
||||||
this.consumerName=consumerName;
|
this.consumerName=consumerName;
|
||||||
|
|
Loading…
Reference in New Issue