public void doCleanup() { long now = System.currentTimeMillis(); for (Map.Entry<SubscriptionKey, DurableTopicSubscription> entry : durableSubscriptions.entrySet()) { DurableTopicSubscription sub = entry.getValue(); if (!sub.isActive()) { long offline = sub.getOfflineTimestamp(); if (offline != -1 && now - offline >= broker.getBrokerService().getOfflineDurableSubscriberTimeout()) { LOG.info("Destroying durable subscriber due to inactivity: {}", sub); try { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(entry.getKey().getClientId()); info.setSubscriptionName(entry.getKey().getSubscriptionName()); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(entry.getKey().getClientId()); removeSubscription(context, info); } catch (Exception e) { LOG.error("Failed to remove inactive durable subscriber", e); } } } } }
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException { super.looseUnmarshal(wireFormat, o, dataIn); RemoveSubscriptionInfo info = (RemoveSubscriptionInfo)o; info.setConnectionId((org.apache.activemq.command.ConnectionId) looseUnmarsalCachedObject(wireFormat, dataIn)); info.setSubscriptionName(looseUnmarshalString(dataIn)); info.setClientId(looseUnmarshalString(dataIn)); }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { RemoveSubscriptionInfo info = (RemoveSubscriptionInfo)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getConnectionId(), dataOut); looseMarshalString(info.getSubscriptionName(), dataOut); looseMarshalString(info.getClientId(), dataOut); } }
/** * Destroys the durable subscription so that messages will no longer be * stored for this subscription */ public void destroy() throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); info.setSubscriptionName(subscriptionName); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(clientId); brokerService.getBroker().removeSubscription(context, info); }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { RemoveSubscriptionInfo info = (RemoveSubscriptionInfo)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getConnectionId(), bs); rc += tightMarshalString1(info.getSubcriptionName(), bs); rc += tightMarshalString1(info.getClientId(), bs); return rc + 0; }
@Override public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception { SubscriptionKey key = new SubscriptionKey(info.getClientId(), info.getSubscriptionName()); DurableTopicSubscription sub = durableSubscriptions.get(key); if (sub == null) { throw new InvalidDestinationException("No durable subscription exists for clientID: " + info.getClientId() + " and subscriptionName: " + info.getSubscriptionName()); durableSubscriptions.remove(key); if (subscriptions.get(sub.getConsumerInfo().getConsumerId()) != null) { super.removeConsumer(context, sub.getConsumerInfo()); } else {
public void onUnSubscribe(String topicName) throws MQTTProtocolException { MQTTSubscription subscription = mqttSubscriptionByTopic.remove(topicName); if (subscription != null) { doUnSubscribe(subscription); // check if the durable sub also needs to be removed if (subscription.getConsumerInfo().getSubscriptionName() != null) { // also remove it from restored durable subscriptions set RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo(); rsi.setConnectionId(getConnectionId()); rsi.setSubscriptionName(subscription.getConsumerInfo().getSubscriptionName()); rsi.setClientId(getClientId()); sendToActiveMQ(rsi, null); } } }
BrokerId[] path = info.getBrokerPath(); if (info.isBrowser()) { LOG.debug("{} Ignoring sub from {}, browsers explicitly suppressed", configuration.getBrokerName(), remoteBrokerName); return; if (!isPermissableDestination(info.getDestination())) { addConsumerInfo(info); } else { synchronized (brokerService.getVmConnectorURI()) { addConsumerInfo(info); for (Iterator<DemandSubscription> i = subscriptionMapByLocalId.values().iterator(); i.hasNext(); ) { DemandSubscription ds = i.next(); boolean removed = ds.removeForcedDurableConsumer(id); final SubscriptionInfo subscriptionInfo = new SubscriptionInfo(info.getClientId(), info.getSubscriptionName()); final boolean proxyBridgeSub = isProxyBridgeSubscription(subscriptionInfo.getClientId(), subscriptionInfo.getSubscriptionName()); for (Iterator<DemandSubscription> i = subscriptionMapByLocalId.values().iterator(); i.hasNext(); ) { DemandSubscription ds = i.next(); boolean removed = ds.getDurableRemoteSubs().remove(subscriptionInfo);
private void cleanupDurableSub(final DemandSubscription ds, Iterator<DemandSubscription> i) throws IOException { if (ds != null && ds.getLocalDurableSubscriber() != null && ds.getDurableRemoteSubs().isEmpty() && ds.getForcedDurableConsumersSize() == 0) { // deactivate subscriber RemoveInfo removeInfo = new RemoveInfo(ds.getLocalInfo().getConsumerId()); localBroker.oneway(removeInfo); // remove subscriber RemoveSubscriptionInfo sending = new RemoveSubscriptionInfo(); sending.setClientId(localClientId); sending.setSubscriptionName(ds.getLocalDurableSubscriber().getSubscriptionName()); sending.setConnectionId(this.localConnectionInfo.getConnectionId()); localBroker.oneway(sending); //remove subscriber from map i.remove(); } }
RegionBroker regionBroker = (RegionBroker) brokerService.getRegionBroker(); TopicRegion topicRegion = (TopicRegion) regionBroker.getTopicRegion(); 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); if (sub != null) { sub.getLocalInfo().setSubscriptionName(getSubscriberName(dest)); sub.setStaticallyIncluded(true); addSubscription(sub); } else if (configuration.isSyncDurableSubs() && !isPermissableDestination(dest)) { if (dest.isTopic()) { RegionBroker regionBroker = (RegionBroker) brokerService.getRegionBroker(); TopicRegion topicRegion = (TopicRegion) regionBroker.getTopicRegion(); String subName = subscription.getConsumerInfo().getSubscriptionName(); if (subName != null && subName.equals(candidateSubName) && subscription instanceof DurableTopicSubscription) { RemoveSubscriptionInfo sending = new RemoveSubscriptionInfo(); sending.setClientId(localClientId); sending.setSubscriptionName(subName); sending.setConnectionId(this.localConnectionInfo.getConnectionId()); localBroker.oneway(sending);
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException { super.tightUnmarshal(wireFormat, o, dataIn, bs); RemoveSubscriptionInfo info = (RemoveSubscriptionInfo)o; info.setConnectionId((org.apache.activemq.command.ConnectionId) tightUnmarsalCachedObject(wireFormat, dataIn, bs)); info.setSubcriptionName(tightUnmarshalString(dataIn, bs)); info.setClientId(tightUnmarshalString(dataIn, bs)); }
@Override public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException { if (consumerInfo.isDurable()) { RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo(); rsi.setConnectionId(session.getConnection().getConnectionId()); rsi.setSubscriptionName(getEndpoint().getName()); rsi.setClientId(session.getConnection().getClientId()); sendToActiveMQ(rsi); } session.unregisterSender(getConsumerId()); AmqpSender.super.close(); } });
@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); } }
/** * @return a new object instance */ public DataStructure createObject() { return new RemoveSubscriptionInfo(); }
@Override public Response processRemoveSubscription(RemoveSubscriptionInfo info) throws Exception { broker.removeSubscription(lookupConnectionState(info.getConnectionId()).getContext(), info); return null; }
@Override public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception { SubscriptionKey key = new SubscriptionKey(info.getClientId(), info.getSubscriptionName()); DurableTopicSubscription sub = durableSubscriptions.get(key); if (sub == null) { throw new InvalidDestinationException("No durable subscription exists for clientID: " + info.getClientId() + " and subscriptionName: " + info.getSubscriptionName()); durableSubscriptions.remove(key); if (subscriptions.get(sub.getConsumerInfo().getConsumerId()) != null) { super.removeConsumer(context, sub.getConsumerInfo()); } else {
public void onUnSubscribe(String topicName) throws MQTTProtocolException { MQTTSubscription subscription = mqttSubscriptionByTopic.remove(topicName); if (subscription != null) { doUnSubscribe(subscription); // check if the durable sub also needs to be removed if (subscription.getConsumerInfo().getSubscriptionName() != null) { // also remove it from restored durable subscriptions set RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo(); rsi.setConnectionId(getConnectionId()); rsi.setSubscriptionName(subscription.getConsumerInfo().getSubscriptionName()); rsi.setClientId(getClientId()); sendToActiveMQ(rsi, null); } } }
@Override public void destroyDurableSubscriber(String clientId, String subscriberName) throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); info.setSubscriptionName(subscriberName); ConnectionContext context = getConnectionContext(); context.setBroker(safeGetBroker()); context.setClientId(clientId); brokerService.getBroker().removeSubscription(context, info); }
private void cleanupDurableSub(final DemandSubscription ds, Iterator<DemandSubscription> i) throws IOException { if (ds != null && ds.getLocalDurableSubscriber() != null && ds.getDurableRemoteSubs().isEmpty() && ds.getForcedDurableConsumersSize() == 0) { // deactivate subscriber RemoveInfo removeInfo = new RemoveInfo(ds.getLocalInfo().getConsumerId()); localBroker.oneway(removeInfo); // remove subscriber RemoveSubscriptionInfo sending = new RemoveSubscriptionInfo(); sending.setClientId(localClientId); sending.setSubscriptionName(ds.getLocalDurableSubscriber().getSubscriptionName()); sending.setConnectionId(this.localConnectionInfo.getConnectionId()); localBroker.oneway(sending); //remove subscriber from map i.remove(); } }
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException { super.tightUnmarshal(wireFormat, o, dataIn, bs); RemoveSubscriptionInfo info = (RemoveSubscriptionInfo)o; info.setConnectionId((org.apache.activemq.command.ConnectionId) tightUnmarsalCachedObject(wireFormat, dataIn, bs)); info.setSubcriptionName(tightUnmarshalString(dataIn, bs)); info.setClientId(tightUnmarshalString(dataIn, bs)); }