public void unregisterSubscription(Subscription sub) { ObjectName name = subscriptionMap.remove(sub); if (name != null) { try { SubscriptionKey subscriptionKey = new SubscriptionKey(sub.getContext().getClientId(), sub.getConsumerInfo().getSubscriptionName()); ObjectName inactiveName = subscriptionKeys.remove(subscriptionKey); if (inactiveName != null) { inactiveDurableTopicSubscribers.remove(inactiveName); managementContext.unregisterMBean(inactiveName); } } catch (Exception e) { LOG.error("Failed to unregister subscription {}", sub, e); } } }
@Override public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception { ObjectName objectName = BrokerMBeanSupport.createProducerName(brokerObjectName, context.getClientId(), info); unregisterProducer(objectName); super.removeProducer(context, info); }
@Override public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception { super.addProducer(context, info); String connectionClientId = context.getClientId(); ObjectName objectName = BrokerMBeanSupport.createProducerName(brokerObjectName, context.getClientId(), info); String userName = brokerService.isPopulateUserNameInMBeans() ? context.getUserName() : null; ProducerView view = new ProducerView(info, connectionClientId, userName, this); registerProducer(objectName, info.getDestination(), view); }
@Override public Response messagePull(ConnectionContext context, MessagePull pull) throws Exception { if (isLogAll() || isLogConsumerEvents()) { LOG.info("Message Pull from: {} on {}", context.getClientId(), pull.getDestination().getPhysicalName()); } return super.messagePull(context, pull); }
public DurableTopicSubscription(Broker broker, SystemUsage usageManager, ConnectionContext context, ConsumerInfo info, boolean keepDurableSubsActive) throws JMSException { super(broker, usageManager, context, info); this.pending = new StoreDurableSubscriberCursor(broker, context.getClientId(), info.getSubscriptionName(), info.getPrefetchSize(), this); this.pending.setSystemUsage(usageManager); this.pending.setMemoryUsageHighWaterMark(getCursorMemoryHighWaterMark()); this.keepDurableSubsActive = keepDurableSubsActive; subscriptionKey = new SubscriptionKey(context.getClientId(), info.getSubscriptionName()); }
@Override public ObjectName[] getSubscriptions() throws IOException, MalformedObjectNameException { List<Subscription> subscriptions = destination.getConsumers(); ObjectName[] answer = new ObjectName[subscriptions.size()]; ObjectName brokerObjectName = broker.getBrokerService().getBrokerObjectName(); int index = 0; for (Subscription subscription : subscriptions) { String connectionClientId = subscription.getContext().getClientId(); answer[index++] = BrokerMBeanSupport.createSubscriptionName(brokerObjectName, connectionClientId, subscription.getConsumerInfo()); } return answer; }
@Override public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { Subscription sub = super.addConsumer(context, info); SubscriptionKey subscriptionKey = new SubscriptionKey(sub.getContext().getClientId(), sub.getConsumerInfo().getSubscriptionName()); ObjectName inactiveName = subscriptionKeys.get(subscriptionKey); if (inactiveName != null) { // if it was inactive, register it registerSubscription(context, sub); } return sub; }
@Override public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception { if (isLogAll() || isLogConsumerEvents()) { LOG.info("Acknowledging message for client ID: {}{}", consumerExchange.getConnectionContext().getClientId(), (ack.getMessageCount() == 1 ? ", " + ack.getLastMessageId() : "")); if (ack.getMessageCount() > 1) { LOG.trace("Message count: {}, First Message Id: {}, Last Message Id: {}", new Object[]{ ack.getMessageCount(), ack.getFirstMessageId(), ack.getLastMessageId() }); } } super.acknowledge(consumerExchange, ack); }
@Override public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { if (info.isDurable()) { SubscriptionKey key = new SubscriptionKey(context.getClientId(), info.getSubscriptionName()); DurableTopicSubscription sub = durableSubscriptions.get(key); if (sub != null) { // deactivate only if given context is same // as what is in the sub. otherwise, during linksteal // sub will get new context, but will be removed here if (sub.getContext() == context) { sub.deactivate(keepDurableSubsActive, info.getLastDeliveredSequenceId()); } } } else { super.removeConsumer(context, info); } }
public ObjectName registerSubscription(ConnectionContext context, Subscription sub) { String connectionClientId = context.getClientId(); SubscriptionKey key = new SubscriptionKey(context.getClientId(), sub.getConsumerInfo().getSubscriptionName()); try { ObjectName objectName = BrokerMBeanSupport.createSubscriptionName(brokerObjectName, connectionClientId, sub.getConsumerInfo()); info.setClientId(context.getClientId()); info.setSubscriptionName(sub.getConsumerInfo().getSubscriptionName()); info.setDestination(sub.getConsumerInfo().getDestination()); String userName = brokerService.isPopulateUserNameInMBeans() ? context.getUserName() : null; if (sub.getConsumerInfo().isDurable()) { view = new DurableSubscriptionView(this, brokerService, context.getClientId(), userName, sub); } else { if (sub instanceof TopicSubscription) { view = new TopicSubscriptionView(context.getClientId(), userName, (TopicSubscription) sub); } else { view = new SubscriptionView(context.getClientId(), userName, sub);
@Override public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception { SubscriptionKey key = new SubscriptionKey(context.getClientId(), info.getSubscriptionName()); RegionBroker regionBroker = null; if (next instanceof RegionBroker) { regionBroker = (RegionBroker) next; } else { BrokerService service = next.getBrokerService(); regionBroker = (RegionBroker) service.getRegionBroker(); } if (regionBroker == null) { LOG.warn("Cannot locate a RegionBroker instance to pass along the removeSubscription call"); throw new IllegalStateException("No RegionBroker found."); } DurableTopicSubscription sub = ((TopicRegion) regionBroker.getTopicRegion()).getDurableSubscription(key); super.removeSubscription(context, info); if (sub == null) { LOG.warn("We cannot send an advisory message for a durable sub removal when we don't know about the durable sub"); return; } ActiveMQDestination dest = sub.getConsumerInfo().getDestination(); // Don't advise advisory topics. if (!AdvisorySupport.isAdvisoryTopic(dest)) { ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(dest); fireConsumerAdvisory(context, dest, topic, info); } }
@Override public void send(ProducerBrokerExchange exchange, Message message) throws Exception { if (exchange != null && exchange.getProducerState() != null && exchange.getProducerState().getInfo() != null) { ProducerInfo info = exchange.getProducerState().getInfo(); if (info.getDestination() == null && info.getProducerId() != null) { ObjectName objectName = BrokerMBeanSupport.createProducerName(brokerObjectName, exchange.getConnectionContext().getClientId(), info); ProducerView view = this.dynamicDestinationProducers.get(objectName); if (view != null) { ActiveMQDestination dest = message.getDestination(); if (dest != null) { view.setLastUsedDestinationName(dest); } } } } super.send(exchange, message); }
throw new JMSException("Cannot create a durable subscription for an advisory Topic"); SubscriptionKey key = new SubscriptionKey(context.getClientId(), info.getSubscriptionName()); DurableTopicSubscription sub = durableSubscriptions.get(key); } else { throw new JMSException("Durable subscription is already active for clientID: " + context.getClientId() + " and subscriptionName: " + info.getSubscriptionName());
String clientId = context.getClientId(); String subscriptionName = info.getSubscriptionName(); SubscriptionKey key = new SubscriptionKey(clientId, subscriptionName);
for (Subscription subscription : topicRegion.getDurableSubscriptions().values()) { String subName = subscription.getConsumerInfo().getSubscriptionName(); String clientId = subscription.getContext().getClientId(); if (subName != null && subName.equals(candidateSubName) && clientId.startsWith(configuration.getName())) { DemandSubscription sub = createDemandSubscription(dest, subName);
String name = subscription.getContext().getClientId() + "_" + subscription.getConsumerInfo().getConsumerId(); int maxBatchSize = subscription.getConsumerInfo().getPrefetchSize(); subscription.setMatched(pendingSubscriberPolicy.getSubscriberPendingMessageCursor(broker,name, maxBatchSize,subscription));
@Override public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception { ObjectName objectName = BrokerMBeanSupport.createProducerName(brokerObjectName, context.getClientId(), info); unregisterProducer(objectName); super.removeProducer(context, info); }
@Override public Response messagePull(ConnectionContext context, MessagePull pull) throws Exception { if (isLogAll() || isLogConsumerEvents()) { LOG.info("Message Pull from: {} on {}", context.getClientId(), pull.getDestination().getPhysicalName()); } return super.messagePull(context, pull); }
@Override public ObjectName[] getSubscriptions() throws IOException, MalformedObjectNameException { List<Subscription> subscriptions = destination.getConsumers(); ObjectName[] answer = new ObjectName[subscriptions.size()]; ObjectName brokerObjectName = broker.getBrokerService().getBrokerObjectName(); int index = 0; for (Subscription subscription : subscriptions) { String connectionClientId = subscription.getContext().getClientId(); answer[index++] = BrokerMBeanSupport.createSubscriptionName(brokerObjectName, connectionClientId, subscription.getConsumerInfo()); } return answer; }
@Override public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception { if (isLogAll() || isLogConsumerEvents()) { LOG.info("Acknowledging message for client ID: {}{}", consumerExchange.getConnectionContext().getClientId(), (ack.getMessageCount() == 1 ? ", " + ack.getLastMessageId() : "")); if (ack.getMessageCount() > 1) { LOG.trace("Message count: {}, First Message Id: {}, Last Message Id: {}", new Object[]{ ack.getMessageCount(), ack.getFirstMessageId(), ack.getLastMessageId() }); } } super.acknowledge(consumerExchange, ack); }