@Override public ObjectName createDurableSubscriber(String clientId, String subscriberName, String topicName, String selector) throws Exception { ConnectionContext context = getConnectionContext(); context.setBroker(safeGetBroker()); context.setClientId(clientId); ConsumerInfo info = new ConsumerInfo(); ConsumerId consumerId = new ConsumerId(); consumerId.setConnectionId(clientId); consumerId.setSessionId(sessionIdCounter.incrementAndGet()); consumerId.setValue(0); info.setConsumerId(consumerId); info.setDestination(new ActiveMQTopic(topicName)); info.setSubscriptionName(subscriberName); info.setSelector(selector); Subscription subscription = safeGetBroker().addConsumer(context, info); safeGetBroker().removeConsumer(context, info); if (subscription != null) { return subscription.getObjectName(); } return null; }
protected void buildExistingSubscriptions() throws Exception { Map<SubscriptionKey, SubscriptionInfo> subscriptions = new HashMap<SubscriptionKey, SubscriptionInfo>(); Set<ActiveMQDestination> destinations = destinationFactory.getDestinations(); if (destinations != null) { for (ActiveMQDestination dest : destinations) { if (dest.isTopic()) { SubscriptionInfo[] infos = destinationFactory.getAllDurableSubscriptions((ActiveMQTopic)dest); if (infos != null) { for (int i = 0; i < infos.length; i++) { SubscriptionInfo info = infos[i]; SubscriptionKey key = new SubscriptionKey(info); if (!alreadyKnown(key)) { LOG.debug("Restoring durable subscription MBean {}", info); subscriptions.put(key, info); } } } } } } for (Map.Entry<SubscriptionKey, SubscriptionInfo> entry : subscriptions.entrySet()) { addInactiveSubscription(entry.getKey(), entry.getValue(), null); } }
/** * Browse messages for this durable subscriber * * @return messages * @throws OpenDataException */ @Override public CompositeData[] browse() throws OpenDataException { return broker.browse(this); }
@Override public List<HealthStatus> healthList() throws Exception { List<HealthStatus> answer = new ArrayList<HealthStatus>(); Map<ObjectName, DestinationView> queueViews = broker.getQueueViews(); for (Map.Entry<ObjectName, DestinationView> entry : queueViews.entrySet()) { DestinationView queue = entry.getValue(); BrokerService brokerService = broker.getBrokerService(); if (brokerService != null && brokerService.getPersistenceAdapter() != null) { PersistenceAdapter adapter = brokerService.getPersistenceAdapter();
@Override public int getPercentageBlocked() { ProducerBrokerExchange producerBrokerExchange = broker.getBrokerService().getProducerBrokerExchange(info); if (producerBrokerExchange != null){ return producerBrokerExchange.getPercentageBlocked(); } return 0; }
info.setDestination(sub.getConsumerInfo().getDestination()); info.setSelector(sub.getSelector()); addInactiveSubscription(key, info, sub); } else { String userName = brokerService.isPopulateUserNameInMBeans() ? context.getUserName() : null; registerSubscription(objectName, sub.getConsumerInfo(), key, view);
/** * Browse messages for this durable subscriber * * @return messages * @throws OpenDataException */ @Override public TabularData browseAsTable() throws OpenDataException { return broker.browseAsTable(this); }
@Override public String getBrokerName() { return safeGetBroker().getBrokerName(); }
public ObjectName registerSubscription(ConnectionContext context, Subscription sub) { String connectionClientId = context.getClientId(); ObjectName brokerJmxObjectName = brokerObjectName; String objectNameStr = getSubscriptionObjectName(sub, connectionClientId, brokerJmxObjectName); SubscriptionKey key = new SubscriptionKey(context.getClientId(), sub.getConsumerInfo().getSubscriptionName()); try { info.setSubscriptionName(sub.getConsumerInfo().getSubscriptionName()); info.setDestination(sub.getConsumerInfo().getDestination()); addInactiveSubscription(key, info); } else { if (sub.getConsumerInfo().isDurable()) { registerSubscription(objectName, sub.getConsumerInfo(), key, view);
@Override public void start() throws Exception { super.start(); // build all existing durable subscriptions buildExistingSubscriptions(); }
@Override public String getBrokerId() { return safeGetBroker().getBrokerId().toString(); }
protected Broker createRegionBroker(DestinationInterceptor destinationInterceptor) throws IOException { RegionBroker regionBroker; if (isUseJmx()) { try { regionBroker = new ManagedRegionBroker(this, getManagementContext(), getBrokerObjectName(), getTaskRunnerFactory(), getConsumerSystemUsage(), destinationFactory, destinationInterceptor,getScheduler(),getExecutor()); } catch(MalformedObjectNameException me){ LOG.warn("Cannot create ManagedRegionBroker due " + me.getMessage(), me); throw new IOException(me); } } else { regionBroker = new RegionBroker(this, getTaskRunnerFactory(), getConsumerSystemUsage(), destinationFactory, destinationInterceptor,getScheduler(),getExecutor()); } destinationFactory.setRegionBroker(regionBroker); regionBroker.setKeepDurableSubsActive(keepDurableSubsActive); regionBroker.setBrokerName(getBrokerName()); regionBroker.getDestinationStatistics().setEnabled(enableStatistics); regionBroker.setAllowTempAutoCreationOnSend(isAllowTempAutoCreationOnSend()); if (brokerId != null) { regionBroker.setBrokerId(brokerId); } return regionBroker; }
protected void unregisterSubscription(ObjectName key, boolean addToInactive) throws Exception { queueSubscribers.remove(key); topicSubscribers.remove(key); temporaryQueueSubscribers.remove(key); temporaryTopicSubscribers.remove(key); if (registeredMBeans.remove(key)) { try { managementContext.unregisterMBean(key); } catch (Throwable e) { LOG.warn("Failed to unregister MBean {}", key); LOG.debug("Failure reason: ", e); } } DurableSubscriptionView view = (DurableSubscriptionView)durableTopicSubscribers.remove(key); if (view != null) { // need to put this back in the inactive list SubscriptionKey subscriptionKey = new SubscriptionKey(view.getClientId(), view.getSubscriptionName()); if (addToInactive) { SubscriptionInfo info = new SubscriptionInfo(); info.setClientId(subscriptionKey.getClientId()); info.setSubscriptionName(subscriptionKey.getSubscriptionName()); info.setDestination(new ActiveMQTopic(view.getDestinationName())); info.setSelector(view.getSelector()); addInactiveSubscription(subscriptionKey, info, (brokerService.isKeepDurableSubsActive() ? view.subscription : null)); } } }
public ObjectName[] getSubscriptions() throws IOException, MalformedObjectNameException { List<Subscription> subscriptions = destination.getConsumers(); ObjectName[] answer = new ObjectName[subscriptions.size()]; ObjectName objectName = broker.getBrokerService().getBrokerObjectName(); int index = 0; for (Subscription subscription : subscriptions) { String connectionClientId = subscription.getContext().getClientId(); String objectNameStr = ManagedRegionBroker.getSubscriptionObjectName(subscription, connectionClientId, objectName); answer[index++] = new ObjectName(objectNameStr); } return answer; }
@Override public void resetFlowControlStats() { ProducerBrokerExchange producerBrokerExchange = broker.getBrokerService().getProducerBrokerExchange(info); if (producerBrokerExchange != null){ producerBrokerExchange.resetFlowControl(); } }
info.setDestination(sub.getConsumerInfo().getDestination()); info.setSelector(sub.getSelector()); addInactiveSubscription(key, info, sub); } else { String userName = brokerService.isPopulateUserNameInMBeans() ? context.getUserName() : null; registerSubscription(objectName, sub.getConsumerInfo(), key, view);
@Override public List<HealthStatus> healthList() throws Exception { List<HealthStatus> answer = new ArrayList<HealthStatus>(); Map<ObjectName, DestinationView> queueViews = broker.getQueueViews(); for (Map.Entry<ObjectName, DestinationView> entry : queueViews.entrySet()) { DestinationView queue = entry.getValue(); BrokerService brokerService = broker.getBrokerService(); if (brokerService != null && brokerService.getPersistenceAdapter() != null) { PersistenceAdapter adapter = brokerService.getPersistenceAdapter();
/** * Browse messages for this durable subscriber * * @return messages * @throws OpenDataException */ public TabularData browseAsTable() throws OpenDataException { return broker.browseAsTable(this); }
@Override public String sendTextMessage(Map<String, String> headers, String body, String userName, @Sensitive String password) throws Exception { String brokerUrl = "vm://" + broker.getBrokerName(); ActiveMQDestination dest = destination.getActiveMQDestination();
@Override public void start() throws Exception { super.start(); // build all existing durable subscriptions buildExistingSubscriptions(); }