public class LoggedBookmarkStore extends java.lang.Object implements BookmarkStore
prune()
to manage the size of the file by removing
outdated entries.
When using LoggedBookmarkStore, it is important to note that this store
is intended to provide the ability for the application to fail and resume.
If your application does not require this fail-and-resume functionality,
it is recommended to use a MemoryBookmarkStore.
Usage:
The LoggedBookmarkStore is automatically set on the returned client
when `createFileBacked` is called. This store is responsible for
tracking and managing bookmarks associated with the client's state.Modifier and Type | Class and Description |
---|---|
protected static class |
LoggedBookmarkStore.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.
|
Constructor and Description |
---|
LoggedBookmarkStore(java.lang.String path)
This constructor is equivalent to calling `LoggedBookmarkStore(path, 1,
false)`.
|
LoggedBookmarkStore(java.lang.String path,
int targetNumberOfSubscriptions)
This constructor is equivalent to calling `LoggedBookmarkStore(path,
targetNumberOfSubscriptions, false)`.
|
LoggedBookmarkStore(java.lang.String path,
int targetNumberOfSubscriptions,
boolean useLastModifiedTime)
A file-backed bookmark store implementation that fully supports
discarding messages in an order different from the order they arrived
(i.e.
|
LoggedBookmarkStore(java.lang.String path,
int targetNumberOfSubscriptions,
boolean useLastModifiedTime,
RecoveryPointAdapter adapter)
A file-backed bookmark store implementation that fully supports
discarding messages in an order different from the order they arrived
(i.e.
|
LoggedBookmarkStore(java.lang.String path,
int targetNumberOfSubscriptions,
boolean useLastModifiedTime,
RecoveryPointAdapter adapter,
RecoveryPointFactory factory)
A file-backed bookmark store implementation that fully supports
discarding messages in an order different from the order they arrived
(i.e.
|
Modifier and Type | Method and Description |
---|---|
void |
_purge()
Removes all entries in the bookmark store and clears all records of messages
received and discarded.
|
void |
_purge(Field subId_)
Removes all entries in the bookmark store associated with a specific
subscription ID (subId_).
|
protected void |
adapterUpdate(Field subId,
BookmarkField bookmark)
Used internally to update the RecoveryPointAdapter if there is one.
|
void |
close()
Closes the bookmark store.
|
void |
discard(Field subId,
long bookmarkSeqNo)
Discards a bookmark entry associated with a specific subscription and
bookmark sequence number.
|
void |
discard(Message message)
Discards a bookmark entry based on the information provided in the message.
|
protected LoggedBookmarkStore.Subscription |
find(Field subId)
Finds and returns the Subscription object for the specified
subscription id (subId).
|
Field |
getMostRecent(Field subId)
Retrieves the most recent bookmark associated with a subscription identified
by the given subId.
|
Field |
getMostRecent(Field subId,
boolean useList)
Retrieves the most recent bookmark associated with a subscription identified
by the given subId.
|
long |
getOldestBookmarkSeq(Field subId)
Retrieves the oldest bookmark sequence number associated with a 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)
This method is called internally by the client to determine whether a
message's bookmark received from the amps server has already been discarded
OR already been delivered to the subscriber during this run.
|
long |
log(Message message)
This is a method the Client calls and is not for customer user.
|
void |
persisted(Field subId,
BookmarkField bookmark)
This method is called by the client and it is used to process persisted
acknowledgements that track a safe recovery point in the txlog.
|
void |
persisted(Field subId,
long bookmark)
Deprecated.
Use
persisted(Field, BookmarkField) instead. |
void |
prune()
Remove outdated entries in the bookmark store.
|
void |
prune(java.lang.String tmpFileName_)
Remove outdated entries in the bookmark store.
|
void |
purge()
Remove all entries in the bookmark store, completely
clearing all record of messages received and discarded.
|
void |
purge(Field subId_)
Removes all entries in the bookmark store associated with a specific
subscription ID (subId_).
|
void |
setRecoveryPointFactory(RecoveryPointFactory factory_)
Change the RecoveryPointFactory used by this store for its adapter.
|
void |
setResizeHandler(BookmarkStoreResizeHandler handler)
Sets a handler for bookmark store resize events.
|
void |
setServerVersion(int version)
Used to change the version of the AMPS server that this bookmark store's
client has connected to.
|
public LoggedBookmarkStore(java.lang.String path) throws java.io.IOException
path
- The path to the backing bookmark log file.java.io.IOException
- If there is a problem creating, reading, or writing
the backing file.LoggedBookmarkStore(String, int, boolean)
public LoggedBookmarkStore(java.lang.String path, int targetNumberOfSubscriptions) throws java.io.IOException
path
- The path to the backing bookmark log file.targetNumberOfSubscriptions
- The initial capacity for the number.java.io.IOException
- If there is a problem creating, reading, or writing
the backing file.LoggedBookmarkStore(String, int, boolean)
public LoggedBookmarkStore(java.lang.String path, int targetNumberOfSubscriptions, boolean useLastModifiedTime) throws java.io.IOException
path
- The path to the backing bookmark log file.targetNumberOfSubscriptions
- The initial capacity for the number
of bookmark subscriptions you anticipate
creating on the AMPS client instance that
this bookmark store is registered on. This
will grow as needed if more subscriptions
are created than anticipated.useLastModifiedTime
- Indicates whether the recovery timestamp
feature should be used. If true, the
last-modified time of the
backing file is included (as an AMPS
timestamp bookmark in a
comma-separated list of bookmarks) when
getMostRecent() is called
after recovering from a bookmark file.
This feature could be
useful if you have an infrequently run
process that is run on a
schedule that is longer than the AMPS
server keeps messages in
its transaction log. When this process is
started and recovers
a bookmark log full of old bookmarks that
are no longer available
using the MOST_RECENT bookmark indicator,
the recovery timestamp
will cause the bookmark subscription to
begin at the start of the
transaction log (e.g. EPOCH), rather than
its tail (e.g. NOW).java.io.IOException
- If there is a problem creating, reading, or writing
the backing file.public LoggedBookmarkStore(java.lang.String path, int targetNumberOfSubscriptions, boolean useLastModifiedTime, RecoveryPointAdapter adapter) throws java.io.IOException
path
- The path to the backing bookmark log file.targetNumberOfSubscriptions
- The initial capacity for the number
of bookmark subscriptions you anticipate
creating on the AMPS client instance that
this bookmark store is registered on. This
will grow as needed if more subscriptions
are created than anticipated.useLastModifiedTime
- Indicates whether the recovery timestamp
feature should be used. If true, the
last-modified time of the
backing file is included (as an AMPS
timestamp bookmark in a
comma-separated list of bookmarks) when
getMostRecent() is called
after recovering from a bookmark file.
This feature could be
useful if you have an infrequently run
process that is run on a
schedule that is longer than the AMPS
server keeps messages in
its transaction log. When this process is
started and recovers
a bookmark log full of old bookmarks that
are no longer available
using the MOST_RECENT bookmark indicator,
the recovery timestamp
will cause the bookmark subscription to
begin at the start of the
transaction log (e.g. EPOCH), rather than
its tail (e.g. NOW).adapter
- The RecoveryPointAdapter backing up the
store. The adapter will be sent
FixedRecoveryPoints.java.io.IOException
- If there is a problem creating, reading, or writing
the backing file.public LoggedBookmarkStore(java.lang.String path, int targetNumberOfSubscriptions, boolean useLastModifiedTime, RecoveryPointAdapter adapter, RecoveryPointFactory factory) throws java.io.IOException
path
- The path to the backing bookmark log file.targetNumberOfSubscriptions
- The initial capacity for the number
of bookmark subscriptions you anticipate
creating on the AMPS client instance that
this bookmark store is registered on. This
will grow as needed if more subscriptions
are created than anticipated.useLastModifiedTime
- Indicates whether the recovery timestamp
feature should be used. If true, the
last-modified time of the
backing file is included (as an AMPS
timestamp bookmark in a
comma-separated list of bookmarks) when
getMostRecent() is called
after recovering from a bookmark file.
This feature could be
useful if you have an infrequently run
process that is run on a
schedule that is longer than the AMPS
server keeps messages in
its transaction log. When this process is
started and recovers
a bookmark log full of old bookmarks that
are no longer available
using the MOST_RECENT bookmark indicator,
the recovery timestamp
will cause the bookmark subscription to
begin at the start of the
transaction log (e.g. EPOCH), rather than
its tail (e.g. NOW).adapter
- The RecoveryPointAdapter backing up the
store.factory
- The RecoveryPointFactory used to create
RecoveryPoints that are sent to the
adapter.java.io.IOException
- If there is a problem creating, reading, or writing
the backing file.public void prune() throws java.io.IOException, StoreException
java.io.IOException
- Thrown when an operation on the file fails.StoreException
- Thrown when any other operation fails with details on
the failure.public void prune(java.lang.String tmpFileName_) throws java.io.IOException, StoreException
tmpFileName_
- The name of the temporary file.java.io.IOException
- Thrown when an operation on the file fails.StoreException
- Thrown when any other operation fails with details on
the failure.public long log(Message message) throws AMPSException
log
in interface BookmarkStore
message
- The message to log, containing the bookmark to be stored.AMPSException
- If an error occurs while logging to the bookmark store.public void discard(Field subId, long bookmarkSeqNo) throws AMPSException
discard
in interface BookmarkStore
subId
- The identifier of the subscription.bookmarkSeqNo
- The sequence number of the bookmark entry to discard.AMPSException
- If an error occurs while discarding from the bookmark
store.public void discard(Message message) throws AMPSException
discard
in interface BookmarkStore
message
- The message containing information about the bookmark to
discard.AMPSException
- If an error occurs while discarding from the bookmark
store.public Field getMostRecent(Field subId) throws AMPSException
getMostRecent
in interface BookmarkStore
subId
- The identifier of the subscription for which to retrieve the
most recent bookmark.AMPSException
- If an error occurs while retrieving the most recent
bookmark or if the store is not open.public Field getMostRecent(Field subId, boolean useList) throws AMPSException
getMostRecent
in interface BookmarkStore
subId
- The identifier of the subscription for which to retrieve the
most recent bookmark.useList
- A flag indicating whether to retrieve the most recent bookmark
list or a single bookmark.AMPSException
- If an error occurs while retrieving the most recent
bookmark or if the store is not open.public boolean isDiscarded(Message message) throws AMPSException
isDiscarded
in interface BookmarkStore
message
- The message containing the bookmark to check for discarding.AMPSException
- If an error occurs while checking if the bookmark is
discarded or if the store is not open.@Deprecated public void persisted(Field subId, long bookmark) throws AMPSException
persisted(Field, BookmarkField)
instead.persisted(Field, BookmarkField)
instead.persisted
in interface BookmarkStore
subId
- The identifier of the subscription for which to set the
persisted bookmark.bookmark
- The persisted bookmark value to set.AMPSException
- If an error occurs while setting the persisted bookmark
or if the store is not open.public void persisted(Field subId, BookmarkField bookmark) throws AMPSException
persisted
in interface BookmarkStore
subId
- The identifier of the subscription for which to set the
persisted bookmark.bookmark
- The persisted bookmark value to set.AMPSException
- If an error occurs while setting the persisted bookmark
or if the store is not open.public long getOldestBookmarkSeq(Field subId) throws AMPSException
getOldestBookmarkSeq
in interface BookmarkStore
subId
- The identifier of the subscription for which to retrieve the
oldest bookmark sequence number.AMPSException
- If an error occurs while retrieving the oldest bookmark
sequence number or if the store is not open.public void setResizeHandler(BookmarkStoreResizeHandler handler)
setResizeHandler
in interface BookmarkStore
handler
- The handler to set for resize events.protected LoggedBookmarkStore.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() throws AMPSException
AMPSException
- If an error occurs during the purging process.public void purge(Field subId_) throws AMPSException
purge
in interface BookmarkStore
subId_
- The subscription ID for which to remove entries from the store.AMPSException
- If an error occurs during the purging process.public void _purge(Field subId_) throws AMPSException
subId_
- The subscription ID for which to remove entries from the store.AMPSException
- If an error occurs during the purging process.public void setRecoveryPointFactory(RecoveryPointFactory factory_) throws AMPSException
factory_
- The new RecoveryPointFactoryAMPSException
- If one of factory or adapter is null.public void close() throws AMPSException
close
in interface java.lang.AutoCloseable
StoreException
- If there is an error closing the file backing in the
store, or the store already closed.AMPSException
public void setServerVersion(int version)
setServerVersion
in interface BookmarkStore
version
- An AMPS server version integer of the form 03080000 for
version 3.8.0.0.public int getServerVersion()
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.