public class XMPPPacketWriter extends Object implements Writer, PacketCollector, ReconnectionListener
Writer implementation which writes XMPP packets onto wire.
XMPPConnection and TCPConnection are not thread-safe.
Moreover, a socket does not permit concurrent writes; therefore,
XMPPPacketWriter enforces serial execution of write calls which may
be triggered by different threads.
XMPPPacketWriter keeps track of the packets for which client has
received ACK from the server. If the client does not receive ACK from server
for a Packet in stipulated time, client assumes that connection to
server is broken. It could be that device does not have Internet connection;
or something unexpected has broken the connection.
| Constructor and Description |
|---|
XMPPPacketWriter(XMPPConnection connection) |
| Modifier and Type | Method and Description |
|---|---|
void |
collect(Packet packet)
This collector takes the given packet.
|
boolean |
isShutdown() |
boolean |
isWriting() |
void |
reconnected()
Call if reconnection is successful
|
void |
reconnectionFailed()
Call if reconnection failed.
|
void |
reconnectionStarted()
Call when reconnection is triggered
|
boolean |
shutdown()
Shutdown the writer after writing all the queued packets; however writer
will stop accepting packets for writing immediately.
|
boolean |
shutdownNow()
Shutdown the writer immediately.
|
void |
start()
Start
Writer; this will start writer thread and will turn on the
'Started' flag. |
String |
toString() |
boolean |
writeAsync(Stanza stanza)
Add a Stanza to writerWaitingQ.
|
boolean |
writeNextAsync(Stanza stanza)
Add a Stanza at the HEAD of writerWaitingQ.
|
void |
writeSync(Packet packet)
Write packets on to the wire directly bypassing normal flow of
XMPPPacketWriter process. |
public XMPPPacketWriter(XMPPConnection connection)
public void start()
WriterWriter; this will start writer thread and will turn on the
'Started' flag.public boolean writeAsync(Stanza stanza)
writeAsync in interface Writerstanza - Stanza packet to be sent to serverpublic boolean writeNextAsync(Stanza stanza)
WriterwriteNextAsync in interface Writerstanza - Stanza packet to be sent to serverpublic void collect(Packet packet)
PacketCollectorcollect in interface PacketCollectorpacket - packet instance to be collectedpublic boolean isWriting()
public boolean isShutdown()
isShutdown in interface Writerpublic void reconnectionStarted()
ReconnectionListenerreconnectionStarted in interface ReconnectionListenerpublic void reconnected()
ReconnectionListenerreconnected in interface ReconnectionListenerpublic void reconnectionFailed()
ReconnectionListenerreconnectionFailed in interface ReconnectionListenerpublic void writeSync(Packet packet) throws NetworkException
XMPPPacketWriter process. This method has restricted access and
meant to be used by SDK only; specifically StreamNegotiator
While stream negotiations are in progress, writer thread waits for negotiation process to finish. In this case, anything added to writer queue will not be processed by writer thread.
writeSync in interface Writerpacket - packet to be writtenNetworkException - when IO error occurrs, device does not have
internet or connection is not connectedpublic boolean shutdown()
Writerpublic boolean shutdownNow()
WritershutdownNow in interface WriterCopyright © 2019. All rights reserved.