org.trippi.impl.base
Class ConcurrentTriplestoreWriter

java.lang.Object
  extended by org.trippi.impl.base.ConcurrentTriplestoreReader
      extended by org.trippi.impl.base.ConcurrentTriplestoreWriter
All Implemented Interfaces:
java.lang.Runnable, TriplestoreReader, TriplestoreWriter

public class ConcurrentTriplestoreWriter
extends ConcurrentTriplestoreReader
implements TriplestoreWriter, java.lang.Runnable

A ConcurrentTriplestoreReader that also implements TriplestoreWriter with concurrent buffered write access.

In addition to on-demand flushes, additions and deletions will periodically by flushed by a separate thread when a certain amount of inactivity has occurred or the buffer reaches a certain size.

If the buffer ever exceeds its safeCapacity(), all updates will be halted until it is flushed.

Author:
cwilper@cs.cornell.edu

Constructor Summary
ConcurrentTriplestoreWriter(TriplestoreSessionPool pool, AliasManager aliasManager, TriplestoreSession updateSession, UpdateBuffer buffer, int autoFlushBufferSize, int autoFlushDormantSeconds)
          Initialize variables, obtain a session for updates, and start the autoFlush thread.
 
Method Summary
 void add(java.util.List triples, boolean flush)
          Add a series of triples to the store.
 void add(org.jrdf.graph.Triple triple, boolean flush)
          Add a single triple to the store (convenience method).
 void add(TripleIterator iter, boolean flush)
          Add a series of triples to the store.
 void close()
          Close the writer, releasing any resources.
 void delete(java.util.List triples, boolean flush)
          Remove a series of triples from the store.
 void delete(org.jrdf.graph.Triple triple, boolean flush)
          Remove a single triple from the store (convenience method).
 void delete(TripleIterator iter, boolean flush)
          Remove a series of triples from the store.
 java.util.List findBufferedUpdates(org.jrdf.graph.SubjectNode subject, org.jrdf.graph.PredicateNode predicate, org.jrdf.graph.ObjectNode object, int updateType)
          Returns an unmodifiable List of TripleUpdates currently in queue.
 void flushBuffer()
          Flush the buffer (write the changes to the store).
 int getBufferSize()
          Get the current size of the buffer.
 void run()
          Watch the buffer and automatically flush it if dormantSeconds or bufferSize is reached.
 void setCacheDeletes(boolean cacheDeletes)
           
 void setFlushErrorHandler(FlushErrorHandler h)
          Set the (optional) handler that will recieve failed flush notification.
 
Methods inherited from class org.trippi.impl.base.ConcurrentTriplestoreReader
countTriples, countTriples, countTriples, countTuples, finalize, findTriples, findTriples, findTriples, findTuples, getAliasMap, listTripleLanguages, listTupleLanguages, setAliasMap
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.trippi.TriplestoreReader
countTriples, countTriples, countTriples, countTuples, findTriples, findTriples, findTriples, findTuples, getAliasMap, listTripleLanguages, listTupleLanguages, setAliasMap
 

Constructor Detail

ConcurrentTriplestoreWriter

public ConcurrentTriplestoreWriter(TriplestoreSessionPool pool,
                                   AliasManager aliasManager,
                                   TriplestoreSession updateSession,
                                   UpdateBuffer buffer,
                                   int autoFlushBufferSize,
                                   int autoFlushDormantSeconds)
                            throws java.io.IOException,
                                   TrippiException
Initialize variables, obtain a session for updates, and start the autoFlush thread.

Throws:
java.io.IOException
TrippiException
Method Detail

setCacheDeletes

public void setCacheDeletes(boolean cacheDeletes)

add

public void add(java.util.List triples,
                boolean flush)
         throws java.io.IOException,
                TrippiException
Add a series of triples to the store. This implementation actually buffers the triples for asychronous addition, which will occur in the autoFlush thread when bufferSize or dormantSeconds is reached. However, if flush is true, the buffer will be flushed in this thread before returning.

Specified by:
add in interface TriplestoreWriter
Parameters:
triples - a list of Triple objects
flush - whether to flush the buffer before returning.
Throws:
java.io.IOException
TrippiException

add

