protected ConsumerInfo getConsumerInfo() { return subscription != null ? subscription.getConsumerInfo() : null; }
protected boolean hasRegularConsumers(List<Subscription> consumers) { boolean hasRegularConsumers = false; for (Subscription subscription: consumers) { if (!subscription.getConsumerInfo().isNetworkSubscription()) { hasRegularConsumers = true; break; } } return hasRegularConsumers; }
@Override public int compare(Subscription o1, Subscription o2) { // We want the list sorted in descending order return o2.getConsumerInfo().getPriority() - o1.getConsumerInfo().getPriority(); } };
@Override public int compare(Subscription s1, Subscription s2) { // We want the list sorted in descending order int val = s2.getConsumerInfo().getPriority() - s1.getConsumerInfo().getPriority(); if (val == 0 && messageGroupOwners != null) { // then ascending order of assigned message groups to favour less loaded consumers // Long.compare in jdk7 long x = s1.getConsumerInfo().getAssignedGroupCount(destination); long y = s2.getConsumerInfo().getAssignedGroupCount(destination); val = (x < y) ? -1 : ((x == y) ? 0 : 1); } return val; } };
public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List<Subscription> consumers) throws Exception { ArrayList<Subscription> ordered = new ArrayList<Subscription>(consumers); Collections.sort(ordered, orderedCompare); StringBuffer stringBuffer = new StringBuffer(); for (Subscription sub: ordered) { stringBuffer.append(sub.getConsumerInfo().getPriority()); stringBuffer.append(','); } //System.err.println("Priority:" + stringBuffer.toString() + ", msg: " + node.getMessage()); return super.dispatch(node, msgContext, ordered); }
@Override public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { for (Subscription sub : subscriptionMap.keySet()) { if (sub.getConsumerInfo().equals(info)) { // unregister all consumer subs unregisterSubscription(subscriptionMap.get(sub), true); } } super.removeConsumer(context, info); }
public void abortConsumer(ObjectName consumerToAbort) { Subscription sub = broker.getSubscriber(consumerToAbort); if (sub != null) { LOG.info("aborting consumer via jmx: {}", sub.getConsumerInfo().getConsumerId()); strategy.abortConsumer(sub, false); } else { LOG.warn("cannot resolve subscription matching name: {}", consumerToAbort); } }
public void recoverRetroactiveMessages(ConnectionContext context, Subscription subscription) throws Exception { if (subscription.getConsumerInfo().isRetroactive()) { subscriptionRecoveryPolicy.recover(context, this, subscription); } }
@Override public String toString() { return "TopicStorePrefetch(" + clientId + "," + subscriberName + ",storeHasMessages=" + this.storeHasMessages +") " + this.subscription.getConsumerInfo().getConsumerId() + " - " + super.toString(); } }
private boolean hasLowerPriority(Subscription candidate, ConsumerInfo info) { return candidate.getConsumerInfo().getPriority() < info.getPriority(); }
private boolean isInActiveDurableSub(Subscription sub) { return (sub.getConsumerInfo().isDurable() && sub instanceof DurableTopicSubscription && !((DurableTopicSubscription) sub).isActive()); }
@Override public void slowConsumer(ConnectionContext context, Destination destination, Subscription subs) { if (isLogAll() || isLogConsumerEvents() || isLogInternalEvents()) { LOG.info("Detected slow consumer on {}", destination.getName()); StringBuffer buf = new StringBuffer("Connection("); buf.append(subs.getConsumerInfo().getConsumerId().getConnectionId()); buf.append(") Session("); buf.append(subs.getConsumerInfo().getConsumerId().getSessionId()); buf.append(")"); LOG.info(buf.toString()); } super.slowConsumer(context, destination, subs); }
@Override public void removeSubscription(ConnectionContext context, Subscription sub, long lastDeliveredSequenceId) throws Exception { if (!sub.getConsumerInfo().isDurable()) { boolean removed = false; synchronized (consumers) { removed = consumers.remove(sub); } if (removed) { super.removeSubscription(context, sub, lastDeliveredSequenceId); } } sub.remove(context, this); }
protected void assignGroup(Subscription subs, MessageGroupMap messageGroupOwners, MessageReference n, String groupId) throws IOException { messageGroupOwners.put(groupId, subs.getConsumerInfo().getConsumerId()); Message message = n.getMessage(); message.setJMSXGroupFirstForConsumer(true); subs.getConsumerInfo().incrementAssignedGroupCount(destination); }
public void abortConnection(ObjectName consumerToAbort) { Subscription sub = broker.getSubscriber(consumerToAbort); if (sub != null) { LOG.info("aborting consumer connection via jmx: {}", sub.getConsumerInfo().getConsumerId().getConnectionId()); strategy.abortConsumer(sub, true); } else { LOG.warn("cannot resolve subscription matching name: {}", consumerToAbort); } }
private void removeDuplicateSubscription(Subscription existingSub) throws IOException { for (NetworkConnector connector : brokerService.getNetworkConnectors()) { if (connector.removeDemandSubscription(existingSub.getConsumerInfo().getConsumerId())) { break; } } }
private boolean matches(Subscription candidate, ConsumerInfo info) { boolean matched = false; for (ConsumerId candidateId: candidate.getConsumerInfo().getNetworkConsumerIds()) { for (ConsumerId subId: info.getNetworkConsumerIds()) { if (candidateId.equals(subId)) { matched = true; break; } } } return matched; }
@Override public synchronized void removeAll(){ cache.clear(); if (destination != null) { for (Subscription s : destination.getConsumers()) { s.getConsumerInfo().clearAssignedGroupCount(destination.getActiveMQDestination()); } } }
@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; }