Class MemoryStore

  • All Implemented Interfaces:
    FederatedServiceResolverClient, NotifyingSail, Sail

    public class MemoryStore
    extends AbstractNotifyingSail
    implements FederatedServiceResolverClient
    An implementation of the Sail interface that stores its data in main memory and that can use a file for persistent storage. This Sail implementation supports single, isolated transactions. This means that changes to the data are not visible until a transaction is committed and that concurrent transactions are not possible. When another transaction is active, calls to startTransaction() will block until the active transaction is committed or rolled back.

    The MemoryStore is designed for datasets with fewer than 100,000 triples. The MemoryStore uses hash tables, and when these hash tables fill up it copies the values to larger hash tables. This can cause strain on the garbage collector due to lots of memory being allocated and freed.

    Author:
    Arjohn Kampman, jeen
    • Constructor Detail

      • MemoryStore

        public MemoryStore()
        Creates a new MemoryStore.
      • MemoryStore

        public MemoryStore​(File dataDir)
        Creates a new persistent MemoryStore. If the specified data directory contains an existing store, its contents will be restored upon initialization.
        Parameters:
        dataDir - the data directory to be used for persistence.
    • Method Detail

      • setPersist

        public void setPersist​(boolean persist)
      • getPersist

        public boolean getPersist()
      • setSyncDelay

        public void setSyncDelay​(long syncDelay)
        Sets the time (in milliseconds) to wait after a transaction was commited before writing the changed data to file. Setting this variable to 0 will force a file sync immediately after each commit. A negative value will deactivate file synchronization until the Sail is shut down. A positive value will postpone the synchronization for at least that amount of milliseconds. If in the meantime a new transaction is started, the file synchronization will be rescheduled to wait for another syncDelay ms. This way, bursts of transaction events can be combined in one file sync.

        The default value for this parameter is 0 (immediate synchronization).

        Parameters:
        syncDelay - The sync delay in milliseconds.
      • getSyncDelay

        public long getSyncDelay()
        Gets the currently configured sync delay.
        Returns:
        syncDelay The sync delay in milliseconds.
        See Also:
        setSyncDelay(long)
      • getFederatedServiceResolver

        public FederatedServiceResolver getFederatedServiceResolver()
        Returns:
        Returns the SERVICE resolver.
      • initializeInternal

        protected void initializeInternal()
                                   throws SailException
        Initializes this repository. If a persistence file is defined for the store, the contents will be restored.
        Overrides:
        initializeInternal in class AbstractSail
        Throws:
        SailException - when initialization of the store failed.
      • isWritable

        public boolean isWritable()
        Checks whether this Sail object is writable. A MemoryStore is not writable if a read-only data file is used.
        Specified by:
        isWritable in interface Sail
      • getValueFactory

        public ValueFactory getValueFactory()
        Description copied from interface: Sail
        Gets a ValueFactory object that can be used to create IRI-, blank node-, literal- and statement objects.
        Specified by:
        getValueFactory in interface Sail
        Returns:
        a ValueFactory object for this Sail object.
      • cancelSyncTask

        protected void cancelSyncTask()
      • cancelSyncTimer

        protected void cancelSyncTimer()
      • sync

        public void sync()
                  throws SailException
        Synchronizes the contents of this repository with the data that is stored on disk. Data will only be written when the contents of the repository and data in the file are out of sync.
        Throws:
        SailException