Class AbstractStorageEngine<SC extends StorageConfiguration>
- java.lang.Object
-
- com.datumbox.framework.common.storage.abstracts.AbstractStorageEngine<SC>
-
- All Implemented Interfaces:
StorageEngine,AutoCloseable
- Direct Known Subclasses:
AbstractFileStorageEngine
public abstract class AbstractStorageEngine<SC extends StorageConfiguration> extends Object implements StorageEngine
The AbstractStorageEngine is the base class for all concrete storage engines. Those classes can be used in a try-with-resources statement block. Moreover this class setups a shutdown hook which ensures that the storage engine will automatically call close() before the JVM is terminated. Finally it contains methods to store complex objects with fields that point to other serialized objects.- Author:
- Vasilis Vryniotis
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.datumbox.framework.common.storage.interfaces.StorageEngine
StorageEngine.MapType, StorageEngine.StorageHint
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.LoggerloggerLogger for all Storage Engines.protected SCstorageConfigurationprotected StringstorageName
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractStorageEngine(String storageName, SC storageConfiguration)Protected Constructor which is responsible for adding the Shutdown hook and storing the storage name and configuration.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidassertConnectionOpen()Ensures the connection is not closed.voidclose()StringgetStorageName()Returns the name of the storage.booleanisClosed()Checks if the storage engine is closed.protected abstract Set<Class>nonSerializableBigMaps()Returns a list of non-serializable bigmap classes which are dependent to the StorageEngine.protected <T extends Serializable>
voidpostDeserializer(T serializableObject)This method is called after the object deserialization.protected <T extends Serializable>
voidpostSerializer(T serializableObject, Map<String,Object> objReferences)This method is called after the object serialization.protected <T extends Serializable>
Map<String,Object>preSerializer(T serializableObject)This method is called before serializing the objects.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.datumbox.framework.common.storage.interfaces.StorageEngine
clear, dropBigMap, existsObject, getBigMap, loadObject, rename, saveObject
-
-
-
-
Field Detail
-
storageName
protected String storageName
-
storageConfiguration
protected final SC extends StorageConfiguration storageConfiguration
-
logger
protected final org.slf4j.Logger logger
Logger for all Storage Engines.
-
-
Method Detail
-
getStorageName
public String getStorageName()
Returns the name of the storage.- Specified by:
getStorageNamein interfaceStorageEngine- Returns:
-
isClosed
public boolean isClosed()
Checks if the storage engine is closed.- Specified by:
isClosedin interfaceStorageEngine- Returns:
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
assertConnectionOpen
protected void assertConnectionOpen()
Ensures the connection is not closed.
-
preSerializer
protected <T extends Serializable> Map<String,Object> preSerializer(T serializableObject)
This method is called before serializing the objects. It extracts all the not-serializable BigMap references of the provided object and stores them in a Map. Then it replaces all the references of the provided object with nulls to avoid their serialization. The main idea is that we temporarily remove from the object any reference that will cause problems during the serialization phase.- Type Parameters:
T-- Parameters:
serializableObject-- Returns:
-
nonSerializableBigMaps
protected abstract Set<Class> nonSerializableBigMaps()
Returns a list of non-serializable bigmap classes which are dependent to the StorageEngine.- Returns:
-
postSerializer
protected <T extends Serializable> void postSerializer(T serializableObject, Map<String,Object> objReferences)
This method is called after the object serialization. It moves all the not-serializable BigMap references from the Map back to the provided object. The main idea is that once the serialization is completed, we are allowed to restore back all the references which were removed by the preSerializer.- Type Parameters:
T-- Parameters:
serializableObject-objReferences-
-
postDeserializer
protected <T extends Serializable> void postDeserializer(T serializableObject)
This method is called after the object deserialization. It initializes all BigMaps of the serializable object which have a null value. The main idea is that once an object is deserialized it will contain nulls in all the BigMap fields which were not serialized. For all of those fields we call their initialization methods.- Type Parameters:
T-- Parameters:
serializableObject-
-
-