|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.xenqtt.message.ChannelManagerImpl
public final class ChannelManagerImpl
Uses a single thread and non-blocking NIO to manage one or more MqttChannels. You must call init() before using this manager and
shutdown() to shut it down.
| Constructor Summary | |
|---|---|
ChannelManagerImpl(long messageResendIntervalSeconds)
Use this constructor for the asynchronous API |
|
ChannelManagerImpl(long messageResendIntervalSeconds,
int blockingTimeoutSeconds)
Use this constructor for the synchronous API |
|
| Method Summary | ||
|---|---|---|
void |
attachChannel(MqttChannelRef channel,
MessageHandler messageHandler)
Attaches the specified channel to this manager's control. |
|
void |
cancelBlockingCommands(MqttChannelRef channel)
Cancels all blocking commands for the specified channel. |
|
void |
close(MqttChannelRef channel)
Closes the specified channel. |
|
void |
close(MqttChannelRef channel,
Throwable cause)
Closes the specified channel and sends cause to the MessageHandler.channelClosed(MqttChannel, Throwable) callback. |
|
void |
detachChannel(MqttChannelRef channel)
Detaches the specified channel from this manager's control. |
|
MessageStats |
getStats(boolean reset)
Request the current snapshot of statistics that are available from this channel manager. |
|
List<MqttMessage> |
getUnsentMessages(MqttChannelRef channel)
|
|
void |
init()
Starts this channel manager. |
|
boolean |
isRunning()
|
|
MqttChannelRef |
newBrokerChannel(SocketChannel socketChannel,
MessageHandler messageHandler)
Create a new broker side MqttChannelRef for use in exchanging data using the MQTT protocol. |
|
MqttChannelRef |
newClientChannel(String host,
int port,
MessageHandler messageHandler)
Create a new client side MqttChannelRef for use in exchanging data using the MQTT protocol. |
|
MqttChannelRef |
newClientChannel(String brokerUri,
MessageHandler messageHandler)
Create a new client side MqttChannelRef for use in exchanging data using the MQTT protocol. |
|
MqttChannelRef |
newClientChannel(URI brokerUri,
MessageHandler messageHandler)
Create a new client side MqttChannelRef for use in exchanging data using the MQTT protocol. |
|
|
send(MqttChannelRef channel,
MqttMessage message)
Send a message over a specified channel. |
|
void |
shutdown()
Stops this channel manager. |
|
void |
transfer(MqttChannelRef oldChannel,
MqttChannelRef newChannel)
Transfers unsent messages from oldChannel to newChannel and changes oldChannel such that any messages sent to it will actually go to newChannel. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ChannelManagerImpl(long messageResendIntervalSeconds)
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resends
public ChannelManagerImpl(long messageResendIntervalSeconds,
int blockingTimeoutSeconds)
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resendsblockingTimeoutSeconds - 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 |
|---|
public void init()
ChannelManager
init in interface ChannelManagerChannelManager.init()public void shutdown()
ChannelManager
shutdown in interface ChannelManagerChannelManager.shutdown()public boolean isRunning()
isRunning in interface ChannelManagerChannelManager.isRunning()
public MqttChannelRef newClientChannel(String brokerUri,
MessageHandler messageHandler)
throws MqttInterruptedException
ChannelManagerMqttChannelRef for use in exchanging data using the MQTT protocol. This is the client end of the connection. The broker
will have the remote end of the connection. This method only blocks long enough for the channel to be created, not for the TCP connection to happen.
newClientChannel in interface ChannelManagerbrokerUri - URI of the broker to connect to. For example, tcp://q.m2m.io:1883.messageHandler - The message handler to use for all received messages
MessageHandler callback methods.
MqttInterruptedException - Thrown when the calling thread is interruptedChannelManager.newClientChannel(java.lang.String, net.sf.xenqtt.message.MessageHandler)
public MqttChannelRef newClientChannel(URI brokerUri,
MessageHandler messageHandler)
throws MqttInterruptedException
ChannelManagerMqttChannelRef for use in exchanging data using the MQTT protocol. This is the client end of the connection. The broker
will have the remote end of the connection. This method only blocks long enough for the channel to be created, not for the TCP connection to happen. This
will throw a RuntimeException wrapping any exception thrown while initializing the connection like UnresolvedAddressException
newClientChannel in interface ChannelManagerbrokerUri - URI of the broker to connect to. For example, tcp://q.m2m.io:1883.messageHandler - The message handler to use for all received messages
MessageHandler callback methods.
MqttInterruptedException - Thrown when the calling thread is interruptedChannelManager.newClientChannel(java.net.URI, net.sf.xenqtt.message.MessageHandler)
public MqttChannelRef newClientChannel(String host,
int port,
MessageHandler messageHandler)
throws MqttInterruptedException
ChannelManagerMqttChannelRef for use in exchanging data using the MQTT protocol. This is the client end of the connection. The broker
will have the remote end of the connection. This method only blocks long enough for the channel to be created, not for the TCP connection to happen. This
will throw a RuntimeException wrapping any exception thrown while initializing the connection like UnresolvedAddressException
newClientChannel in interface ChannelManagerhost - The host name to connect toport - The port to connect tomessageHandler - The message handler to use for all received messages
MessageHandler callback methods.
MqttInterruptedException - Thrown when the calling thread is interruptedChannelManager.newClientChannel(java.lang.String, int, net.sf.xenqtt.message.MessageHandler)
public MqttChannelRef newBrokerChannel(SocketChannel socketChannel,
MessageHandler messageHandler)
throws MqttInterruptedException
ChannelManagerMqttChannelRef for use in exchanging data using the MQTT protocol. This is the broker end of the connection. The client
will have the remote end of the connection. If an exception is thrown the socketChannel will be closed. This method only blocks long enough for the
channel to be created.
newBrokerChannel in interface ChannelManagersocketChannel - The channel to communicate overmessageHandler - The message handler to use for all received messages
MessageHandler callback methods.
MqttInterruptedException - Thrown when the calling thread is interruptedChannelManager.newBrokerChannel(java.nio.channels.SocketChannel, net.sf.xenqtt.message.MessageHandler)
public <T extends MqttMessage> T send(MqttChannelRef channel,
MqttMessage message)
throws MqttInterruptedException
ChannelManagermessage over a specified channel. This method only blocks until the message is queued to send to the channel.
send in interface ChannelManagerchannel - The channel to send the message over. This channel should have been previously created via the
#newChannel(String, int, MessageHandler) or #newChannel(SocketChannel, MessageHandler) methodsmessage - The message to send. This can be any type of MQTT message
ConnectMessage or has a
QoS > 0.
MqttInterruptedException - Thrown when the calling thread is interruptedChannelManager.send(net.sf.xenqtt.message.MqttChannelRef, net.sf.xenqtt.message.MqttMessage)
public void close(MqttChannelRef channel)
throws MqttInterruptedException
ChannelManager
close in interface ChannelManagerMqttInterruptedException - Thrown when the calling thread is interruptedChannelManager.close(net.sf.xenqtt.message.MqttChannelRef)
public void close(MqttChannelRef channel,
Throwable cause)
ChannelManagerMessageHandler.channelClosed(MqttChannel, Throwable) callback. This method blocks until the
channel is closed.
close in interface ChannelManagerChannelManager.close(net.sf.xenqtt.message.MqttChannelRef, java.lang.Throwable)public void cancelBlockingCommands(MqttChannelRef channel)
ChannelManagerCancels all blocking commands for the specified channel. This is not done when the channel is closed because we may want
to reconnect instead of releasing the commands.
cancelBlockingCommands in interface ChannelManagerChannelManager.cancelBlockingCommands(net.sf.xenqtt.message.MqttChannelRef)public List<MqttMessage> getUnsentMessages(MqttChannelRef channel)
getUnsentMessages in interface ChannelManagerChannelManager.getUnsentMessages(net.sf.xenqtt.message.MqttChannelRef)
public void transfer(MqttChannelRef oldChannel,
MqttChannelRef newChannel)
ChannelManager
transfer in interface ChannelManagerChannelManager.transfer(net.sf.xenqtt.message.MqttChannelRef, net.sf.xenqtt.message.MqttChannelRef)
public void detachChannel(MqttChannelRef channel)
throws MqttCommandCancelledException,
MqttTimeoutException,
MqttInterruptedException,
MqttInvocationException,
MqttInvocationError
ChannelManager#attachChannel(MqttChannelRef) to move handling of
the channel's messages from one manager to another. This is always a synchronous operation. It is safe to call this from the ChannelManagerImpl
IO thread.
detachChannel in interface ChannelManagerchannel - The channel to detach
MqttCommandCancelledException - The channel manager uses a command pattern to process this request on the IO thread. If the command is cancelled for some reason, like the
channel closes, this exception is thrown.
MqttTimeoutException - Thrown when using a synchronous implementation and the timeout specified for a blocked method expires
MqttInterruptedException - Thrown when the calling thread is interrupted
MqttInvocationException - The channel manager uses a command pattern to process this request on the IO thread. Any Exception thrown while the command is being
processed will be wrapped in an MqttInvocationException.
MqttInvocationError - The channel manager uses a command pattern to process this request on the IO thread. Any Error thrown while the command is being
processed will be wrapped in an MqttInvocationError.ChannelManager.detachChannel(net.sf.xenqtt.message.MqttChannelRef)
public void attachChannel(MqttChannelRef channel,
MessageHandler messageHandler)
throws MqttCommandCancelledException,
MqttTimeoutException,
MqttInterruptedException,
MqttInvocationException,
MqttInvocationError
ChannelManagerChannelManager.detachChannel(MqttChannelRef) to move handling of the
channel's messages from one manager to another. This is always a synchronous operation.
attachChannel in interface ChannelManagerchannel - The channel to attachmessageHandler - The message handler to use for all received messages
MqttCommandCancelledException - The channel manager uses a command pattern to process this request on the IO thread. If the command is cancelled for some reason, like the
channel closes, this exception is thrown.
MqttTimeoutException - Thrown when using a synchronous implementation and the timeout specified for a blocked method expires
MqttInterruptedException - Thrown when the calling thread is interrupted
MqttInvocationException - The channel manager uses a command pattern to process this request on the IO thread. Any Exception thrown while the command is being
processed will be wrapped in an MqttInvocationException.
MqttInvocationError - The channel manager uses a command pattern to process this request on the IO thread. Any Error thrown while the command is being
processed will be wrapped in an MqttInvocationError.ChannelManager.attachChannel(net.sf.xenqtt.message.MqttChannelRef, net.sf.xenqtt.message.MessageHandler)public MessageStats getStats(boolean reset)
ChannelManagerchannel manager.
getStats in interface ChannelManagerreset - If true following the acquisition of the statistics all applicable counters that can be reset will be. This is useful if statistics
are being gathered and reported at regular intervals and the desire is to see the statistics for the previous interval
statistics for the MQTT clientChannelManager.getStats(boolean)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||