com.crankuptheamps.client
Class HybridPublishStore

java.lang.Object
  extended by com.crankuptheamps.client.HybridPublishStore
All Implemented Interfaces:
Store

public class HybridPublishStore
extends Object
implements Store

PublishStore that stores first in memory, and swaps excess out to disk.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.crankuptheamps.client.Store
Store.StoreReplayer
 
Field Summary
protected  int _cap
           
protected  PublishStore _fileStore
           
protected  long _lowestIndexInTheFile
           
protected  int _lowWatermark
           
protected  MemoryPublishStore _memoryStore
           
protected  String _path
           
 
Fields inherited from interface com.crankuptheamps.client.Store
SOWDeleteByData, SOWDeleteByFilter, SOWDeleteByKeys
 
Constructor Summary
HybridPublishStore(String path, int cap)
           
 
Method Summary
 void discardUpTo(long index)
          Discard all operations up to the index provided.
 void flush()
          Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return.
 void flush(long timeout)
          Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return.
 long getLowestUnpersisted()
          Return the oldest index in the store.
 void replay(Store.StoreReplayer replayer)
          Replay all operations in the store using the provided StoreReplayer.
 void replaySingle(Store.StoreReplayer replayer, long index)
          Replay the operation at the specified index.
 void setLowWatermark(int lowWatermark_)
          Sets the low watermark; once we start swapping out to disk, we keep going until the number of entries in memory is lower than this.
 void setResizeHandler(PublishStoreResizeHandler handler)
          Set the resize handler for the publish store.
 void store(long index, int operation, byte[] topic, long topicOffset, long topicLength, byte[] data, long dataOffset, long dataLength, byte[] corId, long corIdOff, long corIdLen)
          Store the provided operation.
 void store(long index, int operation, byte[] topic, long topicOffset, long topicLength, byte[] data, long dataOffset, long dataLength, byte[] corId, long corIdOff, long corIdLen, int expiration)
          Store the provided operation.
 void store(long index, int operation, byte[] topic, long topicOffset, long topicLength, byte[] data, long dataOffset, long dataLength, int expiration, CommandId cmdId)
          Store the provided operation.
 long unpersistedCount()
          Return the number of operations in the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_fileStore

protected PublishStore _fileStore

_memoryStore

protected MemoryPublishStore _memoryStore

_cap

protected int _cap

_path

protected String _path

_lowWatermark

protected int _lowWatermark

_lowestIndexInTheFile

protected long _lowestIndexInTheFile
Constructor Detail

HybridPublishStore

public HybridPublishStore(String path,
                          int cap)
                   throws IOException,
                          StoreException
Throws:
IOException
StoreException
Method Detail

setLowWatermark

public void setLowWatermark(int lowWatermark_)
Sets the low watermark; once we start swapping out to disk, we keep going until the number of entries in memory is lower than this.

Parameters:
lowWatermark_ - The number of entries to serve as a low watermark.

getLowestUnpersisted

public long getLowestUnpersisted()
Description copied from interface: Store
Return the oldest index in the store.

Specified by:
getLowestUnpersisted in interface Store

discardUpTo

public void discardUpTo(long index)
                 throws StoreException
Description copied from interface: Store
Discard all operations up to the index provided.

Specified by:
discardUpTo in interface Store
Parameters:
index - the index number to keep -- all previous index numbers will be discarded
Throws:
StoreException

replay

public void replay(Store.StoreReplayer replayer)
            throws StoreException,
                   DisconnectedException
Description copied from interface: Store
Replay all operations in the store using the provided StoreReplayer.

Specified by:
replay in interface Store
Parameters:
replayer - the StoreReplayer to use to replay the operations
Throws:
StoreException
DisconnectedException

unpersistedCount

public long unpersistedCount()
Description copied from interface: Store
Return the number of operations in the store.

Specified by:
unpersistedCount in interface Store

replaySingle