public void add(TripleIterator iter,
                boolean flush)
         throws java.io.IOException,
                TrippiException
Description copied from interface: TriplestoreWriter
Add a series of triples to the store.

Specified by:
add in interface TriplestoreWriter
Parameters:
iter - an iterator over the triples
flush - whether to flush the buffer before returning
Throws:
java.io.IOException
TrippiException

add

public void add(org.jrdf.graph.Triple triple,
                boolean flush)
         throws java.io.IOException,
                TrippiException
Add a single triple to the store (convenience method). This implementation actually buffers the triple for asychronous addition, which will occur in the autoFlush thread when bufferSize or dormantSeconds is reached. However, if flush is true, the buffer will be flushed in this thread before returning.

Specified by:
add in interface TriplestoreWriter
Parameters:
triple - the Triple to add
flush - whether to flush the buffer before returning
Throws:
java.io.IOException
TrippiException

delete

public void delete(java.util.List triples,
                   boolean flush)
            throws java.io.IOException,
                   TrippiException
Remove a series of triples from the store. This implementation actually buffers the triples for asychronous deletion, which will occur in the updater thread when bufferSize or dormantSeconds is reached. However, if flush is true, the buffer will be flushed in this thread before returning.

Specified by:
delete in interface TriplestoreWriter
Parameters:
triples - a list of Triple objects
flush - whether to flush the buffer before returning
Throws:
java.io.IOException
TrippiException

delete

public void delete(TripleIterator iter,
                   boolean flush)
            throws java.io.IOException,
                   TrippiException
Description copied from interface: TriplestoreWriter
Remove a series of triples from the store.

Specified by:
delete in interface TriplestoreWriter
Parameters:
iter - an iterator over the triples
flush - whether to flush the buffer before returning
Throws:
java.io.IOException
TrippiException

delete

public void delete(org.jrdf.graph.Triple triple,
                   boolean flush)
            throws java.io.IOException,
                   TrippiException
Remove a single triple from the store (convenience method). This implementation actually buffers the triple for asychronous deletion, which will occur in the updater thread when bufferSize or dormantSeconds is reached. However, if flush is true, the buffer will be flushed in this thread before returning.

Specified by:
delete in interface TriplestoreWriter
Parameters:
triple - the Triple to delete
flush - whether to flush the buffer before returning
Throws:
java.io.IOException
TrippiException

flushBuffer

public void flushBuffer()
                 throws java.io.IOException,
                        TrippiException
Flush the buffer (write the changes to the store). If it's currently being flushed, wait for it to finish, then re-flush it.

Specified by:
flushBuffer in interface TriplestoreWriter
Throws:
java.io.IOException
TrippiException

setFlushErrorHandler

public void setFlushErrorHandler(FlushErrorHandler h)
Description copied from interface: TriplestoreWriter
Set the (optional) handler that will recieve failed flush notification. Applications can use this to ensure that the contents of the buffer are not lost when a flushing error occurs.

Specified by:
setFlushErrorHandler in interface TriplestoreWriter

getBufferSize

public int getBufferSize()
Description copied from interface: TriplestoreWriter
Get the current size of the buffer.

Specified by:
getBufferSize in interface TriplestoreWriter

run

public void run()
Watch the buffer and automatically flush it if dormantSeconds or bufferSize is reached.

Specified by:
run in interface java.lang.Runnable

close

public void close()
           throws TrippiException
Close the writer, releasing any resources. This will stop the auto buffer-flushing thread, flush the buffer, close the buffer, return the reserved update session to the pool, and finally, close the pool.

Specified by:
close in interface TriplestoreReader
Overrides:
close in class ConcurrentTriplestoreReader
Throws:
TrippiException

findBufferedUpdates

public java.util.List findBufferedUpdates(org.jrdf.graph.SubjectNode subject,
                                          org.jrdf.graph.PredicateNode predicate,
                                          org.jrdf.graph.ObjectNode object,
                                          int updateType)
Description copied from interface: TriplestoreWriter
Returns an unmodifiable List of TripleUpdates currently in queue.

Specified by:
findBufferedUpdates in interface TriplestoreWriter
Returns:
unmodifiable List of TripleUpdates currently in queue