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()
Initializes a new instance of the MemoryBookmarkStore class with default settings.
|
MemoryBookmarkStore(int targetNumberOfSubscriptions)
Constructor for MemoryBookmarkStore with a target number of subscriptions.
|
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 internally to update the RecoveryPointAdapter if there is one.
|
void |
close()
Closes down the bookmark store.
|
void |
discard(Field subId,
long bookmarkSeqNo)
Discard a message based on the subscription ID and bookmark sequence number.
|
void |
discard(Message message)
Discard a message based on the provided message.
|
protected MemoryBookmarkStore.Subscription |
find(Field subId)
Finds and returns the Subscription object for the specified
subscription id (subId).
|
Field |
getMostRecent(Field subId)
Get the most recent bookmark for a specific subscription.
|
Field |
getMostRecent(Field subId,
boolean useList)
Get the most recent bookmark for a specific subscription.
|
long |
getOldestBookmarkSeq(Field subId)
Get the oldest bookmark sequence number for a specific subscription.
|
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)
Check if a message is discarded based on its bookmark.
|
long |
log(Message message)
Log a message and update the bookmark sequence number.
|
void |
persisted(Field subId,
BookmarkField bookmark)
Persist a bookmark for a subscription.
|
void |
persisted(Field subId,
long bookmark)
Deprecated.
use
persisted(Field, BookmarkField) instead. |
void |
purge()
Remove all entries in the bookmark store, completely clearing all records of
messages received and discarded.
|
void |
purge(Field subId_)
Remove entries for a specific subscription ID, clearing its records of
messages received and discarded.
|
void |
setRecoveryPointFactory(RecoveryPointFactory factory_)
Change the RecoveryPointFactory used by this store for its adaptor.
|
void |
setResizeHandler(BookmarkStoreResizeHandler handler)
Set the resize handler for this bookmark store and all associated
subscriptions.
|
void |
setServerVersion(int version)
Set the version of the AMPS server.
|
protected RecoveryPointAdapter _adapter
protected RecoveryPointFactory _factory
public MemoryBookmarkStore()
public MemoryBookmarkStore(int targetNumberOfSubscriptions)
targetNumberOfSubscriptions
- The target number of subscriptions to
pre-initialize.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 nullpublic long log(Message message) throws AMPSException
log
in interface BookmarkStore
message
- The message to log.AMPSException
- If an error occurs during the log operation.public void discard(Field subId, long bookmarkSeqNo) throws AMPSException
discard
in interface BookmarkStore
subId
- The subscription ID.bookmarkSeqNo
- The bookmark sequence number to discard.AMPSException
- If an error occurs during the discard operation.public void discard(Message message) throws AMPSException
discard
in interface BookmarkStore
message
- The message to discard.AMPSException
- If an error occurs during the discard operation.public Field getMostRecent(Field subId) throws AMPSException
getMostRecent
in interface BookmarkStore
subId
- The subscription ID.AMPSException
- If an error occurs during the operation.public Field getMostRecent(Field subId, boolean useList) throws AMPSException
getMostRecent
in interface BookmarkStore
subId
- The subscription ID.useList
- Indicates whether to use the bookmark list.AMPSException
- If an error occurs during the operation.public boolean isDiscarded(Message message) throws AMPSException
isDiscarded
in interface BookmarkStore
message
- The message to check.AMPSException
- If an error occurs during the operation.@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
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.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
- If an error occurs during the purge operation.public void purge(Field subId_) throws AMPSException
purge
in interface BookmarkStore
subId_
- The subscription ID to purge.AMPSException
- If an error occurs during the purge operation.public long getOldestBookmarkSeq(Field subId) throws AMPSException
getOldestBookmarkSeq
in interface BookmarkStore
subId
- The subscription ID.AMPSException
- If an error occurs during the operation.public void setResizeHandler(BookmarkStoreResizeHandler handler)
setResizeHandler
in interface BookmarkStore
handler
- The BookmarkStoreResizeHandler to set.public void setServerVersion(int version)
setServerVersion
in interface BookmarkStore
version
- The server version to set.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.