Interface StorageConnection
- All Superinterfaces:
ObjectSwizzling
,PersistenceStoring
,Persister
- All Known Subinterfaces:
EmbeddedStorageManager
,StorageManager
- All Known Implementing Classes:
EmbeddedStorageManager.Default
,StorageConnection.Default
public interface StorageConnection extends Persister
PersistenceManager
instance, potentially exclusively created).
Note that this is a rather "internal" type that users usually do not have to use or care about.
Since StorageManager
implements this interface, is is normally sufficient to use just that.
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
StorageConnection.Default
-
Method Summary
Modifier and Type Method Description default Storer
createEagerStorer()
Creates a newStorer
instance with eager storing behavior.default Storer
createLazyStorer()
Creates a newStorer
instance with lazy storing behavior.StorageRawFileStatistics
createStorageStatistics()
Creates aStorageRawFileStatistics
instance, (obviously) containing raw file statistics about every channel in the storage.default Storer
createStorer()
Creates a newStorer
instance with default storing behavior.default void
exportChannels(StorageLiveFileProvider fileProvider)
Alias forthis.exportChannels(fileHandler, true);
.void
exportChannels(StorageLiveFileProvider fileProvider, boolean performGarbageCollection)
Exports the data of all channels in the storage by using the passedStorageLiveFileProvider
instance.
This is basically a simple file copy applied to all files in the storage, however with the guaranteed safety of no other task / access to the storage's files intervening with the ongoing process.default StorageEntityTypeExportStatistics
exportTypes(StorageEntityTypeExportFileProvider exportFileProvider)
Alias forthis.exportTypes(exportFileProvider, null);
, meaning all types are exported.StorageEntityTypeExportStatistics
exportTypes(StorageEntityTypeExportFileProvider exportFileProvider, Predicate<? super StorageEntityTypeHandler> isExportType)
Exports the entity data of all selected types of all channels into one file per type.
The data will be in the native binary format used internally by the storage.default Object
getObject(long objectId)
Retrieves the instance associated with the passed objectId.void
importFiles(XGettingEnum<AFile> importFiles)
Imports all files specified by the passed Enum (ordered set) ofAFile
in order.
The files are assumed to be in the native binary format used internally by the storage.
All entities contained in the specified files will be imported.default boolean
issueCacheCheck(long nanoTimeBudget)
Issues a storage cache check to be executed, limited to the time budget in nanoseconds specified by the passednanoTimeBudget
.
When the time budget is used up, the checking logic will keep the current progress and continue there at the next opportunity.boolean
issueCacheCheck(long nanoTimeBudget, StorageEntityCacheEvaluator entityEvaluator)
Same asissueCacheCheck(long)
, but with using the passedStorageEntityCacheEvaluator
logic instead of the configured one.boolean
issueFileCheck(long nanoTimeBudget)
Issues a storage file check to be executed, limited to the time budget in nanoseconds specified by the passednanoTimeBudget
.
When the time budget is used up, the checking logic will keep the current progress and continue there at the next opportunity.default void
issueFullBackup(ADirectory targetDirectory)
Issues a full backup of the whole storage to be executed.void
issueFullBackup(StorageLiveFileProvider targetFileProvider, PersistenceTypeDictionaryExporter typeDictionaryExporter)
Issues a full backup of the whole storage to be executed.default void
issueFullCacheCheck()
Issues a full storage cache check to be executed.default void
issueFullCacheCheck(StorageEntityCacheEvaluator entityEvaluator)
Same asissueFullCacheCheck()
, but with using the passedStorageEntityCacheEvaluator
logic instead of the configured one.default void
issueFullFileCheck()
Issues a full storage file check to be executed.default void
issueFullGarbageCollection()
Issues a full garbage collection to be executed.boolean
issueGarbageCollection(long nanoTimeBudget)
Issues garbage collection to be executed, limited to the time budget in nanoseconds specified by the passednanoTimeBudget
.
When the time budget is used up, the garbage collector will keep the current progress and continue there at the next opportunity.static StorageConnection
New(PersistenceManager<Binary> persistenceManager, StorageRequestAcceptor connectionRequestAcceptor)
PersistenceManager<Binary>
persistenceManager()
default long
store(Object instance)
Stores the passed instance in any case and all referenced instances of persistable references recursively, but stores referenced instances only if they are newly encountered (e.g.default void
storeAll(Iterable<?> instances)
Convenience method toPersistenceStoring.store(Object)
all instances of anIterable
type, usually a collection.
The passed instance itself is NOT stored.
Note that this method does not return an array of objectIds, since the amount of instances supplied by the passedIterable
cannot be known until after all instances have been stored and the memory and performance overhead to collect them dynamically would not be worth it in most cases since the returned array is hardly ever needed.default long[]
storeAll(Object... instances)
Convenience method toPersistenceStoring.store(Object)
multiple instances.
-
Method Details
-
issueFullGarbageCollection
default void issueFullGarbageCollection()Issues a full garbage collection to be executed. Depending on the size of the database, the available cache, used hardware, etc., this can take any amount of time.Garbage collection marks all persisted objects/records that are reachable from the root (mark phase) and once that is completed, all non-marked records are determined to be effectively unreachable and are thus deleted. This common mechanism in graph-organised data completely removes the need for any explicit deleting.
Note that the garbage collection on the storage level has nothing to do with the JVM's Garbage Collector on the heap level. While the technical principle is the same, both GCs are separate from each other and do not have anything to do with each other.
- See Also:
issueGarbageCollection(long)
-
issueGarbageCollection
boolean issueGarbageCollection(long nanoTimeBudget)Issues garbage collection to be executed, limited to the time budget in nanoseconds specified by the passednanoTimeBudget
.
When the time budget is used up, the garbage collector will keep the current progress and continue there at the next opportunity. The same progress marker is used by the implicit housekeeping, so both mechanisms will continue on the same progress.
If no store has occured since the last completed garbage sweep, this method will have no effect and return immediately.- Parameters:
nanoTimeBudget
- the time budget in nanoseconds to be used to perform garbage collection.- Returns:
- whether the returned call has completed garbage collection.
- See Also:
issueFullGarbageCollection()
-
issueFullFileCheck
default void issueFullFileCheck()Issues a full storage file check to be executed. Depending on the size of the database, the available cache, used hardware, etc., this can take any amount of time.File checking evaluates every storage data file about being either too small, too big or having too many logical "gaps" in it (created by storing newer versions of an object or by garbage collection). If one of those checks applies, the remaining live data in the file is moved to the current head file and once that is done, the source file (now consisting of 100% logical "gaps", making it effectively superfluous) is then deleted.
The exact logic is defined by
StorageConfiguration.dataFileEvaluator()
- See Also:
issueFileCheck(long)
-
issueFileCheck
boolean issueFileCheck(long nanoTimeBudget)Issues a storage file check to be executed, limited to the time budget in nanoseconds specified by the passednanoTimeBudget
.
When the time budget is used up, the checking logic will keep the current progress and continue there at the next opportunity. The same progress marker is used by the implicit housekeeping, so both mechanisms will continue on the same progress.
If no store has occured since the last completed check, this method will have no effect and return immediately.- Parameters:
nanoTimeBudget
- the time budget in nanoseconds to be used to perform file checking.- Returns:
- whether the returned call has completed file checking.
-
issueFullCacheCheck
default void issueFullCacheCheck()Issues a full storage cache check to be executed. Depending on the size of the database, the available cache, used hardware, etc., this can take any amount of time.Cache checking evaluates every cache entity data about being worth to be kept in cache according to the configured
StorageEntityCacheEvaluator
logic. If deemed unworthy, its data will be cleared from the cache and has to be loaded from the persistent form on the next reading access.
The check will run until the used cache size is 0 or every entity is checked at least once. -
issueFullCacheCheck
Same asissueFullCacheCheck()
, but with using the passedStorageEntityCacheEvaluator
logic instead of the configured one.- Parameters:
entityEvaluator
- the entity cache evaluation logic to be used for the call.- See Also:
issueFullCacheCheck()
,issueCacheCheck(long)
,issueCacheCheck(long,StorageEntityCacheEvaluator)
-
issueCacheCheck
default boolean issueCacheCheck(long nanoTimeBudget)Issues a storage cache check to be executed, limited to the time budget in nanoseconds specified by the passednanoTimeBudget
.
When the time budget is used up, the checking logic will keep the current progress and continue there at the next opportunity. The same progress marker is used by the implicit housekeeping, so both mechanisms will continue on the same progress.
If the used cache size is 0, this method will have no effect and return immediately.- Parameters:
nanoTimeBudget
- the time budget in nanoseconds to be used to perform cache checking.- Returns:
- whether the used cache size is 0 or became 0 via the performed check.
- See Also:
issueFullCacheCheck()
,issueFullCacheCheck(StorageEntityCacheEvaluator)
,issueCacheCheck(long,StorageEntityCacheEvaluator)
-
issueCacheCheck
Same asissueCacheCheck(long)
, but with using the passedStorageEntityCacheEvaluator
logic instead of the configured one.- Parameters:
entityEvaluator
- the entity cache evaluation logic to be used for the call.- See Also:
issueFullCacheCheck()
,issueFullCacheCheck(StorageEntityCacheEvaluator)
,issueCacheCheck(long)
-
issueFullBackup
Issues a full backup of the whole storage to be executed. Keep in mind that this could result in a very long running operation, depending on the storage size.
Although the full backup may be a valid solution in some circumstances, the incremental backup should be preferred, since it is by far more efficient.- Parameters:
targetDirectory
- the directory to write the backup data into- Since:
- 04.01.00
-
issueFullBackup
void issueFullBackup(StorageLiveFileProvider targetFileProvider, PersistenceTypeDictionaryExporter typeDictionaryExporter)Issues a full backup of the whole storage to be executed. Keep in mind that this could result in a very long running operation, depending on the storage size.
Although the full backup may be a valid solution in some circumstances, the incremental backup should be preferred, since it is by far more efficient.- Parameters:
targetFileProvider
- file provider for backup filestypeDictionaryExporter
-- Since:
- 04.01.00
-
createStorageStatistics
StorageRawFileStatistics createStorageStatistics()Creates aStorageRawFileStatistics
instance, (obviously) containing raw file statistics about every channel in the storage.- Returns:
- a
StorageRawFileStatistics
instance based on the current state.
-
exportChannels
Exports the data of all channels in the storage by using the passedStorageLiveFileProvider
instance.
This is basically a simple file copy applied to all files in the storage, however with the guaranteed safety of no other task / access to the storage's files intervening with the ongoing process. This is useful to safely create a complete copy of the storage, e.g. a full backup.- Parameters:
fileProvider
- theStorageLiveFileProvider
logic to be used for the export.performGarbageCollection
- whether aissueFullGarbageCollection()
shall be issued before performing the export.
-
exportChannels
Alias forthis.exportChannels(fileHandler, true);
.- Parameters:
fileProvider
- theStorageLiveFileProvider
logic to be used for the export.- See Also:
exportChannels(StorageLiveFileProvider,boolean)
-
exportTypes
StorageEntityTypeExportStatistics exportTypes(StorageEntityTypeExportFileProvider exportFileProvider, Predicate<? super StorageEntityTypeHandler> isExportType)Exports the entity data of all selected types of all channels into one file per type.
The data will be in the native binary format used internally by the storage. Converters can be used to transform the data into a different, for example human readable, form like CSV.This is useful to extract the data contained in the storage in a structured way, for example to migrate it into another storage system or to analyze it, like converting it into human readable form.
- Parameters:
exportFileProvider
- theStorageEntityTypeExportFileProvider
logic to be used.isExportType
- aPredicate
selecting which type's entity data to be exported.- Returns:
- a
StorageEntityTypeExportStatistics
information instance about the completed export. - See Also:
exportTypes(StorageEntityTypeExportFileProvider)
-
exportTypes
default StorageEntityTypeExportStatistics exportTypes(StorageEntityTypeExportFileProvider exportFileProvider)Alias forthis.exportTypes(exportFileProvider, null);
, meaning all types are exported.- Parameters:
exportFileProvider
- theStorageEntityTypeExportFileProvider
logic to be used.- Returns:
- a
StorageEntityTypeExportStatistics
information instance about the completed export. - See Also:
exportTypes(StorageEntityTypeExportFileProvider,Predicate)
-
importFiles
Imports all files specified by the passed Enum (ordered set) ofAFile
in order.
The files are assumed to be in the native binary format used internally by the storage.
All entities contained in the specified files will be imported. If they already exist in the storage (identified by their ObjectId), their current data will be replaced by the imported data.
Note that importing data that is not reachable from any root entity will have no effect and will eventually be deleted by the garbage collector.- Parameters:
importFiles
- the files whose native binary content shall be imported.
-
persistenceManager
PersistenceManager<Binary> persistenceManager()- Returns:
- the
PersistenceManager
used by thisStorageConnection
.
-
store
Stores the passed instance in any case and all referenced instances of persistable references recursively, but stores referenced instances only if they are newly encountered (e.g. don't have an id associated with them in the object registry, yet and are therefore required to be handled). This is useful for the common case of just storing an updated instance and potentially newly created instances along with it while skipping all existing (and normally unchanged) referenced instances.- Specified by:
store
in interfacePersistenceStoring
- Specified by:
store
in interfacePersister
- Parameters:
instance
- the root instance of the subgraph of required instances to be stored.- Returns:
- the object id representing the passed instance.
-
storeAll
Convenience method toPersistenceStoring.store(Object)
multiple instances. The passed array (maybe implicitely created by the compiler) itself is NOT stored.- Specified by:
storeAll
in interfacePersistenceStoring
- Specified by:
storeAll
in interfacePersister
- Parameters:
instances
- multiple root instances of the subgraphs of required instances to be stored.- Returns:
- an array containing the object ids representing the passed instances.
-
storeAll
Convenience method toPersistenceStoring.store(Object)
all instances of anIterable
type, usually a collection.
The passed instance itself is NOT stored.
Note that this method does not return an array of objectIds, since the amount of instances supplied by the passedIterable
cannot be known until after all instances have been stored and the memory and performance overhead to collect them dynamically would not be worth it in most cases since the returned array is hardly ever needed. If it should be needed, the desired behavior can be easily achieved with a tiny custom-made utility method.- Specified by:
storeAll
in interfacePersistenceStoring
- Specified by:
storeAll
in interfacePersister
- Parameters:
instances
- multiple root instances of the subgraphs of required instances to be stored.
-
createLazyStorer
Creates a newStorer
instance with lazy storing behavior. This means an entity instance encountered while traversing the entity graph is only stored if it is not yet known to the persistence context, i.e. does not have an objectId associated with it in the persistence context'sPersistenceObjectRegistry
.- Specified by:
createLazyStorer
in interfacePersister
- Returns:
- the newly created
Storer
instance.
-
createStorer
Creates a newStorer
instance with default storing behavior. The default is lazy storing. SeePersister.createLazyStorer()
.- Specified by:
createStorer
in interfacePersister
- Returns:
- the newly created
Storer
instance.
-
createEagerStorer
Creates a newStorer
instance with eager storing behavior. This means an entity instance encountered while traversing the entity graph is always stored, regardless of if it is already known to the persistence context or not, i.e. does have an objectId associated with it in the persistence context'sPersistenceObjectRegistry
.Note: Eager storing is a dangerous behavior since - depending on the entity graph's referential layout - it can cause the whole entity graph present in the heap to be stored. Therefore, it is stronly advised to instead use lazy storing logic (see
Persister.createLazyStorer()
) or some other kind of limiting storing logic.- Specified by:
createEagerStorer
in interfacePersister
- Returns:
- the newly created
Storer
instance.
-
getObject
Retrieves the instance associated with the passed objectId. Retrieving means guaranteeing that the associated instance is returned. If it does not yet exist, it will be created from persisted data, including all non-lazily referenced objects it is connected to.- Specified by:
getObject
in interfaceObjectSwizzling
- Specified by:
getObject
in interfacePersister
- Parameters:
objectId
- the objectId defining which instance to return.- Returns:
- the instance associated with the passed objectId.
-
New
static StorageConnection New(PersistenceManager<Binary> persistenceManager, StorageRequestAcceptor connectionRequestAcceptor)
-