public class PahoMqttAgent extends Object implements MqttAgent
PahoMqttContext
.Modifier and Type | Field and Description |
---|---|
protected MqttAgentConfiguration |
agentConfiguration
Factory and configuration provider.
|
protected IMqttAsyncClient |
mqttClient
The MQTT Client used to publish/subscribe to the topics
|
protected Map<String,Set<PahoMqttContext>> |
subscribedTopics
Gives for each subscribed topic, the set of
PahoMqttContext that have subscribed to it. |
Constructor and Description |
---|
PahoMqttAgent(String id,
IMqttAsyncClient mqttClient,
MqttAgentConfiguration agentConfiguration)
Creates a new
MqttAgent that uses Paho. |
Modifier and Type | Method and Description |
---|---|
void |
cleanupConnection(PahoMqttContext connection)
Free any data related to the given connection
|
void |
close()
Close this agent.
|
String |
getId()
Returns the identifier of the agent.
|
Set<PahoMqttContext> |
getMqttContextSubscribedTo(String topic)
Returns the
MqttContext that are subscribed to the given topic. |
MqttContext |
newMqttContext()
Creates a new
MqttContext . |
void |
subscribe(PahoMqttContext connection,
String topicFilter,
int qos)
Subscribe the given connection to the given topic.
|
void |
unsubscribe(PahoMqttContext connection,
String topicFilter)
Remove subscription for the given connection.
|
protected final MqttAgentConfiguration agentConfiguration
protected IMqttAsyncClient mqttClient
protected Map<String,Set<PahoMqttContext>> subscribedTopics
PahoMqttContext
that have subscribed to it.public PahoMqttAgent(String id, IMqttAsyncClient mqttClient, MqttAgentConfiguration agentConfiguration)
MqttAgent
that uses Paho.id
- value returned by getId()
.mqttClient
- the Paho MQTT Client to use for this agent.agentConfiguration
- configuration for this agent.public void cleanupConnection(PahoMqttContext connection)
connection
- the connection to cleanup.public void close()
public String getId()
MqttAgent
public Set<PahoMqttContext> getMqttContextSubscribedTo(String topic)
MqttContext
that are subscribed to the given topic.topic
- the MQTT topic.Set
of PahoMqttContext
.public MqttContext newMqttContext()
MqttAgent
MqttContext
.newMqttContext
in interface MqttAgent
MqttContext
or null
if the MqttContext
cannot be created.public void subscribe(PahoMqttContext connection, String topicFilter, int qos) throws IOException
connection
- the PahoMqttContext
that subscribes.topicFilter
- the topic filter to subscribe to.qos
- the QOS of the subscription.IOException
- on I/O Error.public void unsubscribe(PahoMqttContext connection, String topicFilter) throws IOException
connection
- the PahoMqttContext
that unsubscribes.topicFilter
- the topic filter to unsubscribe to.IOException
- on I/O Error.