Skip to content

ASAPStorage

Thomas Schwotzer edited this page Jan 28, 2021 · 33 revisions

Each ASAP application keeps its data in an ASAPStorage.

There is not need for ASAP application to access those storages at all. On the contrary, it is a really good idea to build an ASAP application that uses this library only as it was planned to be: a message routing protocol.

Nevertheless, messages are stored. And sometimes it might be easier or requires less resource to just access those messages instead of keeping a copy in an application specific database. We cannot make that decision but provide a documentation. The general concept of ASAP message storing is explained. Some specifics and deeper insights into the API come later.

Application can send and receive messages with the ASAPPeer interface. A message is sent with a specific format.

There is an ASAPStorage for each format. An ASAPStorage keeps all messages of an ASAP application. It can be seen as an in- and outbox in an e-mail system.

Each ASAPStorage has got an ASAPChunkStorage which holds a number of ASAPChunks. A chunk is a collection of ASAP message with the same uri. There are at least as many different chunks different uris in our application. This code snippet is from was used to explain [how to send a message(./Implement-an-ASAP-application#send-a-message).

public static final String FORMAT = "application/x-YOUR_APP_FORMAT";
public static final String MESSAGE_URI = "YOUR_APP://message";
...
ASAPPeer yourPeer = ..;
...
byte[] yourMessageContent = ..; // create it

// send message
yourPeer.sendASAPMessage(FORMAT , MESSAGE_URI , yourMessageContent);

This message is stored for later or immediate (usally both) delivery. The following code illustrates how to get access to the ChunkStorage where this message is stored:

public static final String FORMAT = "application/x-YOUR_APP_FORMAT";
...
ASAPPeer asapPeer = ..; // got an object reference from somewhere else
ASAPStorage  asapStorage = asapPeer.getASAPStorage(FORMAT);
ASAPChunkStorage chunkStorage = asapStorage.getChunkStorage();

There is one other thing to understand before we get access to our message again: It is the era.

Each ASAPStorage has got an era. It is initialized with zero. The era can be changed whenever a) the peer encounters another one or loses a connection. The era is changed if b) also at least one new message was added to this storage by calling yourPeer.sendMessage().