com.esf.net.mqtt.client.service
Interface IEsfMqttClient

All Known Subinterfaces:
IEsfMqttCloudClient

public interface IEsfMqttClient


Field Summary
static java.lang.String SERVICE_NAME
          Reports the class name representing this interface.
 
Method Summary
 void connect()
          Connects to the MQtt broker.
 void disconnect()
          Disconnects from the MQtt broker.
 java.lang.String getClientId()
          Returns the last unique ID given to the MQtt agent.
 java.lang.String getPassword()
          Returns the client's password.
 EsfMqttSubscription[] getSubscriptions()
          Returns an array of EsfMqttSubscriptions objects representing the current subscriptions of the client.
 java.lang.String getUsername()
          Returns the client's username.
 boolean isConnected()
          Returns an indication of whether the MQtt connection to the broker is established.
 int publish(java.lang.String topic, byte[] payload, int qos)
          Publishes a message to the MQtt broker.
 void registerCallback(IEsfMqttCallback handler)
          Register an IEsfMqttCallback with the IEsfMqttClient.
 void setBrokerAddress(java.lang.String address)
          The TCP/IP address or domain name of the MQtt broker.
 void setBrokerPort(int port)
          The TCP/IP port number of the MQtt broker.
 void setCleanStart(boolean cs)
          The clean start flag for the MQtt client.
 void setClientId(java.lang.String id)
          The MQtt user ID sent to the broker when a new connection is established.
 void setKeepAlive(short seconds)
          Set the service MQtt ping interval.
 void setPassword(java.lang.String password)
          Returns the client's password.
 void setUsername(java.lang.String username)
          Sets the client's username.
 int subscribe(EsfMqttSubscription subscription)
          Subscribes to a topic with the MQtt broker.
 int subscribe(EsfMqttSubscription[] subscriptions)
          Subscribes to one or more topics with the MQtt broker.
 int subscribe(java.lang.String topic, int qos)
          Subscribes to a topic with the MQtt broker.
 int unsubscribe(EsfMqttSubscription subscription)
          Unsubscribes from a topic with the MQtt broker.
 int unsubscribe(java.lang.String topic)
          Unsubscribes from a topic with the MQtt broker.
 

Field Detail

SERVICE_NAME

static final java.lang.String SERVICE_NAME
Reports the class name representing this interface.

Method Detail

setKeepAlive

void setKeepAlive(short seconds)
Set the service MQtt ping interval. This value is sent to the MQtt broker, as the MQtt keep-alive value for the connection.

Parameters:
seconds - Ping interval, in units of seconds.

unsubscribe

int unsubscribe(EsfMqttSubscription subscription)
                throws EsfMqttException
Unsubscribes from a topic with the MQtt broker. An EsfMqttSubscription topic is specified that contains the topic in which to unsubscribe from. If the unsubscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Parameters:
subscription - A EsfMqttSubscription object containing the topic.
Returns:
The unsubscribe message's ID.
Throws:
EsfMqttException

unsubscribe

int unsubscribe(java.lang.String topic)
                throws EsfMqttException
Unsubscribes from a topic with the MQtt broker. A String object is specified which contains the topic in which to unsubscribe from. If the unsubscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Parameters:
topic - A String object containing the topic.
Returns:
The unsubscribe message's ID.
Throws:
EsfMqttException

subscribe

int subscribe(EsfMqttSubscription[] subscriptions)
              throws EsfMqttException
Subscribes to one or more topics with the MQtt broker. The topics are specified as an array of EsfMqttSubscription objects. If the subscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Parameters:
subscriptions - An array of EsfMqttSubscription objects.
Returns:
The subscribe message's ID.
Throws:
EsfMqttException

subscribe

int subscribe(EsfMqttSubscription subscription)
              throws EsfMqttException
Subscribes to a topic with the MQtt broker. The topic and QoS are specified in an EsfMqttSubscription object. If the subscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Parameters:
subscription - An EsfMqttSubscription object.
Returns:
The subscribe message's ID.
Throws:
EsfMqttException

subscribe

int subscribe(java.lang.String topic,
              int qos)
              throws EsfMqttException
Subscribes to a topic with the MQtt broker. The topic is specified as a String object and the QoS is specified as an interger. If the subscribe fails, an exception will be thrown that will contain information about the cause of the failure.

Parameters:
topic - A String object containing the topic.
qos - An int containing the Quality of Service.
Returns:
The subscribe message's ID.
Throws:
EsfMqttException

getSubscriptions

EsfMqttSubscription[] getSubscriptions()
Returns an array of EsfMqttSubscriptions objects representing the current subscriptions of the client.

Returns:
An array of EsfMqttSubscription objects.

setUsername

void setUsername(java.lang.String username)
Sets the client's username.

Parameters:
username - A String object specifying the username.

getUsername

java.lang.String getUsername()
Returns the client's username.

Returns:
A String object specifying the username.

setPassword

void setPassword(java.lang.String password)
Returns the client's password.

Parameters:
password - A String object specifying the password.

getPassword

java.lang.String getPassword()
Returns the client's password.

Returns:
A String object specifying the password.

setClientId

void setClientId(java.lang.String id)
The MQtt user ID sent to the broker when a new connection is established. This ID should be unique for any connection to the broker, across all clients. This string should be more than one character, and no more than 23 characters in length.

Parameters:
id - A String representing the Client's ID.

getClientId

java.lang.String getClientId()
Returns the last unique ID given to the MQtt agent. This represents the MQtt client ID that is used in the MQtt CONNECT command.

Returns:
string A String representing the Client's ID.

isConnected

boolean isConnected()
Returns an indication of whether the MQtt connection to the broker is established.

Returns:
boolean, whether connection to broker is established.

registerCallback

void registerCallback(IEsfMqttCallback handler)
Register an IEsfMqttCallback with the IEsfMqttClient. This handler will receive events when a client publication has arrived, and when a publish (QoS > 0) has been fully acknowledged by the broker.

Parameters:
handler - An implementation of the IEsfMqttCallback interface.

setBrokerAddress

void setBrokerAddress(java.lang.String address)
The TCP/IP address or domain name of the MQtt broker.

Parameters:
address - A String representing the broker address

setBrokerPort

void setBrokerPort(int port)
The TCP/IP port number of the MQtt broker. The default value is 1883.

Parameters:
port - TCP/IP port number of broker.

setCleanStart

void setCleanStart(boolean cs)
The clean start flag for the MQtt client. The default value is true.

Parameters:
cs - The clean start flag.

connect

void connect()
             throws EsfMqttException
Connects to the MQtt broker.

Throws:
EsfMqttException

disconnect

void disconnect()
                throws EsfMqttException
Disconnects from the MQtt broker.

Throws:
EsfMqttException

publish

int publish(java.lang.String topic,
            byte[] payload,
            int qos)
            throws EsfMqttException
Publishes a message to the MQtt broker.

Parameters:
topic - A String specifying the topic the message was published on.
payload - An array of bytes containing the payload of the message.
qos - An integer specifying the quality of service the message was published on.
Returns:
The published message's ID.
Throws:
EsfMqttException