Class AbstractStorageEngine<SC extends StorageConfiguration>

  • 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
    • Field Detail

      • storageName

        protected String storageName
      • logger

        protected final org.slf4j.Logger logger
        Logger for all Storage Engines.
    • Constructor Detail

      • AbstractStorageEngine

        protected AbstractStorageEngine​(String storageName,
                                        SC storageConfiguration)
        Protected Constructor which is responsible for adding the Shutdown hook and storing the storage name and configuration.
        Parameters:
        storageName -
        storageConfiguration -
    • Method Detail

      • isClosed

        public boolean isClosed()
        Checks if the storage engine is closed.
        Specified by:
        isClosed in interface StorageEngine
        Returns:
      • 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 -