com.crankuptheamps.client
Class BookmarkRingBuffer

java.lang.Object
  extended by com.crankuptheamps.client.BookmarkRingBuffer

public class BookmarkRingBuffer
extends Object

A ring buffer of bookmarks and activation status Used by all of the bookmark stores to track state of bookmarks we need to hold on to, either because they're active or because they're after an active one.


Nested Class Summary
 class BookmarkRingBuffer.Entry
          Represents a single entry in an array of bookmarks
 
Field Summary
static int UNSET_INDEX
           
 
Constructor Summary
BookmarkRingBuffer()
          Initializes the underlying array, and sets the "last discarded" value to something reasonable.
 
Method Summary
 int capacity()
          Size of underlying array
 boolean discard(long index)
          Discards an entry by index.
 BookmarkRingBuffer.Entry find(BookmarkField field)
          Searches valid Entrys for the given bookmark
 BookmarkRingBuffer.Entry getByIndex(long index)
          Retrieves an Entry given an index
 long getEndIndex()
          Returns the index value one greater than the last valid Entry in self.
 BookmarkField getLastDiscarded()
          Returns the "last discarded" bookmark.
 long getStartIndex()
          Returns the index value associated with the first valid Entry in self.
 boolean isEmpty()
          Returns if the buffer is currently empty.
 long log(BookmarkField bookmark)
          Logs the bookmark by allocating an Entry, setting the Entry to active, copying the bookmark value to that entry, and returning the index of that entry.
 void noPersistedAcks()
          Called to indicate that the server won't provide persisted acks for the bookmarks so anything that is discarded should be assumed persisted.
 void persisted(BookmarkField bookmark)
          Mark all records up to the and including the provided bookmark as safe for discard and discard all appropriate bookmarks.
 void persisted(long bookmark)
           
 boolean persistedAcks()
          Called to check if persisted acks are expected.
 long relog(long oldIndex, BookmarkField bookmark)
          Re-logs the bookmark by copying an Entry to a new location and returning the index of that new location.
 void setPersistedAcks()
          Called to indicate that the server will provide persisted acks for the bookmarks.
 long setRecovery()
           
 void setResizeHandler(BookmarkStoreResizeHandler handler, BookmarkStore store)
           
 void setSubId(Field sub)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNSET_INDEX

public static final int UNSET_INDEX
See Also:
Constant Field Values
Constructor Detail

BookmarkRingBuffer

public BookmarkRingBuffer()
Initializes the underlying array, and sets the "last discarded" value to something reasonable.

Method Detail

capacity

public int capacity()
Size of underlying array

Returns:
current capacity of self.

getByIndex

public BookmarkRingBuffer.Entry getByIndex(long index)
Retrieves an Entry given an index

Parameters:
index - An index returned by .getIndex(), getStartIndex(), getEndIndex(), log, etc.
Returns:
The entry at that index, or null if not found.

getLastDiscarded

public BookmarkField getLastDiscarded()
Returns the "last discarded" bookmark. This may be a newer bookmark than the one you last passed to discard(), if you're discarding out of order.

Returns:
the last bookmark to be discarded.

isEmpty

public boolean isEmpty()
Returns if the buffer is currently empty.

Returns:
true if self is empty and false otherwise.

getStartIndex

public long getStartIndex()
Returns the index value associated with the first valid Entry in self.

Returns:
index of first valid entry.

getEndIndex

public long getEndIndex()
Returns the index value one greater than the last valid Entry in self.

Returns:
index 1 greater than last valid entry.

log

public long log(BookmarkField bookmark)
Logs the bookmark by allocating an Entry, setting the Entry to active, copying the bookmark value to that entry, and returning the index of that entry.

Parameters:
bookmark - the bookmark to loc
Returns:
the index of the new Entry.

relog

public long relog(long oldIndex,
                  BookmarkField bookmark)
Re-logs the bookmark by copying an Entry to a new location and returning the index of that new location.

Parameters:
bookmark - the index to move
Returns:
the index of the new Entry.

discard

public boolean discard(long index)
Discards an entry by index. If the discard is completed, lastDiscarded will change, otherwise the discard is cached in the entry, and the getLastDiscarded() value is unchanged.

Parameters:
index - the index of the entry.
Returns:
true if this caused lastDiscarded to change.

find

public BookmarkRingBuffer.Entry find(BookmarkField field)
Searches valid Entrys for the given bookmark

Parameters:
field - the bookmark to search for
Returns:
the Entry containing the given bookmark, or null.

persisted

public void persisted(BookmarkField bookmark)
Mark all records up to the and including the provided bookmark as safe for discard and discard all appropriate bookmarks. Applies to server versions 3.8x.

Parameters:
bookmark - The latest bookmark that can be safely disposed.

persisted

public void persisted(long bookmark)

noPersistedAcks

public void noPersistedAcks()
Called to indicate that the server won't provide persisted acks for the bookmarks so anything that is discarded should be assumed persisted.


setPersistedAcks

public void setPersistedAcks()
Called to indicate that the server will provide persisted acks for the bookmarks.


persistedAcks

public boolean persistedAcks()
Called to check if persisted acks are expected.


setResizeHandler

public void setResizeHandler(BookmarkStoreResizeHandler handler,
                             BookmarkStore store)

setSubId

public void setSubId(Field sub)

setRecovery

public long setRecovery()