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, Executor executor, boolean synchronous)
          Constructs an object to create synchronous or asynchronous clients using a user provided Executor with the default config.
MqttClientFactory(String brokerUri, Executor executor, boolean synchronous, MqttClientConfig config)
          Constructs an object to create synchronous or asynchronous clients using a user provided Executor with a custom config.
MqttClientFactory(String brokerUri, int messageHandlerThreadPoolSize, boolean synchronous)
          Constructs an object to create synchronous or asynchronous clients using an Executor owned by this class with the default config.
MqttClientFactory(String brokerUri, int messageHandlerThreadPoolSize, boolean synchronous, MqttClientConfig config)
          Constructs an object to create synchronous or asynchronous clients using an Executor owned by this class with a custom config.
 
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,
                         int messageHandlerThreadPoolSize,
                         boolean synchronous)
Constructs an object to create synchronous or asynchronous clients using an Executor owned by this class with the default config.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
messageHandlerThreadPoolSize - The number of threads used to handle incoming messages and invoke the listener's methods
synchronous - True to create synchronous clients, false to create asynchronous clients. If true then the synchronous clients' blockingTimeoutSeconds will be 0 (wait forever).

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         Executor executor,
                         boolean synchronous)
Constructs an object to create synchronous or asynchronous clients using a user provided Executor with the default config.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
executor - The executor used to handle incoming messages and invoke the listener's methods. This class will NOT shut down the executor.
synchronous - True to create synchronous clients, false to create asynchronous clients. If true then the synchronous clients' blockingTimeoutSeconds will be 0 (wait forever).

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         int messageHandlerThreadPoolSize,
                         boolean synchronous,
                         MqttClientConfig config)
Constructs an object to create synchronous or asynchronous clients using an Executor owned by this class with a custom config.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
messageHandlerThreadPoolSize - The number of threads used to handle incoming messages and invoke the listener's methods
synchronous - True to create synchronous clients, false to create asynchronous clients.
config - The configuration for the client

MqttClientFactory

public MqttClientFactory(String brokerUri,
                         Executor executor,
                         boolean synchronous,
                         MqttClientConfig config)
Constructs an object to create synchronous or asynchronous clients using a user provided Executor with a custom config.

Parameters:
brokerUri - The URL to the broker to connect to. For example, tcp://q.m2m.io:1883
executor - The executor used to handle incoming messages and invoke the listener's methods. This class will NOT shut down the executor.
synchronous - True to create synchronous clients, false to create asynchronous clients.
config - The configuration for the client
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. Use MqttClientListener.NULL_LISTENER if you don't want to receive messages or be notified of events.
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. Use AsyncClientListener.NULL_LISTENER if you don't want to receive messages or be notified of events.
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.