org.openrdf.sail.memory
Class MemoryStore

java.lang.Object
  extended by org.openrdf.sail.helpers.SailBase
      extended by org.openrdf.sail.memory.MemoryStore
All Implemented Interfaces:
Sail

public class MemoryStore
extends SailBase

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.

Author:
Arjohn Kampman, jeen

Field Summary
protected static String DATA_FILE_NAME
           
 
Fields inherited from class org.openrdf.sail.helpers.SailBase
connectionTimeOut, DEFAULT_CONNECTION_TIMEOUT, logger
 
Constructor Summary
MemoryStore()
          Creates a new MemoryStore.
MemoryStore(File dataDir)
          Creates a new persistent MemoryStore.
 
Method Summary
protected  Statement addStatement(Resource subj, URI pred, Value obj, Resource context, boolean explicit)
           
protected  void cancelSyncTask()
           
protected  void cancelSyncTimer()
           
protected  void cleanSnapshots()
          Removes statements from old snapshots from the main statement list and resets the snapshot to 1 for the rest of the statements.
protected  void commit()
           
protected
<X extends Exception>
CloseableIteration<MemStatement,X>
createStatementIterator(Class<X> excClass, Resource subj, URI pred, Value obj, boolean explicitOnly, int snapshot, ReadMode readMode, Resource... contexts)
          Creates a StatementIterator that contains the statements matching the specified pattern of subject, predicate, object, context.
protected  SailConnection getConnectionInternal()
          returns a store-specific SailConnection object.
protected  int getCurrentSnapshot()
           
protected  org.openrdf.sail.memory.MemNamespaceStore getNamespaceStore()
           
 boolean getPersist()
           
protected  MemStatementList getStatements()
           
protected  Lock getStatementsReadLock()
           
 long getSyncDelay()
          Gets the currently configured sync delay.
protected  Lock getTransactionLock()
           
 MemValueFactory getValueFactory()
          Gets a ValueFactory object that can be used to create URI-, blank node-, literal- and statement objects.
 void initialize()
          Initializes this repository.
protected  boolean isInitialized()
          Checks whether the Sail has been initialized.
 boolean isWritable()
          Checks whether this Sail object is writable.
protected  boolean removeStatement(MemStatement st, boolean explicit)
           
protected  void rollback()
           
protected  void scheduleSnapshotCleanup()
           
protected  void scheduleSyncTask()
           
 void setDataDir(File dataDir)
           
 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.
protected  int size()
           
protected  void startTransaction()
           
 void sync()
          Synchronizes the contents of this repository with the data that is stored on disk.
 
Methods inherited from class org.openrdf.sail.helpers.SailBase
addSailChangedListener, connectionClosed, getConnection, getDataDir, notifySailChanged, removeSailChangedListener, shutDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_FILE_NAME

protected static final String DATA_FILE_NAME
See Also:
Constant Field Values
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

setDataDir

public void setDataDir(File dataDir)
Specified by:
setDataDir in interface Sail
Overrides:
setDataDir in class SailBase

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)

initialize

public void initialize()
                throws SailException
Initializes this repository. If a persistence file is defined for the store, the contents will be restored.

Throws:
SailException - when initialization of the store failed.

isInitialized

protected final boolean isInitialized()
Checks whether the Sail has been initialized.

Returns:
true if the Sail has been initialized, false otherwise.

shutDownInternal

protected void shutDownInternal()
                         throws SailException
Description copied from class: SailBase
Do store-specific operations to ensure proper shutdown of the store.

Specified by:
shutDownInternal in class SailBase
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.


getConnectionInternal

protected SailConnection getConnectionInternal()
                                        throws SailException
Description copied from class: SailBase
returns a store-specific SailConnection object.

Specified by:
getConnectionInternal in class SailBase
Returns:
a SailConnection
Throws:
SailException

getValueFactory

public MemValueFactory getValueFactory()
Description copied from interface: Sail
Gets a ValueFactory object that can be used to create URI-, blank node-, literal- and statement objects.

Returns:
a ValueFactory object for this Sail object.

getNamespaceStore

protected org.openrdf.sail.memory.MemNamespaceStore getNamespaceStore()

getStatements

protected MemStatementList getStatements()

getCurrentSnapshot

protected int getCurrentSnapshot()

getStatementsReadLock

protected Lock getStatementsReadLock()
                              throws SailException
Throws:
SailException

getTransactionLock

protected Lock getTransactionLock()
                           throws SailException
Throws:
SailException

size

protected int size()

createStatementIterator

protected <X extends Exception> CloseableIteration<MemStatement,X> createStatementIterator(Class<X> excClass,
                                                                                           Resource subj,
                                                                                           URI pred,
                                                                                           Value obj,
                                                                                           boolean explicitOnly,
                                                                                           int snapshot,
                                                                                           ReadMode readMode,
                                                                                           Resource... contexts)
Creates a StatementIterator that contains the statements matching the specified pattern of subject, predicate, object, context. Inferred statements are excluded when explicitOnly is set to true. Statements from the null context are excluded when namedContextsOnly is set to true. The returned StatementIterator will assume the specified read mode.


addStatement

protected Statement addStatement(Resource subj,
                                 URI pred,
                                 Value obj,
                                 Resource context,
                                 boolean explicit)
                          throws SailException
Throws:
SailException

removeStatement

protected boolean removeStatement(MemStatement st,
                                  boolean explicit)
                           throws SailException
Throws:
SailException

startTransaction

protected void startTransaction()
                         throws SailException
Throws:
SailException

commit

protected void commit()
               throws SailException
Throws:
SailException

rollback

protected void rollback()
                 throws SailException
Throws:
SailException

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

cleanSnapshots

protected void cleanSnapshots()
                       throws InterruptedException
Removes statements from old snapshots from the main statement list and resets the snapshot to 1 for the rest of the statements.

Throws:
InterruptedException

scheduleSnapshotCleanup

protected void scheduleSnapshotCleanup()


Copyright © 2001-2008 Aduna. All Rights Reserved.