public class DefaultPersistenceMechanism extends Object implements UndeliveredStanzaManager.PersistenceMechanism
UndeliveredStanzaManager.PersistenceMechanism interface. User
packets generated on a client are queued up and marked delivered only when a
ACK is received from the server. The packets for which ACK has been received
are removed from the queue. Typically, when underlying network connection is
broken ACK packets are not recceived; if ACK is not received from the server
witin stipulated time, the SDK will try to resend undelivered packets to
server.
While undelieverd packets are queued up in writer's queue, it may happen that SDK is off-loaded from memory (there could be many possible reasons such as power failure on underlying device, application was killed forcefully, device shutdown, application may crash due to a programming bug etc) and if the SDK is off-loaded from memory, undelivered message queues will be wiped out too. Therefore it is importatnt to persist undelivered messsages to avoid message loss.
XMPP as a protocol does not recommend a mechanism to avoid undelievred message loss. However Stringflow SDK provides a default mechanism to persist undelivered messages on to a file. This class is the default implementation in which message are written on to a file. The packets are serialized before getting written to a file. It is application developer's responsibility to ensure that SDK has enough permissions to be able to create/write file on the underlying file system.
UndeliveredStanzaManager.PersistenceMechanism is an injectable interface; application
developers can inject an implementation of UndeliveredStanzaManager.PersistenceMechanism
interface which, instead of DefaultPersistenceMechanism, will be used
to persist packets.
| Constructor and Description |
|---|
DefaultPersistenceMechanism(String dirPath)
Instantiate
DefaultPersistenceMechanism object with a directory
path in which files will be created. |
| Modifier and Type | Method and Description |
|---|---|
List<Stanza> |
readAll()
Read all the stanzas from persistent store and delete them.
|
void |
remove(int count)
Remove number of stanza from persistent store.
|
void |
truncateUndeliverStanzas()
Delete All stanzas from store.
|
void |
write(List<Stanza> stanzas)
Write a stanza to persistent store.
|
void |
write(Stanza stanza)
Write a stanza to persistent store.
|
public DefaultPersistenceMechanism(String dirPath) throws Exception
DefaultPersistenceMechanism object with a directory
path in which files will be created. If the given path name does not
exist, a directory representing the path will be created. If the given
path name exist but represents a regualr file not a directory a
FileNotFoundException exception will be thrown.dirPath - directory path on the file system in which data files will
be stored. The may or may not exist; it could be relative or
absolute pathException - if there is permission issue or any other error while
setting up the files and directoriespublic void write(Stanza stanza) throws IOException
UndeliveredStanzaManager.PersistenceMechanismwrite in interface UndeliveredStanzaManager.PersistenceMechanismstanza - stanzaIOException - IOExceptionpublic void write(List<Stanza> stanzas) throws IOException
UndeliveredStanzaManager.PersistenceMechanismwrite in interface UndeliveredStanzaManager.PersistenceMechanismstanzas - stanzasIOException - IOExceptionpublic void remove(int count)
throws IOException
UndeliveredStanzaManager.PersistenceMechanismremove in interface UndeliveredStanzaManager.PersistenceMechanismcount - stanzaCountIOException - IOExceptionpublic List<Stanza> readAll() throws IOException
UndeliveredStanzaManager.PersistenceMechanismreadAll in interface UndeliveredStanzaManager.PersistenceMechanismIOException - IOExceptionpublic void truncateUndeliverStanzas()
UndeliveredStanzaManager.PersistenceMechanismtruncateUndeliverStanzas in interface UndeliveredStanzaManager.PersistenceMechanismCopyright © 2019. All rights reserved.