Package org.eclipse.rdf4j.sail.memory
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
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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
contentsChanged
Flag indicating whether the contents of this repository have changed.protected static java.lang.String
DATA_FILE_NAME
private java.io.File
dataFile
The file used for data persistence, null if this is a volatile RDF store.private SPARQLServiceResolver
dependentServiceResolver
dependent life cycleprivate Lock
dirLock
The directory lock, null if this is read-only or a volatile RDF store.private EvaluationStrategyFactory
evalStratFactory
private static org.slf4j.Logger
logger
private boolean
persist
private FederatedServiceResolver
serviceResolver
independent life cycleprivate SailStore
store
Factory/cache for MemValue objects.protected static java.lang.String
SYNC_FILE_NAME
private long
syncDelay
The sync delay.private java.io.File
syncFile
The file used for serialising data, null if this is a volatile RDF store.private java.lang.Object
syncSemaphore
Semaphore used to synchronize concurrent access to#syncWithLock()
.private java.util.Timer
syncTimer
The timer used to trigger file synchronization.private java.lang.Object
syncTimerSemaphore
Semaphore used to synchronize concurrent access tosyncTimer
andsyncTimerTask
.private java.util.TimerTask
syncTimerTask
The currently scheduled timer task, if any.-
Fields inherited from class org.eclipse.rdf4j.sail.helpers.AbstractSail
connectionTimeOut, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_ITERATION_SYNC_THRESHOLD, initializationLock
-
-
Constructor Summary
Constructors Constructor Description MemoryStore()
Creates a new MemoryStore.MemoryStore(java.io.File dataDir)
Creates a new persistent MemoryStore.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cancelSyncTask()
protected void
cancelSyncTimer()
protected NotifyingSailConnection
getConnectionInternal()
Returns a store-specific SailConnection object.EvaluationStrategyFactory
getEvaluationStrategyFactory()
FederatedServiceResolver
getFederatedServiceResolver()
Gets theFederatedServiceResolver
used by this client.boolean
getPersist()
(package private) SailStore
getSailStore()
long
getSyncDelay()
Gets the currently configured sync delay.ValueFactory
getValueFactory()
Gets a ValueFactory object that can be used to create IRI-, blank node-, literal- and statement objects.protected void
initializeInternal()
Initializes this repository.boolean
isWritable()
Checks whether this Sail object is writable.void
notifySailChanged(SailChangedEvent event)
Notifies all registered SailChangedListener's of changes to the contents of this Sail.protected void
scheduleSyncTask()
void
setEvaluationStrategyFactory(EvaluationStrategyFactory factory)
Sets theEvaluationStrategy
to use.void
setFederatedServiceResolver(FederatedServiceResolver resolver)
Overrides theFederatedServiceResolver
used by this instance, but the given resolver is not shutDown when this instance is.void
setPersist(boolean persist)
void
setSyncDelay(long syncDelay)
Sets the time (in milliseconds) to wait after a transaction was commited before writing the changed data to file.protected void
shutDownInternal()
Do store-specific operations to ensure proper shutdown of the store.void
sync()
Synchronizes the contents of this repository with the data that is stored on disk.-
Methods inherited from class org.eclipse.rdf4j.sail.helpers.AbstractNotifyingSail
addSailChangedListener, getConnection, removeSailChangedListener
-
Methods inherited from class org.eclipse.rdf4j.sail.helpers.AbstractSail
addSupportedIsolationLevel, connectionClosed, debugEnabled, getDataDir, getDefaultIsolationLevel, getDefaultQueryEvaluationMode, getIterationCacheSyncThreshold, getSupportedIsolationLevels, init, isInitialized, isTrackResultSize, removeSupportedIsolationLevel, setConnectionTimeOut, setDataDir, setDefaultIsolationLevel, setDefaultQueryEvaluationMode, setIterationCacheSyncThreshold, setSupportedIsolationLevels, setSupportedIsolationLevels, setTrackResultSize, shutDown, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.sail.Sail
getCollectionFactory, getDataDir, getDefaultIsolationLevel, getSupportedIsolationLevels, init, setDataDir, shutDown
-
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
DATA_FILE_NAME
protected static final java.lang.String DATA_FILE_NAME
- See Also:
- Constant Field Values
-
SYNC_FILE_NAME
protected static final java.lang.String SYNC_FILE_NAME
- See Also:
- Constant Field Values
-
store
private SailStore store
Factory/cache for MemValue objects.
-
persist
private volatile boolean persist
-
dataFile
private volatile java.io.File dataFile
The file used for data persistence, null if this is a volatile RDF store.
-
syncFile
private volatile java.io.File syncFile
The file used for serialising data, null if this is a volatile RDF store.
-
dirLock
private volatile Lock dirLock
The directory lock, null if this is read-only or a volatile RDF store.
-
contentsChanged
private volatile boolean contentsChanged
Flag indicating whether the contents of this repository have changed.
-
syncDelay
private volatile long syncDelay
The sync delay.- See Also:
setSyncDelay(long)
-
syncSemaphore
private final java.lang.Object syncSemaphore
Semaphore used to synchronize concurrent access to#syncWithLock()
.
-
syncTimer
private volatile java.util.Timer syncTimer
The timer used to trigger file synchronization.
-
syncTimerTask
private volatile java.util.TimerTask syncTimerTask
The currently scheduled timer task, if any.
-
syncTimerSemaphore
private final java.lang.Object syncTimerSemaphore
Semaphore used to synchronize concurrent access tosyncTimer
andsyncTimerTask
.
-
evalStratFactory
private EvaluationStrategyFactory evalStratFactory
-
serviceResolver
private FederatedServiceResolver serviceResolver
independent life cycle
-
dependentServiceResolver
private SPARQLServiceResolver dependentServiceResolver
dependent life cycle
-
-
Constructor Detail
-
MemoryStore
public MemoryStore()
Creates a new MemoryStore.
-
MemoryStore
public MemoryStore(java.io.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)
-
getEvaluationStrategyFactory
public EvaluationStrategyFactory getEvaluationStrategyFactory()
- Returns:
- Returns the
EvaluationStrategy
.
-
setEvaluationStrategyFactory
public void setEvaluationStrategyFactory(EvaluationStrategyFactory factory)
Sets theEvaluationStrategy
to use.
-
getFederatedServiceResolver
public FederatedServiceResolver getFederatedServiceResolver()
Description copied from interface:FederatedServiceResolverClient
Gets theFederatedServiceResolver
used by this client.- Specified by:
getFederatedServiceResolver
in interfaceFederatedServiceResolverClient
- Returns:
- Returns the SERVICE resolver.
-
setFederatedServiceResolver
public void setFederatedServiceResolver(FederatedServiceResolver resolver)
Overrides theFederatedServiceResolver
used by this instance, but the given resolver is not shutDown when this instance is.- Specified by:
setFederatedServiceResolver
in interfaceFederatedServiceResolverClient
- Parameters:
resolver
- The SERVICE resolver to set.
-
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 classAbstractSail
- Throws:
SailException
- when initialization of the store failed.
-
shutDownInternal
protected void shutDownInternal() throws SailException
Description copied from class:AbstractSail
Do store-specific operations to ensure proper shutdown of the store.- Specified by:
shutDownInternal
in 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:
isWritable
in interfaceSail
-
getConnectionInternal
protected NotifyingSailConnection getConnectionInternal() throws SailException
Description copied from class:AbstractSail
Returns a store-specific SailConnection object.- Specified by:
getConnectionInternal
in classAbstractNotifyingSail
- Returns:
- A connection to the store.
- Throws:
SailException
-
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 interfaceSail
- Returns:
- a ValueFactory object for this Sail object.
-
notifySailChanged
public void notifySailChanged(SailChangedEvent event)
Description copied from class:AbstractNotifyingSail
Notifies all registered SailChangedListener's of changes to the contents of this Sail.- Overrides:
notifySailChanged
in classAbstractNotifyingSail
-
scheduleSyncTask
protected void scheduleSyncTask() throws SailException
- Throws:
SailException
-
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
-
getSailStore
SailStore getSailStore()
-
-