Class MemoryStore
java.lang.Object
org.eclipse.rdf4j.sail.helpers.AbstractSail
org.eclipse.rdf4j.sail.helpers.AbstractNotifyingSail
org.eclipse.rdf4j.sail.memory.MemoryStore
- All Implemented Interfaces:
FederatedServiceResolverClient, NotifyingSail, Sail
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
-
Field Summary
FieldsFields inherited from class AbstractSail
connectionTimeOut, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_ITERATION_SYNC_THRESHOLD, initializationLockModifier and TypeFieldDescriptionprotected longConnection timeout on shutdown (in ms).protected static final longDefault connection timeout on shutdown: 20,000 milliseconds (20 seconds).protected static final longdefault value for the Iteration item sync thresholdprotected final ReentrantReadWriteLockLock used to synchronize the initialization state of a sail. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new MemoryStore.MemoryStore(File dataDir) Creates a new persistent MemoryStore. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidprotected NotifyingSailConnectionReturns a store-specific SailConnection object.Gets theFederatedServiceResolverused by this client.booleanlongGets the currently configured sync delay.Gets a ValueFactory object that can be used to create IRI-, blank node-, literal- and statement objects.protected voidInitializes this repository.booleanChecks whether this Sail object is writable.voidNotifies all registered SailChangedListener's of changes to the contents of this Sail.protected voidvoidSets theEvaluationStrategyto use.voidOverrides theFederatedServiceResolverused by this instance, but the given resolver is not shutDown when this instance is.voidsetPersist(boolean persist) voidsetSyncDelay(long syncDelay) Sets the time (in milliseconds) to wait after a transaction was commited before writing the changed data to file.protected voidDo store-specific operations to ensure proper shutdown of the store.voidsync()Synchronizes the contents of this repository with the data that is stored on disk.Methods inherited from class AbstractNotifyingSail
addSailChangedListener, getConnection, removeSailChangedListenerModifier and TypeMethodDescriptionvoidaddSailChangedListener(SailChangedListener listener) Adds the specified SailChangedListener to receive events when the data in this Sail object changes.Opens a connection on the Sail which can be used to query and update data.voidremoveSailChangedListener(SailChangedListener listener) Removes the specified SailChangedListener so that it no longer receives events from this Sail object.Methods inherited from class AbstractSail
addSupportedIsolationLevel, connectionClosed, debugEnabled, getDataDir, getDefaultIsolationLevel, getDefaultQueryEvaluationMode, getIterationCacheSyncThreshold, getSupportedIsolationLevels, init, isInitialized, isTrackResultSize, removeSupportedIsolationLevel, setConnectionTimeOut, setDataDir, setDefaultIsolationLevel, setDefaultQueryEvaluationMode, setIterationCacheSyncThreshold, setSupportedIsolationLevels, setSupportedIsolationLevels, setTrackResultSize, shutDown, toStringModifier and TypeMethodDescriptionprotected voidAppends the providedIsolationLevelsto the SAIL's list of supported isolation levels.protected voidconnectionClosed(SailConnection connection) Signals to the store that the supplied connection has been closed; called byAbstractSailConnection.close().protected static booleanGets the Sail's data directory.Retrieves the defaultIsolationLevellevel on which transactions in this Sail operate.longRetrieves the currently configured threshold for syncing query evaluation iteration caches to disk.Retrieve theIsolationLevels supported by this SAIL, ordered by increasing complexity.voidinit()Initializes the Sail.protected booleanChecks whether the Sail has been initialized.booleanReturns the status of the result size tracking for the query plan.protected voidRemoves all occurrences of the providedIsolationLevelsin the list of supported Isolation levels.voidsetConnectionTimeOut(long connectionTimeOut) Set connection timeout on shutdown (in ms).voidsetDataDir(File dataDir) Sets the data directory for the Sail.voidsetDefaultIsolationLevel(IsolationLevel defaultIsolationLevel) Sets the defaultIsolationLevelon which transactions in this Sail operate.voidsetDefaultQueryEvaluationMode(QueryEvaluationMode defaultQueryEvaluationMode) voidsetIterationCacheSyncThreshold(long iterationCacheSyncThreshold) Set the threshold for syncing query evaluation iteration caches to disk.protected voidsetSupportedIsolationLevels(List<IsolationLevel> supportedIsolationLevels) Sets the list of supportedIsolationLevelss for this SAIL.protected voidsetSupportedIsolationLevels(IsolationLevel... supportedIsolationLevels) Sets the list of supportedIsolationLevelss for this SAIL.voidsetTrackResultSize(boolean trackResultSize) Enable or disable results size tracking for the query plan.voidshutDown()Shuts down the Sail, giving it the opportunity to synchronize any stale data.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Sail
getCollectionFactoryModifier and TypeMethodDescriptiondefault Supplier<CollectionFactory> Gets a CollectionFactory that may be optimized for this store and may or may not use disk or other resources.
-
Field Details
-
DATA_FILE_NAME
- See Also:
-
SYNC_FILE_NAME
- See Also:
-
-
Constructor Details
-
MemoryStore
public MemoryStore()Creates a new MemoryStore. -
MemoryStore
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 Details
-
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:
-
getEvaluationStrategyFactory
- Returns:
- Returns the
EvaluationStrategy.
-
setEvaluationStrategyFactory
Sets theEvaluationStrategyto use. -
getFederatedServiceResolver
Description copied from interface:FederatedServiceResolverClientGets theFederatedServiceResolverused by this client.- Specified by:
getFederatedServiceResolverin interfaceFederatedServiceResolverClient- Returns:
- Returns the SERVICE resolver.
-
setFederatedServiceResolver
Overrides theFederatedServiceResolverused by this instance, but the given resolver is not shutDown when this instance is.- Specified by:
setFederatedServiceResolverin interfaceFederatedServiceResolverClient- Parameters:
resolver- The SERVICE resolver to set.
-
initializeInternal
Initializes this repository. If a persistence file is defined for the store, the contents will be restored.- Overrides:
initializeInternalin classAbstractSail- Throws:
SailException- when initialization of the store failed.
-
shutDownInternal
Description copied from class:AbstractSailDo store-specific operations to ensure proper shutdown of the store.- Specified by:
shutDownInternalin classAbstractSail- Throws:
SailException
-
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:
isWritablein interfaceSail
-
getConnectionInternal
Description copied from class:AbstractSailReturns a store-specific SailConnection object.- Specified by:
getConnectionInternalin classAbstractNotifyingSail- Returns:
- A connection to the store.
- Throws:
SailException
-
getValueFactory
Description copied from interface:SailGets a ValueFactory object that can be used to create IRI-, blank node-, literal- and statement objects.- Specified by:
getValueFactoryin interfaceSail- Returns:
- a ValueFactory object for this Sail object.
-
notifySailChanged
Description copied from class:AbstractNotifyingSailNotifies all registered SailChangedListener's of changes to the contents of this Sail.- Overrides:
notifySailChangedin classAbstractNotifyingSail
-
scheduleSyncTask
- Throws:
SailException
-
cancelSyncTask
protected void cancelSyncTask() -
cancelSyncTimer
protected void cancelSyncTimer() -
sync
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
-