com.crankuptheamps.client
Class RingBookmarkStore

java.lang.Object
  extended by com.crankuptheamps.client.RingBookmarkStore
All Implemented Interfaces:
BookmarkStore

public class RingBookmarkStore
extends Object
implements BookmarkStore

RingBookmarkStore is an implementation of BookmarkStore that stores state on disk and in memory. For each subscription, RingBookmarkStore keeps the most recent bookmark B for which all messages prior to B have been discard()ed by the subscriber. As messages are logged and discarded, an in-memory array is used to track when a new bookmark can be logged.


Constructor Summary
RingBookmarkStore(String path)
           
RingBookmarkStore(String path, int targetNumberOfSubscriptions)
           
 
Method Summary
 void discard(Field subId, long bookmarkSeqNo)
          Log a discard-bookmark entry to the persistent log based on a bookmark sequence number.
 void discard(Message message)
          Log a discard-bookmark entry to the persistent log based on a Message.
 Field getMostRecent(Field subId)
          Returns the most recent bookmark from the log that ought to be used for (re-)subscriptions.
 long getOldestBookmarkSeq(Field subId)
          Called to retrieve the sequence number of the oldest bookmark in the store.
 boolean isDiscarded(Message message)
          Called for each arriving message to determine if the application has already seen this bookmark and should not be reprocessed.
 long log(Message message)
          Log a bookmark to the persistent log.
 void noPersistedAcks(Field subId)
          Called internally to let the bookmark store know that the AMPS server version doesn't support persisted acks for bookmarks.
 void persisted(Field subId, BookmarkField bookmark)
          Called to mark a message as safely persisted by AMPS to all of its sync replication destination.
 void persisted(Field subId, long bookmark)
          Called to mark a message as safely persisted by AMPS to all of its sync replication destination.
 void purge()
          Called to purge the contents of this store.
 void setResizeHandler(BookmarkStoreResizeHandler handler)
          Called to set a resize handler that is invoked when the store needs to resize.
 void setServerVersion(int version)
          Called by the Client when connected to an AMPS server to indicate what version the server is.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RingBookmarkStore

public RingBookmarkStore(String path)
                  throws AMPSException
Throws:
AMPSException

RingBookmarkStore

public RingBookmarkStore(String path,
                         int targetNumberOfSubscriptions)
                  throws AMPSException
Throws:
AMPSException
Method Detail

log

public long log(Message message)
         throws AMPSException
Description copied from interface: BookmarkStore
Log a bookmark to the persistent log.

Specified by:
log in interface BookmarkStore
Returns:
the corresponding bookmark sequence number for this bookmark
Throws:
AMPSException

discard

public void discard(Field subId,
                    long bookmarkSeqNo)
             throws AMPSException
Description copied from interface: BookmarkStore
Log a discard-bookmark entry to the persistent log based on a bookmark sequence number. Recommended to use discard(Message) instead for performance.

Specified by:
discard in interface BookmarkStore
Throws:
AMPSException

discard

public void discard(Message message)
             throws AMPSException
Description copied from interface: BookmarkStore
Log a discard-bookmark entry to the persistent log based on a Message.

Specified by:
discard in interface BookmarkStore
Throws:
AMPSException

getMostRecent

public Field getMostRecent(Field subId)
                    throws AMPSException
Description copied from interface: BookmarkStore
Returns the most recent bookmark from the log that ought to be used for (re-)subscriptions.

Specified by:
getMostRecent in interface BookmarkStore
Throws:
AMPSException

isDiscarded

public boolean isDiscarded(Message message)
                    throws AMPSException
Description copied from interface: BookmarkStore
Called for each arriving message to determine if the application has already seen this bookmark and should not be reprocessed. Returns 'true' if the bookmark is in the log and should not be re-processed, false otherwise.

Specified by:
isDiscarded in interface BookmarkStore
Throws:
AMPSException

persisted

public void persisted(Field subId,
                      BookmarkField bookmark)
               throws AMPSException
Description copied from interface: BookmarkStore
Called to mark a message as safely persisted by AMPS to all of its sync replication destination.

Specified by:
persisted in interface BookmarkStore
Throws:
AMPSException

persisted

public void persisted(Field subId,
                      long bookmark)
               throws AMPSException
Description copied from interface: BookmarkStore
Called to mark a message as safely persisted by AMPS to all of its sync replication destination.

Specified by:
persisted in interface BookmarkStore
Throws:
AMPSException

noPersistedAcks

public void noPersistedAcks(Field subId)
                     throws AMPSException
Description copied from interface: BookmarkStore
Called internally to let the bookmark store know that the AMPS server version doesn't support persisted acks for bookmarks.

Specified by:
noPersistedAcks in interface BookmarkStore
Throws:
AMPSException

getOldestBookmarkSeq

public long getOldestBookmarkSeq(Field subId)
                          throws AMPSException
Description copied from interface: BookmarkStore
Called to retrieve the sequence number of the oldest bookmark in the store.

Specified by:
getOldestBookmarkSeq in interface BookmarkStore
Throws:
AMPSException

setResizeHandler

public void setResizeHandler(BookmarkStoreResizeHandler handler)
Description copied from interface: BookmarkStore
Called to set a resize handler that is invoked when the store needs to resize.

Specified by:
setResizeHandler in interface BookmarkStore

purge

public void purge()
           throws AMPSException
Description copied from interface: BookmarkStore
Called to purge the contents of this store. Removes any tracking history associated with publishers and received messages, and may delete or truncate on-disk representations as well.

Specified by:
purge in interface BookmarkStore
Throws:
AMPSException

setServerVersion

public void setServerVersion(int version)
Description copied from interface: BookmarkStore
Called by the Client when connected to an AMPS server to indicate what version the server is.

Specified by:
setServerVersion in interface BookmarkStore