public void replaySingle(Store.StoreReplayer replayer,
                         long index)
                  throws StoreException,
                         DisconnectedException
Description copied from interface: Store
Replay the operation at the specified index.

Specified by:
replaySingle in interface Store
Throws:
StoreException
DisconnectedException

store

public void store(long index,
                  int operation,
                  byte[] topic,
                  long topicOffset,
                  long topicLength,
                  byte[] data,
                  long dataOffset,
                  long dataLength,
                  byte[] corId,
                  long corIdOff,
                  long corIdLen)
           throws StoreException
Description copied from interface: Store
Store the provided operation. The index provided is a key that the client can later use to replay the operation or remove the operation from the store. Implementations may assume that the index increases monotonically.

Specified by:
store in interface Store
Parameters:
index - an index that identifies this operation
operation - the operation to store
topic - a byte array containing the name of the topic for this operation
topicOffset - the offset in the topic array where the topic name begins
topicLength - the length of the topic name
data - a byte array containing the data for this operation
dataOffset - the offset into the data array where the data begins
dataLength - the length of the data
corId - the correlation ID for this message
corIdOff - the offset into the correlation ID array where the correlation ID begins
corIdLen - the length of the correlation ID
Throws:
StoreException

store

public void store(long index,
                  int operation,
                  byte[] topic,
                  long topicOffset,
                  long topicLength,
                  byte[] data,
                  long dataOffset,
                  long dataLength,
                  byte[] corId,
                  long corIdOff,
                  long corIdLen,
                  int expiration)
           throws StoreException
Description copied from interface: Store
Store the provided operation. The index provided is a key that the client can later use to replay the operation or remove the operation from the store. Implementations may assume that the index increases monotonically.

Specified by:
store in interface Store
Parameters:
index - an index that identifies this operation
operation - the operation to store
topic - a byte array containing the name of the topic for this operation
topicOffset - the offset in the topic array where the topic name begins
topicLength - the length of the topic name
data - a byte array containing the data for this operation
dataOffset - the offset into the data array where the data begins
dataLength - the length of the data
corId - the correlation ID for this message
corIdOff - the offset into the correlation ID array where the correlation ID begins
corIdLen - the length of the correlation ID
expiration - the expiration to set on the operation
Throws:
StoreException

store

public void store(long index,
                  int operation,
                  byte[] topic,
                  long topicOffset,
                  long topicLength,
                  byte[] data,
                  long dataOffset,
                  long dataLength,
                  int expiration,
                  CommandId cmdId)
           throws StoreException
Description copied from interface: Store
Store the provided operation. The index provided is a key that the client can later use to replay the operation or remove the operation from the store. Implementations may assume that the index increases monotonically.

Specified by:
store in interface Store
Parameters:
index - an index that identifies this operation
operation - the operation to store
topic - a byte array containing the name of the topic for this operation
topicOffset - the offset in the topic array where the topic name begins
topicLength - the length of the topic name
data - a byte array containing the data for this operation
dataOffset - the offset into the data array where the data begins
dataLength - the length of the data
expiration - the expiration to set on the operation
cmdId - the commandId to set on the operation
Throws:
StoreException

flush

public void flush()
           throws TimedOutException
Description copied from interface: Store
Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return.

Specified by:
flush in interface Store
Throws:
TimedOutException

flush

public void flush(long timeout)
           throws TimedOutException
Description copied from interface: Store
Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return. Throw an exception if this is not completed in the number of milliseconds specified by the timeout.

Specified by:
flush in interface Store
Parameters:
timeout - the number of milliseconds to wait for the flush
Throws:
TimedOutException

setResizeHandler

public void setResizeHandler(PublishStoreResizeHandler handler)
Description copied from interface: Store
Set the resize handler for the publish store. An implementation can call the resize handler in the event that it needs to grow the size of the publish store.

Specified by:
setResizeHandler in interface Store