public class PahoMqttAgent
extends java.lang.Object
implements ej.data.pubsub.MqttAgent
PahoMqttContext
.Modifier and Type | Field and Description |
---|---|
protected MqttAgentConfiguration |
agentConfiguration
Factory and configuration provider.
|
protected org.eclipse.paho.client.mqttv3.IMqttAsyncClient |
mqttClient
The MQTT Client used to publish/subscribe to the topics
|
protected java.util.Map<java.lang.String,java.util.Set<PahoMqttContext>> |
subscribedTopics
Gives for each subscribed topic, the set of
PahoMqttContext that have subscribed to it. |
Constructor and Description |
---|
PahoMqttAgent(java.lang.String id,
org.eclipse.paho.client.mqttv3.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.
|
java.lang.String |
getId() |
java.util.Set<PahoMqttContext> |
getMqttContextSubscribedTo(java.lang.String topic)
Returns the
MqttContext that are subscribed to the given topic. |
ej.data.pubsub.MqttContext |
newMqttContext() |
void |
subscribe(PahoMqttContext connection,
java.lang.String topicFilter,
int qos)
Subscribe the given connection to the given topic.
|
void |
unsubscribe(PahoMqttContext connection,
java.lang.String topicFilter)
Remove subscription for the given connection.
|
protected org.eclipse.paho.client.mqttv3.IMqttAsyncClient mqttClient
protected final MqttAgentConfiguration agentConfiguration
protected java.util.Map<java.lang.String,java.util.Set<PahoMqttContext>> subscribedTopics
PahoMqttContext
that have subscribed to it.public PahoMqttAgent(java.lang.String id, org.eclipse.paho.client.mqttv3.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 ej.data.pubsub.MqttContext newMqttContext()
newMqttContext
in interface ej.data.pubsub.MqttAgent
public java.lang.String getId()
getId
in interface ej.data.pubsub.MqttAgent
public void subscribe(PahoMqttContext connection, java.lang.String topicFilter, int qos) throws java.io.IOException
connection
- the PahoMqttContext
that subscribes.topicFilter
- the topic filter to subscribe to.qos
- the QOS of the subscription.java.io.IOException
- on I/O Error.public void unsubscribe(PahoMqttContext connection, java.lang.String topicFilter) throws java.io.IOException
connection
- the PahoMqttContext
that unsubscribes.topicFilter
- the topic filter to unsubscribe to.java.io.IOException
- on I/O Error.public void cleanupConnection(PahoMqttContext connection)
connection
- the connection to cleanup.public java.util.Set<PahoMqttContext> getMqttContextSubscribedTo(java.lang.String topic)
MqttContext
that are subscribed to the given topic.topic
- the MQTT topic.Set
of PahoMqttContext
.public void close()