public class DataModel
extends java.lang.Object
implements java.io.Closeable
A DataModel is a container of Chunks, optionally registered to different 'segments' of the DataModel. Each Chunk defines its own CRUD operations on its own classes. Some Chunks might merely hold objects in memory, whilst others might persist objects via a network API or local database. In all cases, the Chunks present a consistent interface. Chunks themselves are accessed synchronously, however when registered on a DataModel they can be accessed asynchronously. Chunks are registered on the DataModel with an optional 'segment', that is a key that addresses possibly many Chunks.
Modifier and Type | Class and Description |
---|---|
class |
DataModel.CompositeIOException |
Constructor and Description |
---|
DataModel() |
Modifier and Type | Method and Description |
---|---|
void |
addChunk(Chunk chunk)
Add a Chunk to the default segment of this DataModel.
|
void |
addChunk(Chunk chunk,
java.util.concurrent.ExecutorService executor)
Add a Chunk to the default segment of this DataModel.
|
void |
addChunk(java.lang.String segment,
Chunk chunk)
Add a Chunk to the given segment of this DataModel.
|
void |
addChunk(java.lang.String segment,
Chunk chunk,
java.util.concurrent.ExecutorService executor)
Add a Chunk to the given segment of this DataModel.
|
void |
close()
Close all registered chunks
|
<K> java.util.concurrent.Future<java.util.List<java.lang.Integer>> |
delete(K key,
DeleteEventFactory... deleteEventFactories)
Delete the given key from all Chunks registered at the default segment of the DataModel.
|
<K> java.util.concurrent.Future<java.util.List<java.lang.Integer>> |
delete(java.lang.String segment,
K key,
DeleteEventFactory... deleteEventFactories)
Delete the given key from all Chunks registered at the default segment of the DataModel.
|
<V> java.util.concurrent.Future<java.util.List<java.lang.Object>> |
insert(java.lang.String segment,
V value,
InsertEventFactory... insertEventFactories)
Insert the given value to all Chunks registered at the given segment of the DataModel.
|
<V> java.util.concurrent.Future<java.util.List<java.lang.Object>> |
insert(V value,
InsertEventFactory... insertEventFactories)
Insert the given value to all Chunks registered at the default segment of the DataModel.
|
<K> java.util.concurrent.Future<java.util.List<QueryResult<java.lang.Object>>> |
query(K key,
QueryEventFactory... queryEventFactories)
Query the given key at all Chunks registered at the given segment of the DataModel.
|
<K> java.util.concurrent.Future<java.util.List<QueryResult<java.lang.Object>>> |
query(java.lang.String segment,
K key,
QueryEventFactory... queryEventFactories)
Query the given key at all Chunks registered at the default segment of the DataModel.
|
<K,V> java.util.concurrent.Future<java.util.List<java.lang.Integer>> |
update(K key,
V value,
UpdateEventFactory... updateEventFactories)
Update the given key with the given value at all Chunks registered at the default segment of the DataModel.
|
<K,V> java.util.concurrent.Future<java.util.List<java.lang.Integer>> |
update(java.lang.String segment,
K key,
V value,
UpdateEventFactory... updateEventFactories)
Update the given key with the given value at all Chunks registered at the given segment of the DataModel.
|
public void addChunk(Chunk chunk)
chunk
- The Chunk to addpublic void addChunk(java.lang.String segment, Chunk chunk)
segment
- A String naming the segmentchunk
- The Chunk to addpublic void addChunk(Chunk chunk, java.util.concurrent.ExecutorService executor)
chunk
- The Chunk to addexecutor
- The ExecutorService on which to run the Chunk operations. If null, a default single-threaded
ExecutorService will be used.public void addChunk(java.lang.String segment, Chunk chunk, java.util.concurrent.ExecutorService executor)
segment
- A String naming the segmentchunk
- The Chunk to addexecutor
- The ExecutorService on which to run the Chunk operations. If null, a default single-threaded
ExecutorService will be used.public <K> java.util.concurrent.Future<java.util.List<java.lang.Integer>> delete(K key, DeleteEventFactory... deleteEventFactories)
Optional event factories may be given, which are forwarded to the Chunk's delete method. These events will be dispatched, in addition to events from any DeleteEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunks' delete operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
K
- The type of the key on the Chunks.key
- The key to delete.deleteEventFactories
- An optional list of DeleteEventFactory used to generate events for this operation.public <K> java.util.concurrent.Future<java.util.List<java.lang.Integer>> delete(java.lang.String segment, K key, DeleteEventFactory... deleteEventFactories)
Optional event factories may be given, which are forwarded to the Chunk's delete method. These events will be dispatched, in addition to events from any DeleteEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunks' delete operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
K
- The type of the key on the Chunks.segment
- A String naming the segment to apply the operation. The delete operation will be propagated
to all Chunks registered at the segment.key
- The key to delete.deleteEventFactories
- An optional list of DeleteEventFactory used to generate events for this operation.public <V> java.util.concurrent.Future<java.util.List<java.lang.Object>> insert(V value, InsertEventFactory... insertEventFactories)
Optional event factories may be given, which are forwarded to the Chunks' insert method. These events will be dispatched, in addition to events from any InsertEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunk's insert operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
V
- The type of the value on the Chunks.value
- The value to insert.insertEventFactories
- An optional list of InsertEventFactory used to generate events for this operation.public <V> java.util.concurrent.Future<java.util.List<java.lang.Object>> insert(java.lang.String segment, V value, InsertEventFactory... insertEventFactories)
Optional event factories may be given, which are forwarded to the Chunks' insert method. These events will be dispatched, in addition to events from any InsertEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunk's insert operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
V
- The type of the value on the Chunks.segment
- A String naming the segment to apply the operation. The insert operation will be propagated
to all Chunks registered at the segment.value
- The value to insert.insertEventFactories
- An optional list of InsertEventFactory used to generate events for this operation.public <K> java.util.concurrent.Future<java.util.List<QueryResult<java.lang.Object>>> query(K key, QueryEventFactory... queryEventFactories)
Optional event factories may be given, which are forwarded to the Chunks' query method. These events will be dispatched, in addition to events from any QueryEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunk's query operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
K
- The type of the key on the Chunks.key
- The key to query.queryEventFactories
- An optional list of QueryEventFactory used to generate events for this operation.public <K> java.util.concurrent.Future<java.util.List<QueryResult<java.lang.Object>>> query(java.lang.String segment, K key, QueryEventFactory... queryEventFactories)
Optional event factories may be given, which are forwarded to the Chunks' query method. These events will be dispatched, in addition to events from any QueryEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunk's query operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
K
- The type of the key on the Chunks.segment
- A String naming the segment to apply the operation. The query operation will be propagated
to all Chunks registered at the segment.key
- The key to query.queryEventFactories
- An optional list of QueryEventFactory used to generate events for this operation.public <K,V> java.util.concurrent.Future<java.util.List<java.lang.Integer>> update(K key, V value, UpdateEventFactory... updateEventFactories)
Optional event factories may be given, which are forwarded to the Chunks' query method. These events will be dispatched, in addition to events from any QueryEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunk's query operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
K
- The type of the key on the Chunks.V
- The type of the value on the Chunks.key
- The key to update.value
- The value to update.updateEventFactories
- An optional list of UpdateEventFactory used to generate events for this operation.public <K,V> java.util.concurrent.Future<java.util.List<java.lang.Integer>> update(java.lang.String segment, K key, V value, UpdateEventFactory... updateEventFactories)
Optional event factories may be given, which are forwarded to the Chunks' query method. These events will be dispatched, in addition to events from any QueryEventFactory already added to the respective Chunk.
This method returns a Future containing a List of results from each registered Chunk's query operation. Rather than wait on the result of this future, client code should usually await a event from an EventFactory.
K
- The type of the key on the Chunks.V
- The type of the value on the Chunks.segment
- A String naming the segment to apply the operation. The update operation will be propagated
to all Chunks registered at the segment.key
- The key to update.value
- The value to update.updateEventFactories
- An optional list of UpdateEventFactory used to generate events for this operation.public void close() throws DataModel.CompositeIOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
DataModel.CompositeIOException