|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ChannelManager
Specifies a type that manages zero or more channels
that communicate via the MQTT protocol.
All of the methods in this specification are thread-safe. Implementations may be blocking or non-blocking
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. |
Method Detail |
---|
MqttChannelRef newClientChannel(String brokerUri, MessageHandler messageHandler) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
MqttChannelRef
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.
brokerUri
- 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.
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
.MqttChannelRef newClientChannel(URI brokerUri, MessageHandler messageHandler) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
MqttChannelRef
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
brokerUri
- 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.
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
.MqttChannelRef newClientChannel(String host, int port, MessageHandler messageHandler) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
MqttChannelRef
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
host
- The host name to connect toport
- The port to connect tomessageHandler
- The message handler
to use for all received messages
MessageHandler
callback methods.
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
.MqttChannelRef newBrokerChannel(SocketChannel socketChannel, MessageHandler messageHandler) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
MqttChannelRef
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.
socketChannel
- The channel
to communicate overmessageHandler
- The message handler
to use for all received messages
MessageHandler
callback methods.
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
.<T extends MqttMessage> T send(MqttChannelRef channel, MqttMessage message) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
message
over a specified channel
. This method only blocks until the message is queued to send to the channel.
channel
- 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.
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
.void close(MqttChannelRef channel) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
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
.void close(MqttChannelRef channel, Throwable cause) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
MessageHandler.channelClosed(MqttChannel, Throwable)
callback. This method blocks until the
channel is closed.
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
.void cancelBlockingCommands(MqttChannelRef channel) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
Cancels
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.
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
.List<MqttMessage> getUnsentMessages(MqttChannelRef channel) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
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
.void transfer(MqttChannelRef oldChannel, MqttChannelRef newChannel) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
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
.void detachChannel(MqttChannelRef channel) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
#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.
channel
- 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
.void attachChannel(MqttChannelRef channel, MessageHandler messageHandler) throws MqttCommandCancelledException, MqttTimeoutException, MqttInterruptedException, MqttInvocationException, MqttInvocationError
detachChannel(MqttChannelRef)
to move handling of the
channel's messages from one manager to another. This is always a synchronous operation.
channel
- 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
.void init()
void shutdown()
boolean isRunning()
MessageStats getStats(boolean reset)
channel manager
.
reset
- 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 client
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |