Skip to content

Commit 7c781b1

Browse files
committed
introduce chunk cache concept
1 parent 58a03f5 commit 7c781b1

File tree

5 files changed

+422
-184
lines changed

5 files changed

+422
-184
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package net.sharksystem.aasp;
2+
3+
import java.io.IOException;
4+
import java.util.Iterator;
5+
6+
/**
7+
* Chunks are identified by an URI and ordered by era numbers.
8+
* User applications can often define an URI but would hardly like
9+
* to deal with era management.
10+
*
11+
* This interface helps those applications. Classes implementing that
12+
* interface wrap an actual chunk storage and offer a view of an ordered
13+
* list of message. Especially era management is hidden with this interfaces.
14+
*
15+
* It is meant to be a cache. It is *not* assumed that this cache is
16+
* always in sync with the actual chunk storage. Syncing is up to application
17+
* which makes implementing that cache easier.
18+
*
19+
*
20+
* @author thsc
21+
*/
22+
public interface AASPChunkCache {
23+
/**
24+
*
25+
* @return number of messages fitting to that uri regardless of era
26+
*/
27+
public int getNumberMessage() throws IOException;
28+
29+
/**
30+
*
31+
* @return uri of that chunk cache
32+
*/
33+
public CharSequence getURI();
34+
35+
/**
36+
*
37+
* @param chronologically in chronological order: true: oldest message comes
38+
* first, false: newest message comes first
39+
* @return iterator of all messages in that chunk cache
40+
* @throws IOException
41+
*/
42+
Iterator<CharSequence> getMessages(boolean chronologically) throws IOException;
43+
44+
/**
45+
* Returns a message with a given position
46+
* @param position
47+
* @param chronologically in chronological order: true: oldest message comes
48+
* first, false: newest message comes first
49+
* @return message
50+
* @throws net.sharksystem.aasp.AASPException message on that position does
51+
* not exist
52+
* @throws IOException couldn't read from storage
53+
*/
54+
CharSequence getMessage(int position, boolean chronologically)
55+
throws AASPException, IOException;
56+
57+
/**
58+
* Add a message. Implementations are free to simply delegate that method to
59+
* the underlying chunk storage. They can also decide to keep the cache in
60+
* sync. That could be useful if only one application uses the chunk storage.
61+
* It's up to implementation and using application to clarify semantics
62+
* of this method.
63+
*
64+
* @param message
65+
* @throws IOException
66+
*/
67+
void add(CharSequence message) throws IOException;
68+
69+
}
Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
package net.sharksystem.aasp;
2-
3-
import java.io.IOException;
4-
import java.util.List;
5-
6-
/**
7-
* A storage is a logical unit containing chunks. It offers methods
8-
* to get (and create) and remove (drop) chunks. There is at least
9-
* one storage containing message produced by a local app.
10-
*
11-
* There can be other storages containg messages which arrived from a
12-
* peer during sychronization.
13-
*
14-
* @author thsc
15-
*/
16-
public interface AASPChunkStorage {
17-
18-
public AASPChunk getChunk(CharSequence urlTarget, int era) throws IOException;
19-
20-
public List<AASPChunk> getChunks(int era) throws IOException;
21-
22-
public void dropChunks(int era) throws IOException;
23-
}
1+
package net.sharksystem.aasp;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
/**
7+
* A storage is a logical unit containing chunks. It offers methods
8+
* to get (and create) and remove (drop) chunks. There is at least
9+
* one storage containing message produced by a local app.
10+
*
11+
* There can be other storages containg messages which arrived from a
12+
* peer during sychronization.
13+
*
14+
* @author thsc
15+
*/
16+
public interface AASPChunkStorage {
17+
18+
public AASPChunk getChunk(CharSequence uri, int era) throws IOException;
19+
20+
public List<AASPChunk> getChunks(int era) throws IOException;
21+
22+
public void dropChunks(int era) throws IOException;
23+
24+
/**
25+
*
26+
* @param uri chunk storage uri
27+
* @param fromEra oldest era
28+
* @param toEra youngest era
29+
* @return a chunk cache which hides details of era
30+
* @throws IOException
31+
*/
32+
public AASPChunkCache getAASPChunkCache(CharSequence uri, int fromEra,
33+
int toEra) throws IOException;
34+
}

0 commit comments

Comments
 (0)