public class MemoryBookmarkStore extends java.lang.Object implements BookmarkStore
RecoveryPointAdapter
can be specified at construction
to persist bookmark subscription recovery state to an external store so the
subscription can be resumed if the subscriber fails.Modifier and Type | Class and Description |
---|---|
protected static class |
MemoryBookmarkStore.Subscription
The Subscription object is used to represent internal bookmark state
for the messages received and discarded on a specific subscription
within the bookmark store.
|
Modifier and Type | Field and Description |
---|---|
protected RecoveryPointAdapter |
_adapter
Optional recovery point adapter used to persist bookmark replay recovery
state for each subscription.
|
protected RecoveryPointFactory |
_factory |
Constructor and Description |
---|
MemoryBookmarkStore() |
MemoryBookmarkStore(int targetNumberOfSubscriptions) |
MemoryBookmarkStore(int targetNumberOfSubscriptions,
RecoveryPointAdapter adapter)
Initialize self with a target number of subscriptions to pool and the
specified recovery point adapter.
|
MemoryBookmarkStore(int targetNumberOfSubscriptions,
RecoveryPointAdapter adapter,
RecoveryPointFactory factory)
Initialize self with a target number of subscriptions to pool and the
specified recovery point adapter.
|
Modifier and Type | Method and Description |
---|---|
protected void |
adapterUpdate(Field subId,
BookmarkField bookmark)
Used inernally to update the RecoveryPointAdapter if there is one.
|
void |
close()
Closes down the bookmark store.
|
void |
discard(Field subId,
long bookmarkSeqNo)
Call this when you want to mark the message specified by the
subscription ID and the bookmark sequence number as discarded,
indicating that the application has completed processing the message.
|
void |
discard(Message message)
Call this when you want to mark the provided message as discarded,
indicating that the application has completed processing the message.
|
protected MemoryBookmarkStore.Subscription |
find(Field subId)
Finds and returns the Subscription object for the specified
subscription id (subId).
|
Field |
getMostRecent(Field subId)
Call this when you want to return the correct recovery point for
resubscription of the provided subID from the BookmarkStore.
|
Field |
getMostRecent(Field subId,
boolean useList)
Call this when you want to return the correct recovery point for
resubscription of the provided subID from the BookmarkStore.
|
long |
getOldestBookmarkSeq(Field subId)
Call this when you want to retrieve the sequence number of the oldest bookmark in the store.
|
int |
getServerVersion()
Called by Client when connected to an AMPS server in order to retrieve the version
number of the server.
|
boolean |
isDiscarded(Message message)
Called for each arriving message to determine if
the application has already processed and discarded this message.
|
long |
log(Message message)
Called internally by the Client to log a bookmark to the persistent log.
|
void |
persisted(Field subId,
BookmarkField bookmark)
Called internally by the Client to record the last persisted message in the transaction log of the connected AMPS server
to all of its sync replication destinations.
|
void |
persisted(Field subId,
long bookmark)
Deprecated.
use
persisted(Field, BookmarkField) instead. |
void |
purge()
Remove all entries in the bookmark store, completely
clearing all record of messages received and discarded.
|
void |
purge(Field subId_)
Call this when you want to purge the contents of this store for a given subscription ID.
|
void |
setRecoveryPointFactory(RecoveryPointFactory factory_)
Change the RecoveryPointFactory used by this store for its adapter.
|
void |
setResizeHandler(BookmarkStoreResizeHandler handler)
Called this when you want to set a resize handler that is invoked when the store needs to resize.
|
void |
setServerVersion(int version)
Called internally by the Client when connected to an AMPS server to indicate
what version the server is.
|
protected RecoveryPointAdapter _adapter
protected RecoveryPointFactory _factory
public MemoryBookmarkStore()
public MemoryBookmarkStore(int targetNumberOfSubscriptions)
public MemoryBookmarkStore(int targetNumberOfSubscriptions, RecoveryPointAdapter adapter) throws AMPSException
targetNumberOfSubscriptions
- The number of subscriptions this store
will initially create in its pool.adapter
- Recovery point adapter this instance will
call with recovery point state for each of its subscriptions.
The adapter can persist this state to an external store and
retrieve it on application restart so that bookmark replay
subscriptions can be continued approximately where they left off
(with the possible delivery of some duplicate messages). The
adapter will be given FixedRecoveryPoints.AMPSException
- If the given adapter throws an exception during
recovery.public MemoryBookmarkStore(int targetNumberOfSubscriptions, RecoveryPointAdapter adapter, RecoveryPointFactory factory) throws AMPSException
targetNumberOfSubscriptions
- The number of subscriptions this store
will initially create in its pool.adapter
- Recovery point adapter this instance will
call with recovery point state for each of its subscriptions.
The adapter can persist this state to an external store and
retrieve it on application restart so that bookmark replay
subscriptions can be continued approximately where they left off
(with the possible delivery of some duplicate messages).factory
- RecoveryPointFactory that will produce RecoveryPoints
for the adapter.AMPSException
- If the given adapter throws an exception during
recovery.public void setRecoveryPointFactory(RecoveryPointFactory factory_) throws AMPSException
factory_
- The new RecoveryPointFactoryAMPSException
- if the factory_ parameter is null or the recovery point adapter is null.public long log(Message message) throws AMPSException
BookmarkStore
log
in interface BookmarkStore
message
- The message containing the bookmark to log.AMPSException
- Thrown when the message cannot be logged.public void discard(Field subId, long bookmarkSeqNo) throws AMPSException
BookmarkStore
discard
in interface BookmarkStore
subId
- The subscription ID of the bookmark.bookmarkSeqNo
- The bookmark sequence number.AMPSException
- Thrown when the specified bookmark cannot be discareded.public void discard(Message message) throws AMPSException
BookmarkStore
discard
in interface BookmarkStore
message
- Message to be marked as discarded.AMPSException
- Thrown when the specified message cannot be discareded.public Field getMostRecent(Field subId) throws AMPSException
BookmarkStore
getMostRecent
in interface BookmarkStore
subId
- The subscription ID of the most recent bookmark.AMPSException
- Thrown when the store cannot produce a recovery point for the specified subID.public Field getMostRecent(Field subId, boolean useList) throws AMPSException
BookmarkStore
getMostRecent
in interface BookmarkStore
subId
- The subscription ID of the most recent bookmark.useList
- In the case where the store has not received any persisted
acks, it will build a list of bookmarks based on the last discarded for
each publisher if true (default).AMPSException
- Thrown when the store cannot produce a recovery point for the specified subID.public boolean isDiscarded(Message message) throws AMPSException
BookmarkStore
isDiscarded
in interface BookmarkStore
message
- Message used to determine if the application has already
processed and discarded the message.AMPSException
- Thrown when the store cannot determine if the message is discarded.@Deprecated public void persisted(Field subId, long bookmark) throws AMPSException
persisted(Field, BookmarkField)
instead.persisted
in interface BookmarkStore
subId
- The subId associated with the bookmark to be persisted.bookmark
- The bookmark to be persisted.AMPSException
- If the bookmark was unable to be persisted to the bookmark store.public void persisted(Field subId, BookmarkField bookmark) throws AMPSException
BookmarkStore
persisted
in interface BookmarkStore
subId
- The subscription ID for the message.bookmark
- The bookmark containing the message.AMPSException
- Thrown if the store is unable to record information in the store.protected MemoryBookmarkStore.Subscription find(Field subId)
subId
- The subId to find or create a Subscription for.public void purge() throws AMPSException
purge
in interface BookmarkStore
AMPSException
- Thrown if the store is unable to remove the contents.public void purge(Field subId_) throws AMPSException
BookmarkStore
purge
in interface BookmarkStore
subId_
- The identifier of the subscription to purge.AMPSException
- Thrown if the store is unable to remove information for the subscription.public long getOldestBookmarkSeq(Field subId) throws AMPSException
BookmarkStore
getOldestBookmarkSeq
in interface BookmarkStore
subId
- The subscription ID for the oldest bookmark in the store.AMPSException
- The operation could not successfully be completed.public void setResizeHandler(BookmarkStoreResizeHandler handler)
BookmarkStore
setResizeHandler
in interface BookmarkStore
handler
- The handler to invoke for the resize.public void setServerVersion(int version)
BookmarkStore
setServerVersion
in interface BookmarkStore
version
- The version of the AMPS server.public int getServerVersion()
public void close() throws AMPSException
close
in interface java.lang.AutoCloseable
AMPSException
protected void adapterUpdate(Field subId, BookmarkField bookmark) throws java.io.IOException
subId
- The subId to update.bookmark
- The latest bookmark.java.io.IOException
- If there is an exception from the adapter.