Class AbstractMQTTSubscriptionStrategy
java.lang.Object
org.apache.activemq.transport.mqtt.strategy.AbstractMQTTSubscriptionStrategy
- All Implemented Interfaces:
BrokerServiceAware,MQTTSubscriptionStrategy
- Direct Known Subclasses:
MQTTDefaultSubscriptionStrategy,MQTTVirtualTopicSubscriptionStrategy
public abstract class AbstractMQTTSubscriptionStrategy
extends Object
implements MQTTSubscriptionStrategy, BrokerServiceAware
Abstract implementation of the
MQTTSubscriptionStrategy interface providing
the base functionality that is common to most implementations.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BrokerServiceprotected final LongSequenceGeneratorprotected final ConcurrentMap<String,MQTTSubscription> protected MQTTProtocolConverterprotected final ConcurrentMap<org.apache.activemq.command.ConsumerId,MQTTSubscription> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddeleteDurableSubs(List<org.apache.activemq.command.SubscriptionInfo> subs) protected bytedoSubscribe(org.apache.activemq.command.ConsumerInfo consumerInfo, String topicName, org.fusesource.mqtt.client.QoS qoS) voiddoUnSubscribe(MQTTSubscription subscription) protected org.apache.activemq.command.ConsumerIdgetSubscription(org.apache.activemq.command.ConsumerId consumerId) Lookup anMQTTSubscriptioninstance based on knownConsumerIdvalue.voidinitialize(MQTTProtocolConverter protocol) Initialize the strategy before first use.booleanisControlTopic(org.apache.activemq.command.ActiveMQDestination destination) Allows the protocol handler to interrogate an destination name to determine if it is equivalent to the MQTT control topic (starts with $).protected List<org.apache.activemq.command.SubscriptionInfo>lookupSubscription(String clientId) voidonReSubscribe(MQTTSubscription mqttSubscription) Called when a client sends a duplicate subscribe request which should force any retained messages on that topic to be replayed again as though the client had just subscribed for the first time.org.apache.activemq.command.ActiveMQDestinationIntercepts PUBLISH operations from the client and allows the strategy to map the target destination so that the send operation will land in the destinations that this strategy has mapped the incoming subscribe requests to.onSend(org.apache.activemq.command.ActiveMQDestination destination) Intercepts send operations from the broker and allows the strategy to map the target topic name so that the client sees a valid Topic name.byteonSubscribe(org.fusesource.mqtt.client.Topic topic) Called for each Topic that a client requests to subscribe to.protected voidrestoreDurableSubs(List<org.apache.activemq.command.SubscriptionInfo> subs) voidsetBrokerService(BrokerService brokerService) voidSets theMQTTProtocolConverterthat is the parent of this strategy object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.activemq.transport.mqtt.strategy.MQTTSubscriptionStrategy
onConnect, onSubscribe, onUnSubscribe
-
Field Details
-
protocol
-
brokerService
-
subscriptionsByConsumerId
protected final ConcurrentMap<org.apache.activemq.command.ConsumerId,MQTTSubscription> subscriptionsByConsumerId -
mqttSubscriptionByTopic
-
restoredDurableSubs
-
consumerIdGenerator
-
-
Constructor Details
-
AbstractMQTTSubscriptionStrategy
public AbstractMQTTSubscriptionStrategy()
-
-
Method Details
-
initialize
Description copied from interface:MQTTSubscriptionStrategyInitialize the strategy before first use.- Specified by:
initializein interfaceMQTTSubscriptionStrategy- Parameters:
protocol- the MQTTProtocolConverter that is initializing the strategy- Throws:
MQTTProtocolException- if an error occurs during initialization.
-
setBrokerService
- Specified by:
setBrokerServicein interfaceBrokerServiceAware
-
setProtocolConverter
Description copied from interface:MQTTSubscriptionStrategySets theMQTTProtocolConverterthat is the parent of this strategy object.- Specified by:
setProtocolConverterin interfaceMQTTSubscriptionStrategy- Parameters:
parent- theMQTTProtocolConverterthat owns this strategy.
-
getProtocolConverter
- Specified by:
getProtocolConverterin interfaceMQTTSubscriptionStrategy- Returns:
- the
MQTTProtocolConverterthat owns this strategy.
-
onSubscribe
Description copied from interface:MQTTSubscriptionStrategyCalled for each Topic that a client requests to subscribe to. The strategy needs check each Topic for duplicate subscription requests and change of QoS state.- Specified by:
onSubscribein interfaceMQTTSubscriptionStrategy- Parameters:
topic- the MQTT Topic instance being subscribed to.- Returns:
- the assigned QoS value given to the new subscription.
- Throws:
MQTTProtocolException- if an error occurs while processing the subscribe actions.
-
onReSubscribe
Description copied from interface:MQTTSubscriptionStrategyCalled when a client sends a duplicate subscribe request which should force any retained messages on that topic to be replayed again as though the client had just subscribed for the first time. The method should not unsubscribe the client as it might miss messages sent while the subscription is being recreated.- Specified by:
onReSubscribein interfaceMQTTSubscriptionStrategy- Parameters:
mqttSubscription- the MQTTSubscription that contains the subscription state.- Throws:
MQTTProtocolException
-
onSend
Description copied from interface:MQTTSubscriptionStrategyIntercepts PUBLISH operations from the client and allows the strategy to map the target destination so that the send operation will land in the destinations that this strategy has mapped the incoming subscribe requests to.- Specified by:
onSendin interfaceMQTTSubscriptionStrategy- Parameters:
topicName- the targeted Topic that the client sent the message to.- Returns:
- an ActiveMQ Topic instance that lands the send in the correct destinations.
-
onSend
Description copied from interface:MQTTSubscriptionStrategyIntercepts send operations from the broker and allows the strategy to map the target topic name so that the client sees a valid Topic name.- Specified by:
onSendin interfaceMQTTSubscriptionStrategy- Parameters:
destination- the destination that the message was dispatched from- Returns:
- an Topic name that is valid for the receiving client.
-
isControlTopic
public boolean isControlTopic(org.apache.activemq.command.ActiveMQDestination destination) Description copied from interface:MQTTSubscriptionStrategyAllows the protocol handler to interrogate an destination name to determine if it is equivalent to the MQTT control topic (starts with $). Since the mapped destinations that the strategy might alter the naming scheme the strategy must provide a way to reverse map and determine if the destination was originally an MQTT control topic.- Specified by:
isControlTopicin interfaceMQTTSubscriptionStrategy- Parameters:
destination- the destination to query.- Returns:
- true if the destination is an MQTT control topic.
-
getSubscription
Description copied from interface:MQTTSubscriptionStrategyLookup anMQTTSubscriptioninstance based on knownConsumerIdvalue.- Specified by:
getSubscriptionin interfaceMQTTSubscriptionStrategy- Parameters:
consumerId- the consumer ID to lookup.- Returns:
- the
MQTTSubscriptionfor the consumer or null if no subscription exists.
-
getNextConsumerId
protected org.apache.activemq.command.ConsumerId getNextConsumerId() -
doSubscribe
protected byte doSubscribe(org.apache.activemq.command.ConsumerInfo consumerInfo, String topicName, org.fusesource.mqtt.client.QoS qoS) throws MQTTProtocolException - Throws:
MQTTProtocolException
-
doUnSubscribe
-
deleteDurableSubs
-
restoreDurableSubs
-
lookupSubscription
protected List<org.apache.activemq.command.SubscriptionInfo> lookupSubscription(String clientId) throws MQTTProtocolException - Throws:
MQTTProtocolException
-