public class ReadWriteLockDataStore extends Object implements InMemoryDataStore, ObservableDataStore
data store and their methods are thread-safe.
The data store provides the capability of an adding observers which
are able to listen any changes in the data store.| Constructor and Description |
|---|
ReadWriteLockDataStore() |
| Modifier and Type | Method and Description |
|---|---|
void |
addObserver(DataStoreObserver observer)
Adds an
observer
to the set of observers for this observable object
ObservableDataStore. |
void |
deleteObserver(DataStoreObserver observer)
Deletes an
observer
from the set of observers of this object. |
<T extends Serializable> |
get(String key,
Class<T> type)
Retrieve data from the data store.
|
Collection<Serializable> |
getAll() |
void |
load(InputStream in)
Load content of the data store from an input stream.
|
<T extends Serializable> |
put(String key,
T data)
Store new data or replace existing data stored under a
key with the new
data. |
void |
save(OutputStream out)
Save current content of the data store to an output stream.
|
public <T extends Serializable> Serializable put(String key, T data)
InMemoryDataStorekey with the new
data.
The method throws an exception if the key is null.put in interface InMemoryDataStorekey - a unique identifier of the location where the data should be
stored or replaced. Must not be null.data - new data to be stored under the given key. May be null,
in which case the data will be removed from the store.null if there are no data stored under the given key
or any replaced data previously stored under the key.public <T extends Serializable> T get(String key, Class<T> type)
InMemoryDataStorekey from the data store
and returns the data cast into the Java type specified by type parameter.get in interface InMemoryDataStorekey - a unique identifier of the location from which the stored data should be
retrieved. Must not be null.type - expected Java type of the data being retrieved. Must not be null.null if there are no data stored under the given
key.public void save(OutputStream out) throws IOException
InMemoryDataStoresave in interface InMemoryDataStoreout - output stream where the content of the data store is saved.
The method does not close the stream.IOException - in case the save operation failed.public void load(InputStream in) throws IOException
InMemoryDataStoreload in interface InMemoryDataStorein - input stream from which the content of the data store is loaded.
The method does not close the stream.IOException - in case the load operation failed.public void addObserver(DataStoreObserver observer)
ObservableDataStoreobserver
to the set of observers for this observable object
ObservableDataStore.addObserver in interface ObservableDataStoreobserver - an observer to be added.public void deleteObserver(DataStoreObserver observer)
ObservableDataStoreobserver
from the set of observers of this object.
Passing null to this method will have no effect.deleteObserver in interface ObservableDataStoreobserver - the observer to be deleted.public Collection<Serializable> getAll()
Copyright © 2007-2016, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.