net.sf.xenqtt.client
Class MqttClientFactory

java.lang.Object
  extended by net.sf.xenqtt.client.MqttClientFactory

public final class MqttClientFactory
extends Object

Used to create multiple "sibling" clients that share an Executor, broker URI, etc.


Constructor Summary
MqttClientFactory(String brokerUri, ReconnectionStrategy reconnectionStrategy, Executor executor, int connectTimeoutSeconds, int messageResendIntervalSeconds)
          Constructs an object to create asynchronous clients using a user provided Executor.
MqttClientFactory(String brokerUri, ReconnectionStrategy reconnectionStrategy, Executor executor, int connectTimeoutSeconds, int messageResendIntervalSeconds, int blockingTimeoutSeconds)
          Constructs an object to create synchronous clients using a user provided Executor.
MqttClientFactory(String brokerUri, ReconnectionStrategy reconnectionStrategy, int messageHandlerThreadPoolSize, int connectTimeoutSeconds, int messageResendIntervalSeconds)
          Constructs an object to create asynchronous clients using an Executor owned by this class.
MqttClientFactory(String brokerUri, ReconnectionStrategy reconnectionStrategy, int messageHandlerThreadPoolSize, int connectTimeoutSeconds, int messageResendIntervalSeconds, int blockingTimeoutSeconds)
          Constructs an object to create synchronous clients using an Executor owned by this class.
 
Method Summary
 MqttClient newAsyncClient(AsyncClientListener asyncClientListener)
          Creates an asynchronous client.
 MqttClient newSynchronousClient(MqttClientListener mqttClientListener)
          Creates a synchronous client.
 void shutdown()
          Stops this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         ReconnectionStrategy reconnectionStrategy,
                         int messageHandlerThreadPoolSize,
                         int connectTimeoutSeconds,
                         int messageResendIntervalSeconds,
                         int blockingTimeoutSeconds)
Constructs an object to create synchronous clients using an Executor owned by this class.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
reconnectionStrategy - The algorithm used to reconnect to the broker if the connection is lost
messageHandlerThreadPoolSize - The number of threads used to handle incoming messages and invoke the listener's methods
connectTimeoutSeconds - Seconds to wait for an ack to a connect message before timing out and closing the channel. 0 to wait forever.
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resends
blockingTimeoutSeconds - Seconds until a blocked method invocation times out and an MqttTimeoutException is thrown. -1 will create a non-blocking API, 0 will create a blocking API with no timeout, > 0 will create a blocking API with the specified timeout.

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         ReconnectionStrategy reconnectionStrategy,
                         Executor executor,
                         int connectTimeoutSeconds,
                         int messageResendIntervalSeconds,
                         int blockingTimeoutSeconds)
Constructs an object to create synchronous clients using a user provided Executor.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
reconnectionStrategy - The algorithm used to reconnect to the broker if the connection is lost
executor - The executor used to handle incoming messages and invoke the listener's methods. This class will NOT shut down the executor.
connectTimeoutSeconds - Seconds to wait for an ack to a connect message before timing out and closing the channel. 0 to wait forever.
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resends
blockingTimeoutSeconds - Seconds until a blocked method invocation times out and an MqttTimeoutException is thrown. -1 will create a non-blocking API, 0 will create a blocking API with no timeout, > 0 will create a blocking API with the specified timeout.

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         ReconnectionStrategy reconnectionStrategy,
                         int messageHandlerThreadPoolSize,
                         int connectTimeoutSeconds,
                         int messageResendIntervalSeconds)
Constructs an object to create asynchronous clients using an Executor owned by this class.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
reconnectionStrategy - The algorithm used to reconnect to the broker if the connection is lost
messageHandlerThreadPoolSize - The number of threads used to handle incoming messages and invoke the listener's methods
connectTimeoutSeconds - Seconds to wait for an ack to a connect message before timing out and closing the channel. 0 to wait forever.
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resends

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         ReconnectionStrategy reconnectionStrategy,
                         Executor executor,
                         int connectTimeoutSeconds,
                         int messageResendIntervalSeconds)
Constructs an object to create asynchronous clients using a user provided Executor.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
reconnectionStrategy - The algorithm used to reconnect to the broker if the connection is lost
executor - The executor used to handle incoming messages and invoke the listener's methods. This class will NOT shut down the executor.
connectTimeoutSeconds - Seconds to wait for an ack to a connect message before timing out and closing the channel. 0 to wait forever.
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resends
blockingTimeoutSeconds - Seconds until a blocked method invocation times out and an MqttTimeoutException is thrown. -1 will create a non-blocking API, 0 will create a blocking API with no timeout, > 0 will create a blocking API with the specified timeout.
Method Detail

shutdown

public void shutdown()
Stops this factory. Closes all open connections to the broker. Blocks until shutdown is complete. Any other methods called after this have unpredictable results.


newSynchronousClient

public MqttClient newSynchronousClient(MqttClientListener mqttClientListener)
                                throws IllegalStateException
Creates a synchronous client. You may only use this method if the factory was constructed to create synchronous clients.

Parameters:
mqttClientListener - Handles events from this client's channel
Returns:
A new synchronous client
Throws:
IllegalStateException - If this factory was constructed to create asynchronous clients and not synchronous clients.

newAsyncClient

public MqttClient newAsyncClient(AsyncClientListener asyncClientListener)
                          throws IllegalStateException
Creates an asynchronous client. You may only use this method if the factory was constructed to create asynchronous clients.

Parameters:
asyncClientListener - Handles events from this client's channel
Returns:
A new asynchronous client
Throws:
IllegalStateException - If this factory was constructed to create synchronous clients and not asynchronous clients.


Copyright © 2013. All Rights Reserved.