public class BasicStorageImpl extends AbstractModule<BasicStorageConfig> implements IRecordStorageModule<BasicStorageConfig>
PERST implementation of IBasicStorage
for storing simple data records.
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoCommit |
protected org.garret.perst.Storage |
db |
protected org.garret.perst.Persistent |
dbRoot |
config, eventHandler, lastError, logger, securityHandler, startRequested, state, stateLock, statusMsg
Constructor and Description |
---|
BasicStorageImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addRecordStore(String name,
DataComponent recordStructure,
DataEncoding recommendedEncoding)
Adds a data store for a new record type in this storage
|
void |
backup(OutputStream os)
Backups storage to specified output stream
|
void |
cleanup()
Cleans up all ressources used by the module when deleted
All persistent resources created by the module should be cleaned
when this is called
|
void |
commit()
Commits all changes generated by transactional methods since the last commit event
|
protected org.garret.perst.Persistent |
createRoot(org.garret.perst.Storage db) |
DataBlock |
getDataBlock(DataKey key)
Retrieves raw data block with the specified key
|
Iterator<DataBlock> |
getDataBlockIterator(IDataFilter filter)
Gets iterator of raw data blocks matching the specified filter
|
AbstractProcess |
getDataSourceDescriptionAtTime(double time)
Retrieves data source description valid at specified time
|
List<AbstractProcess> |
getDataSourceDescriptionHistory(double startTime,
double endTime)
Retrieves history of data source description for the given time period
|
AbstractProcess |
getLatestDataSourceDescription()
Retrieves latest data source description (i.e.
|
int |
getNumMatchingRecords(IDataFilter filter,
long maxCount)
Computes the (potentially approximate) number of records matching the
given filter.
Since the returned value can be approximate and the number of matching records can change before or even during the actual call to IBasicStorage.getRecordIterator(IDataFilter) , the exact number of records can
only be obtained by counting the records returned by the iterator next()
function. |
int |
getNumRecords(String recordType)
Helper method to retrieve the total number of method for the specified
record type
|
Iterator<? extends IDataRecord> |
getRecordIterator(IDataFilter filter)
Gets iterator of records matching the specified filter
|
Iterator<double[]> |
getRecordsTimeClusters(String recordType)
Retrieves time boundaries of data clusters
(i.e.
|
double[] |
getRecordsTimeRange(String recordType)
Retrieves time range spanned by all records of the specified type
|
Map<String,? extends IRecordStoreInfo> |
getRecordStores()
Gets the list of available record types in this storage
|
void |
removeDataSourceDescription(double time)
Removes data source description valid at specified time
|
void |
removeDataSourceDescriptionHistory(double startTime,
double endTime)
Removes data source descriptions whose validity periods lie within the given time period
|
void |
removeRecord(DataKey key)
Removes record with the specified key
|
int |
removeRecords(IDataFilter filter)
Removes all records matching the filter
|
void |
restore(InputStream is)
Restores storage from backup obtained from specified input stream
|
void |
rollback()
Cancels all changes generated by transactional methods since the last commit event
|
void |
start()
Starts the module synchronously with the current configuration.
Implementations of this method must block until the module is successfully started or send an exception. Module lifecycle events may not be generated when calling this method directly. init() should always be called before start(). |
void |
stop()
Stops the module.
All temporary resources created by the module should be cleaned when this is called (ex: memory, files, connections, etc.) Implementations of this method must block until the module is successfully stopped or send an exception. Module lifecycle events may not be generated when calling this method directly. stop() can be called right after init() even if start() hasn't been called. |
void |
storeDataSourceDescription(AbstractProcess process)
Stores a new data source description into storage.
|
void |
storeRecord(DataKey key,
DataBlock data)
Persists data block in storage
|
void |
sync(IStorageModule<?> storage)
Synchronizes storage with another storage of the same type (potentially remote)
|
void |
updateDataSourceDescription(AbstractProcess process)
Update the data source description in storage.
|
void |
updateRecord(DataKey key,
DataBlock data)
Updates record with specified key with new data
|
canInit, canStart, canStop, clearError, clearStatus, getConfiguration, getCurrentError, getCurrentState, getLocalID, getLogger, getName, getStatusMessage, init, init, isInitialized, isStarted, loadState, notifyConnectionStatus, registerListener, reportError, reportError, reportStatus, requestInit, requestStart, requestStop, saveState, setConfiguration, setState, toString, unregisterListener, updateConfig, waitForState
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getConfiguration, getCurrentError, getCurrentState, getLocalID, getName, getStatusMessage, init, init, isInitialized, isStarted, loadState, registerListener, requestInit, requestStart, requestStop, saveState, setConfiguration, unregisterListener, updateConfig, waitForState
protected org.garret.perst.Storage db
protected org.garret.perst.Persistent dbRoot
protected boolean autoCommit
public void start() throws StorageException
IModule
start
in interface IModule<BasicStorageConfig>
StorageException
protected org.garret.perst.Persistent createRoot(org.garret.perst.Storage db)
public void stop() throws SensorHubException
IModule
stop
in interface IModule<BasicStorageConfig>
SensorHubException
public void cleanup() throws SensorHubException
IModule
cleanup
in interface IModule<BasicStorageConfig>
SensorHubException
public void backup(OutputStream os) throws IOException
IStorageModule
backup
in interface IStorageModule<BasicStorageConfig>
IOException
public void restore(InputStream is) throws IOException
IStorageModule
restore
in interface IStorageModule<BasicStorageConfig>
IOException
public void commit()
IStorageModule
commit
in interface IStorageModule<BasicStorageConfig>
public void rollback()
IStorageModule
rollback
in interface IStorageModule<BasicStorageConfig>
public void sync(IStorageModule<?> storage)
IStorageModule
sync
in interface IStorageModule<BasicStorageConfig>
public AbstractProcess getLatestDataSourceDescription()
IBasicStorage
getLatestDataSourceDescription
in interface IBasicStorage
public List<AbstractProcess> getDataSourceDescriptionHistory(double startTime, double endTime)
IBasicStorage
getDataSourceDescriptionHistory
in interface IBasicStorage
startTime
- lower bound of the time periodendTime
- upper bound of the time periodpublic AbstractProcess getDataSourceDescriptionAtTime(double time)
IBasicStorage
getDataSourceDescriptionAtTime
in interface IBasicStorage
public void storeDataSourceDescription(AbstractProcess process)
IBasicStorage
storeDataSourceDescription
in interface IBasicStorage
process
- SensorML process description to storepublic void updateDataSourceDescription(AbstractProcess process)
IBasicStorage
updateDataSourceDescription
in interface IBasicStorage
process
- SensorML process description to updatepublic void removeDataSourceDescription(double time)
IBasicStorage
removeDataSourceDescription
in interface IBasicStorage
time
- any time falling within the validity period of the description version to removepublic void removeDataSourceDescriptionHistory(double startTime, double endTime)
IBasicStorage
removeDataSourceDescriptionHistory
in interface IBasicStorage
startTime
- lower bound of the time periodendTime
- upper bound of the time periodpublic void addRecordStore(String name, DataComponent recordStructure, DataEncoding recommendedEncoding)
IBasicStorage
addRecordStore
in interface IBasicStorage
name
- name of record type (should match output name of the data source)recordStructure
- SWE data component describing the record structurerecommendedEncoding
- recommended encoding for this record typepublic Map<String,? extends IRecordStoreInfo> getRecordStores()
IBasicStorage
getRecordStores
in interface IBasicStorage
public int getNumRecords(String recordType)
IBasicStorage
getNumRecords
in interface IBasicStorage
recordType
- name of record typepublic double[] getRecordsTimeRange(String recordType)
IBasicStorage
getRecordsTimeRange
in interface IBasicStorage
recordType
- name of record typepublic Iterator<double[]> getRecordsTimeClusters(String recordType)
IBasicStorage
getRecordsTimeClusters
in interface IBasicStorage
recordType
- name of record typepublic DataBlock getDataBlock(DataKey key)
IBasicStorage
getDataBlock
in interface IBasicStorage
key
- Record keypublic Iterator<DataBlock> getDataBlockIterator(IDataFilter filter)
IBasicStorage
getDataBlockIterator
in interface IBasicStorage
filter
- filtering parameterspublic Iterator<? extends IDataRecord> getRecordIterator(IDataFilter filter)
IBasicStorage
getRecordIterator
in interface IBasicStorage
filter
- filtering parameterspublic int getNumMatchingRecords(IDataFilter filter, long maxCount)
IBasicStorage
IBasicStorage.getRecordIterator(IDataFilter)
, the exact number of records can
only be obtained by counting the records returned by the iterator next()
function.getNumMatchingRecords
in interface IBasicStorage
filter
- filtering parametersmaxCount
- counting will stop once this threshold is reachedpublic void storeRecord(DataKey key, DataBlock data)
IBasicStorage
storeRecord
in interface IBasicStorage
key
- key object to associate to recorddata
- actual record datapublic void updateRecord(DataKey key, DataBlock data)
IBasicStorage
updateRecord
in interface IBasicStorage
key
- key of record to updatedata
- new data block to assign to the recordpublic void removeRecord(DataKey key)
IBasicStorage
removeRecord
in interface IBasicStorage
key
- record keypublic int removeRecords(IDataFilter filter)
IBasicStorage
removeRecords
in interface IBasicStorage
filter
- filtering parametersCopyright © 2016 Sensia Software LLC. All rights reserved.