public class MqttTopic
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MULTI_LEVEL_WILDCARD
Multi-level wildcard The number sign (#) is a wildcard character that
matches any number of levels within a topic.
|
static java.lang.String |
MULTI_LEVEL_WILDCARD_PATTERN
Multi-level wildcard pattern(/#)
|
static java.lang.String |
SINGLE_LEVEL_WILDCARD
Single-level wildcard The plus sign (+) is a wildcard character that
matches only one topic level.
|
static java.lang.String |
TOPIC_LEVEL_SEPARATOR
The forward slash (/) is used to separate each level within a topic tree
and provide a hierarchical structure to the topic space.
|
static java.lang.String |
TOPIC_WILDCARDS
Topic wildcards (#+)
|
Constructor and Description |
---|
MqttTopic(java.lang.String name,
ClientComms comms) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getName()
Returns the name of the queue or topic.
|
static boolean |
isMatched(java.lang.String topicFilter,
java.lang.String topicName)
Check the supplied topic name and filter match
|
MqttDeliveryToken |
publish(byte[] payload,
int qos,
boolean retained)
Publishes a message on the topic.
|
MqttDeliveryToken |
publish(MqttMessage message)
Publishes the specified message to this topic, but does not wait for delivery
of the message to complete.
|
java.lang.String |
toString()
Returns a string representation of this topic.
|
static void |
validate(java.lang.String topicString,
boolean wildcardAllowed)
Validate the topic name or topic filter
|
public static final java.lang.String TOPIC_LEVEL_SEPARATOR
public static final java.lang.String MULTI_LEVEL_WILDCARD
public static final java.lang.String SINGLE_LEVEL_WILDCARD
public static final java.lang.String MULTI_LEVEL_WILDCARD_PATTERN
public static final java.lang.String TOPIC_WILDCARDS
public MqttTopic(java.lang.String name, ClientComms comms)
public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException
MqttMessage
object with a byte array payload and the
specified QoS, and then publish it. All other values in the
message will be set to the defaults.payload
- the byte array to use as the payloadqos
- the Quality of Service. Valid values are 0, 1 or 2.retained
- whether or not this message should be retained by the server.java.lang.IllegalArgumentException
- if value of QoS is not 0, 1 or 2.MqttException
MqttPersistenceException
publish(MqttMessage)
,
MqttMessage.setQos(int)
,
MqttMessage.setRetained(boolean)
public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException
token
can be used
to track the delivery status of the message. Once this method has
returned cleanly, the message has been accepted for publication by the
client. Message delivery will be completed in the background when a connection
is available.message
- the message to publishMqttException
MqttPersistenceException
public java.lang.String getName()
public java.lang.String toString()
toString
in class java.lang.Object
public static void validate(java.lang.String topicString, boolean wildcardAllowed) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
topicString
- topic name or filterwildcardAllowed
- true if validate topic filter, false otherwisejava.lang.IllegalArgumentException
- if the topic is invalidjava.lang.IllegalStateException
public static boolean isMatched(java.lang.String topicFilter, java.lang.String topicName) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
topicFilter
- topic filter: wildcards allowedtopicName
- topic name: wildcards not allowedjava.lang.IllegalArgumentException
- if the topic name or filter is invalidjava.lang.IllegalStateException