org.eclipse.jgit.storage.dht.spi.cache
Class CacheBuffer

java.lang.Object
  extended by org.eclipse.jgit.storage.dht.spi.util.AbstractWriteBuffer
      extended by org.eclipse.jgit.storage.dht.spi.cache.CacheBuffer
All Implemented Interfaces:
WriteBuffer

public class CacheBuffer
extends AbstractWriteBuffer

WriteBuffer implementation for a CacheDatabase.


Constructor Summary
CacheBuffer(WriteBuffer dbBuffer, CacheService client, CacheOptions options)
          Initialize a new buffer.
 
Method Summary
 void abort()
          Abort pending writes, and wait for acknowledgment.
 void flush()
          Flush any pending writes, and wait for them to complete.
 WriteBuffer getWriteBuffer()
           
 void modify(CacheService.Change op)
          Schedule any cache change.
 void put(CacheKey key, byte[] value)
          Schedule storing (or replacing) a key in the cache.
 void remove(CacheKey key)
          Schedule removal of a key from the cache.
 void removeAfterFlush(CacheKey key)
          Schedule a removal only after the underlying database flushes.
protected  void startQueuedOperations(int bytes)
          Start all queued operations.
 
Methods inherited from class org.eclipse.jgit.storage.dht.spi.util.AbstractWriteBuffer
add, queued, start, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheBuffer

public CacheBuffer(WriteBuffer dbBuffer,
                   CacheService client,
                   CacheOptions options)
Initialize a new buffer.

Parameters:
dbBuffer - the underlying database's own buffer.
client - connection to the cache service.
options - options controlling cache operations.
Method Detail

remove

public void remove(CacheKey key)
            throws DhtException
Schedule removal of a key from the cache.

Unlike removeAfterFlush(CacheKey), these removals can be flushed when the cache buffer is full, potentially before any corresponding removal is written to the underlying database.

Parameters:
key - key to remove.
Throws:
DhtException - a prior flush failed.

removeAfterFlush

public void removeAfterFlush(CacheKey key)
Schedule a removal only after the underlying database flushes.

Unlike remove(CacheKey), these removals are buffered until the application calls flush() and aren't sent to the cache service until after the underlying database flush() operation is completed successfully.

Parameters:
key - key to remove.

put

public void put(CacheKey key,
                byte[] value)
         throws DhtException
Schedule storing (or replacing) a key in the cache.

Parameters:
key - key to store.
value - new value to store.
Throws:
DhtException - a prior flush failed.

modify

public void modify(CacheService.Change op)
            throws DhtException
Schedule any cache change.

Parameters:
op - the cache operation.
Throws:
DhtException - a prior flush failed.

getWriteBuffer

public WriteBuffer getWriteBuffer()
Returns:
the underlying database's own write buffer.

startQueuedOperations

protected void startQueuedOperations(int bytes)
                              throws DhtException
Description copied from class: AbstractWriteBuffer
Start all queued operations.

This method is invoked by AbstractWriteBuffer.queued(int) or by AbstractWriteBuffer.flush() when there is a non-zero number of bytes already enqueued as a result of prior AbstractWriteBuffer.add(int) and {#link AbstractWriteBuffer.queued(int) calls.

Implementors should use AbstractWriteBuffer.start(Callable, int) to begin their mutation tasks in the background.

Specified by:
startQueuedOperations in class AbstractWriteBuffer
Parameters:
bytes - number of bytes that were already enqueued. This count should be passed to AbstractWriteBuffer.start(Callable, int).
Throws:
DhtException - a previously started operation completed and failed.

flush

public void flush()
           throws DhtException
Description copied from interface: WriteBuffer
Flush any pending writes, and wait for them to complete.

Specified by:
flush in interface WriteBuffer
Overrides:
flush in class AbstractWriteBuffer
Throws:
DhtException - one or more writes failed. As writes may occur in any order, the exact state of the database is unspecified.

abort

public void abort()
           throws DhtException
Description copied from interface: WriteBuffer
Abort pending writes, and wait for acknowledgment.

Once a buffer has been aborted, it cannot be reused. Application code must discard the buffer instance and use a different buffer to issue subsequent operations.

If writes have not been started yet, they should be discarded and not submitted to the storage system.

If writes have already been started asynchronously in the background, this method may try to cancel them, but must wait for the operation to either complete or abort before returning. This allows callers to clean up by scanning the storage system and making corrections to clean up any partial writes.

Specified by:
abort in interface WriteBuffer
Overrides:
abort in class AbstractWriteBuffer
Throws:
DhtException - one or more already started writes failed.


Copyright © 2011. All Rights Reserved.