|
| 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 | +} |
0 commit comments