public final class BOSHClient extends Object
BOSHClientConfig cfg = BOSHClientConfig.Builder.create( "http://server:1234/httpbind", "jabber.org") .setFrom("user@jabber.org") .build(); BOSHClient client = BOSHClient.create(cfg);Additional client configuration options are available. See the
BOSHClientConfig.Builder
class for more information.
Once a BOSHClient
instance has been created, communication with
the remote connection manager can begin. No attempt will be made to
establish a connection to the connection manager until the first call
is made to the send(ComposableBody)
method. Note that it is
possible to send an empty body to cause an immediate connection attempt
to the connection manager. Sending an empty message would look like
the following:
client.send(ComposableBody.builder().build());For more information on creating body messages with content, see the
ComposableBody.Builder
class documentation.
Once a session has been successfully started, the client instance can be
used to send arbitrary payload data. All aspects of the BOSH
protocol involving setting and processing attributes in the BOSH
namespace will be handled by the client code transparently and behind the
scenes. The user of the client instance can therefore concentrate
entirely on the content of the message payload, leaving the semantics of
the BOSH protocol to the client implementation.
To be notified of incoming messages from the remote connection manager,
a BOSHClientResponseListener
should be added to the client instance.
All incoming messages will be published to all response listeners as they
arrive and are processed. As with the transmission of payload data via
the send(ComposableBody)
method, there is no need to worry about
handling of the BOSH attributes, since this is handled behind the scenes.
If the connection to the remote connection manager is terminated (either
explicitly or due to a terminal condition of some sort), all connection
listeners will be notified. After the connection has been closed, the
client instance is considered dead and a new one must be created in order
to resume communications with the remote server.
Instances of this class are thread-safe.Modifier and Type | Method and Description |
---|---|
void |
addBOSHClientConnListener(BOSHClientConnListener listener)
Adds a connection listener to the session.
|
void |
addBOSHClientRequestListener(BOSHClientRequestListener listener)
Adds a request message listener to the session.
|
void |
addBOSHClientResponseListener(BOSHClientResponseListener listener)
Adds a response message listener to the session.
|
void |
close()
Forcibly close this client session instance.
|
static BOSHClient |
create(BOSHClientConfig clientCfg)
Create a new BOSH client session using the client configuration
information provided.
|
void |
disconnect()
End the BOSH session by disconnecting from the remote BOSH connection
manager.
|
void |
disconnect(ComposableBody msg)
End the BOSH session by disconnecting from the remote BOSH connection
manager, sending the provided content in the final connection
termination message.
|
BOSHClientConfig |
getBOSHClientConfig()
Get the client configuration that was used to create this client
instance.
|
boolean |
pause()
Attempt to pause the current session.
|
void |
removeBOSHClientConnListener(BOSHClientConnListener listener)
Removes a connection listener from the session.
|
void |
removeBOSHClientRequestListener(BOSHClientRequestListener listener)
Removes a request message listener from the session, if previously
added.
|
void |
removeBOSHClientResponseListener(BOSHClientResponseListener listener)
Removes a response message listener from the session, if previously
added.
|
void |
send(ComposableBody body)
Send the provided message data to the remote connection manager.
|
public static BOSHClient create(BOSHClientConfig clientCfg)
clientCfg
- session configurationpublic BOSHClientConfig getBOSHClientConfig()
public void addBOSHClientConnListener(BOSHClientConnListener listener)
listener
- connection listener to add, if not already addedpublic void removeBOSHClientConnListener(BOSHClientConnListener listener)
listener
- connection listener to remove, if previously addedpublic void addBOSHClientRequestListener(BOSHClientRequestListener listener)
listener
- request listener to add, if not already addedpublic void removeBOSHClientRequestListener(BOSHClientRequestListener listener)
listener
- instance to removepublic void addBOSHClientResponseListener(BOSHClientResponseListener listener)
listener
- response listener to add, if not already addedpublic void removeBOSHClientResponseListener(BOSHClientResponseListener listener)
listener
- instance to removepublic void send(ComposableBody body) throws BOSHException
body
- message data to send to remote serverBOSHException
- on message transmission failurepublic boolean pause()
true
if the connection manager supports session pausing,
false
if the connection manager does not support session
pausing or if the session has not yet been establishedpublic void disconnect() throws BOSHException
BOSHException
- when termination message cannot be sentpublic void disconnect(ComposableBody msg) throws BOSHException
msg
- final message to sendBOSHException
- when termination message cannot be sentpublic void close()
Copyright © 2020. All rights reserved.