net.sf.xenqtt.client
Class MqttClientFactory

java.lang.Object
  extended by net.sf.xenqtt.client.MqttClientFactory
All Implemented Interfaces:
AsyncClientFactory, ClientFactory, SyncClientFactory

public final class MqttClientFactory
extends Object
implements AsyncClientFactory, SyncClientFactory

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
 MessageStats getStats(boolean reset)
           
 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()
Description copied from interface: ClientFactory
Stops this factory. Closes all open connections to the broker. Blocks until shutdown is complete. Any other methods called after this have unpredictable results.

Specified by:
shutdown in interface ClientFactory
See Also:
ClientFactory.shutdown(), ClientFactory.shutdown()

newSynchronousClient

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

Specified by:
newSynchronousClient in interface SyncClientFactory
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.
See Also:
SyncClientFactory.newSynchronousClient(net.sf.xenqtt.client.MqttClientListener)

newAsyncClient

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

Specified by:
newAsyncClient in interface AsyncClientFactory
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.
See Also:
AsyncClientFactory.newAsyncClient(net.sf.xenqtt.client.AsyncClientListener)

getStats

public MessageStats getStats(boolean reset)
Specified by:
getStats in interface ClientFactory
Parameters:
reset - If true the stats will be reset to 0 (where applicable) so the next time they are retrieved they will be for the time between the 2 calls to this method.
Returns:
A snapshot of the statistics for all the clients created by this factory.
See Also:
ClientFactory.getStats(boolean)


Copyright © 2013. All Rights Reserved.