public class SOWRecoveryPointAdapter extends java.lang.Object implements RecoveryPointAdapter
An implementation of the recovery point adapter interface that uses an AMPS SOW (State of the World) topic as an external store to persist recovery point state for bookmark replay subscriptions.
This class allows you to use an AMPS SOW topic as a backup bookmark store for bookmark replay. It serves as a recovery point adapter that serializes and deserializes recovery points to and from the SOW topic. To use this class effectively, you will need to configure your AMPS server to include a SOW topic that matches the expected format used by this adapter.
Server-side configuration for AMPS SOW topics is required for successful integration with this class. Ensure that your AMPS server is properly configured to handle SOW topics, including topics matching the expected format used for recovery points. See the 'Java Developer Guide' for the suggested configuration.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
_bookmarkField |
protected java.util.regex.Pattern |
_bookmarkPattern
Regular expression pattern to pull the bookmark string from subscription
state saved in the AMPS SOW.
|
protected Client |
_client |
protected java.lang.String |
_clientNameField |
protected boolean |
_closeClient |
protected Command |
_cmd |
protected RecoveryPoint |
_current |
protected java.beans.ExceptionListener |
_exceptionListener |
protected java.lang.String |
_initStr |
protected java.util.concurrent.ConcurrentHashMap<Field,BookmarkField> |
_lastValue
A concurrent hash map of subscription id's (known to this store)
mapped to the subscription's most-recent-for-recovery value
that was last persisted to the SOW.
|
protected boolean |
_recovering |
protected Field |
_serializeField |
protected int |
_serializeStart |
protected MessageStream |
_stream |
protected java.lang.String |
_subIdField |
protected java.util.regex.Pattern |
_subIdPattern
Regular expression pattern to pull the subscription id from subscription
state saved in the AMPS SOW.
|
protected boolean |
_throwNotListen |
protected long |
_timeoutMillis |
protected java.lang.String |
_topic |
protected java.lang.String |
_trackedName |
protected boolean |
_useTimestamp |
protected Field |
EPOCH_FIELD |
protected static int |
JSON_END |
protected static int |
JSON_INIT_LEN |
protected static int |
JSON_LEN |
protected static int |
JSON_START |
protected static int |
SUBID_LEN |
Constructor and Description |
---|
SOWRecoveryPointAdapter(Client client,
java.lang.String trackedClientName,
boolean closeClient,
boolean useTimestamp,
boolean throwExceptions)
A recovery point adapter implementation that uses an AMPS SOW topic
as an external store to persist recovery point state for bookmark
replay subscriptions.
|
SOWRecoveryPointAdapter(Client client,
java.lang.String trackedClientName,
boolean closeClient,
boolean useTimestamp,
boolean throwExceptions,
long timeoutMillis,
java.lang.String topic,
java.lang.String clientNameField,
java.lang.String subIdField,
java.lang.String bookmarkField)
A recovery point adapter implementation that uses an AMPS SOW topic
as an external store to persist recovery point state for bookmark
replay subscriptions.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this adapter making sure all updates are at the server and close
the internal client if set up to do so.
|
protected boolean |
deserialize(Message m)
Deserializes a JSON string into a
RecoveryPoint instance for use
by next() during bookmark store creation/initialization. |
boolean |
hasNext()
Implements
Iterator.hasNext() . |
protected void |
initSerialization()
Initializes the serialization buffer and an initial string for serialization
purposes.
|
java.util.Iterator<RecoveryPoint> |
iterator()
Implements
Iterable.iterator() to return this instance. |
RecoveryPoint |
next()
Implements
Iterator.next() for a message stream. |
void |
purge()
Purge all recovery information stored in the SOW.
|
void |
purge(Field subId)
Purge all recovery information stored in the SOW.
|
void |
remove()
Operation not supported.
|
protected void |
runQuery()
Set up the MessageStream for data recovery.
|
protected boolean |
serialize(RecoveryPoint recoveryPoint)
Serializes a
RecoveryPoint to JSON in the internal buffer for
publishing to a JSON SOW topic. |
void |
setExceptionListener(java.beans.ExceptionListener exceptionListener)
Sets the
ExceptionListener instance used for
communicating absorbed exceptions. |
void |
update(RecoveryPoint recoveryPoint)
Sends an update to the underlying SOW.
|
protected java.lang.String _trackedName
protected java.lang.String _topic
protected java.lang.String _clientNameField
protected java.lang.String _subIdField
protected java.lang.String _bookmarkField
protected Client _client
protected java.beans.ExceptionListener _exceptionListener
protected Field _serializeField
protected long _timeoutMillis
protected boolean _closeClient
protected boolean _useTimestamp
protected boolean _throwNotListen
protected Command _cmd
protected MessageStream _stream
protected boolean _recovering
protected static final int JSON_START
protected static final int JSON_END
protected static final int JSON_LEN
protected static final int SUBID_LEN
protected static final int JSON_INIT_LEN
protected java.lang.String _initStr
protected int _serializeStart
protected RecoveryPoint _current
protected Field EPOCH_FIELD
protected java.util.regex.Pattern _bookmarkPattern
protected java.util.regex.Pattern _subIdPattern
protected final java.util.concurrent.ConcurrentHashMap<Field,BookmarkField> _lastValue
public SOWRecoveryPointAdapter(Client client, java.lang.String trackedClientName, boolean closeClient, boolean useTimestamp, boolean throwExceptions) throws StoreException
client
- The internal AMPS client instance used to write
bookmark state to the AMPS SOW. This MUST NOT be the
client whose registered bookmark store is associated
with this recovery point adapter. In other words, it
must not be the AMPS client used to place the
bookmark replay subscriptions whose recovery state
is being persisted by this adapter.trackedClientName
- The unique name of the subscriber AMPS client
we're tracking bookmark recovery state for. If your
client names change with each run, this should be a
unique session name that is stable across
application restarts. For example, such a name
could be formed by concatenating an application name
with a logical functional area (e.g.
"MyApp_OrderReplay"). This name will be used as a
key in the SOW for tracking the subscriber client's
bookmark state. For guidance on choosing stable
unique AMPS client names or session names for use
with this adapter, please see our support FAQ
article entitled Unique Client Naming and AMPS.closeClient
- Indicates whether this adapter instance should close
its internal AMPS client when this adapter is
closed. Defaults to true. If this flag is true, this
adapter considers the internal client passed to it
during construction as being owned by this adapter,
such that its life-cycle should end when this
adapter is closed. If false, this adapter will
consider it the responsibility of the caller to
close the internal client after this adapter is
closed, allowing that client to be shared, possibly
among multiple adapters (keeping in mind potential
performance impacts of multiple threads publishing
using the same AMPS client instance).useTimestamp
- Indicates if the last updated timestamp of each
entries should be included in the RecoveryPoint.
This is similar to useLastModifiedTime in
LoggedBookmarkStore
.throwExceptions
- Indicates whether exceptions should be thrown
to the caller (usually the bookmark store), or
should instead be delivered to this adapter's
registered exception listener callback. This flag
lets the user decide their error handling strategy
for recovery state write failures. The default is
false, meaning the exception is absorbed, and sent
to the exception listener (if any). A value of true
means errors in the update() method throw
exceptions. NOTE: Since this adapter implementation
publishes to an AMPS SOW and most AMPS publishing
failures have asynchronous notification, users
should consider registering a
FailedWriteHandler
and publish store on the
internal client passed above.StoreException
- If client name and trackedClientName are the same.SOWRecoveryPointAdapter(Client, String, boolean, boolean, boolean,
long, String, String, String, String)
public SOWRecoveryPointAdapter(Client client, java.lang.String trackedClientName, boolean closeClient, boolean useTimestamp, boolean throwExceptions, long timeoutMillis, java.lang.String topic, java.lang.String clientNameField, java.lang.String subIdField, java.lang.String bookmarkField) throws StoreException
client
- The internal AMPS client instance used to write
bookmark state to the AMPS SOW. This MUST NOT be the
client whose registered bookmark store is associated
with this recovery point adapter. In other words, it
must not be the AMPS client used to place the
bookmark replay subscriptions whose recovery state
is being persisted by this adapter.trackedClientName
- The unique name of the subscriber AMPS client
we're tracking bookmark recovery state for. If your
client names change with each run, this should be a
unique session name that is stable across
application restarts. For example such a name could
be formed by concatenating an application name with
a logical functional area (e.g.
"MyApp_OrderReplay"). This name will be used as a
key in the SOW for tracking the subscriber client's
bookmark state. For guidance on choosing stable
unique AMPS client names or session names for use
with this adapter, please see our support FAQ
article entitled Unique Client Naming and AMPS.closeClient
- Indicates whether this adapter instance should close
its internal AMPS client when this adapter is
closed. Defaults to true. If this flag is true, this
adapter considers the internal client passed to it
during construction as being owned by this adapter,
such that its life-cycle should end when this
adapter is closed. If false, this adapter will
consider it the responsibility of the caller to
close the internal client after this adapter is
closed, allowing that client to be shared, possibly
among multiple adapters (keeping in mind potential
performance impacts of multiple threads publishing
using the same AMPS client instance).useTimestamp
- Indicates if the last updated timestamp of each
entries should be included in the RecoveryPoint.
This is similar to useLastModifiedTime in
LoggedBookmarkStore
.throwExceptions
- Indicates whether exceptions should be thrown
to the caller (usually the bookmark store), or
should instead be delivered to this adapter's
registered exception listener callback. This flag
lets the user decide their error handling strategy
for recovery state write failures. The default is
false, meaning the exception is absorbed, and sent
to the exception listener (if any). A value of true
means errors in the update() method throw
exceptions. NOTE: Since this adapter implementation
publishes to an AMPS SOW and most AMPS publishing
failures have asynchronous notification, users
should consider registering a
FailedWriteHandler
and publish store on the
internal client passed above.timeoutMillis
- The number of milliseconds to wait for the initial
sow query to complete and for publish_flush to
complete during close()
. The default value
is 0, which means no timeout.topic
- The AMPS SOW topic configured to persist bookmark
recovery state for this adapter. Usually defaults to
"/ADMIN/bookmark_store", but this allows users to
customize their usage for non-default SOW configs.
NOTE: The message type of this topic in the
AMPS config must be "json" unless overriding the
operation of this adapter in a subclass.clientNameField
- The name of the SOW topic field we use for
persisting the tracked client name or session name.
Usually just "clientName", but this allows users to
customize their usage for non-default SOW configs.
NOTE: This field must be one of two key fields
configured on the SOW topic.subIdField
- The name of the SOW topic field we use for
persisting the subscription id. Usually just
"subId", but this allows users to customize their
usage for non-default SOW configs. NOTE: This
field must be one of two key fields configured on
the SOW topic.bookmarkField
- The name of the SOW topic field we use for
persisting the bookmark. Usually just "bookmark",
but this allows users to customize their usage for
non-default SOW configs.StoreException
- If client name and trackedClientName are the same.public void setExceptionListener(java.beans.ExceptionListener exceptionListener)
ExceptionListener
instance used for
communicating absorbed exceptions.exceptionListener
- The exception listener instance to invoke for
internal exceptions.public void update(RecoveryPoint recoveryPoint) throws java.lang.Exception
update
in interface RecoveryPointAdapter
recoveryPoint
- The recovery state to persist in the SOW.java.lang.Exception
- StoreException wrapper of exception thrown while
clearing the SOW of recovery information.public void purge() throws StoreException
purge
in interface RecoveryPointAdapter
StoreException
- Wrapper of exception thrown while clearing the
SOW of recovery information.BookmarkStore.purge()
public void purge(Field subId) throws StoreException
purge
in interface RecoveryPointAdapter
subId
- The subId of the subscription to remove.StoreException
- Wrapper of exception thrown while clearing the
SOW of recovery information.BookmarkStore.purge(com.crankuptheamps.client.fields.Field)
public void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
protected void runQuery()
public boolean hasNext()
Iterator.hasNext()
.hasNext
in interface java.util.Iterator<RecoveryPoint>
public RecoveryPoint next()
Iterator.next()
for a message stream.next
in interface java.util.Iterator<RecoveryPoint>
public void remove()
Iterator.remove()
to throw
UnsupportedOperationException.remove
in interface java.util.Iterator<RecoveryPoint>
public java.util.Iterator<RecoveryPoint> iterator()
Iterable.iterator()
to return this instance.iterator
in interface java.lang.Iterable<RecoveryPoint>
protected boolean serialize(RecoveryPoint recoveryPoint) throws java.lang.Exception
RecoveryPoint
to JSON in the internal buffer for
publishing to a JSON SOW topic. Used by the
update(RecoveryPoint)
method.
This method provides an override point where a recovery point can be
serialized another message type into the buffer.recoveryPoint
- The recovery point to serialize.java.lang.Exception
- If an error occurs during serialization.protected boolean deserialize(Message m) throws java.lang.Exception
RecoveryPoint
instance for use
by next()
during bookmark store creation/initialization.
This method provides an override point where another message type
can be deserialized into a RecoveryPoint
. This method is only
called via recover() during bookmark store creation/initialization by a
single thread.m
- The `sow` Message from the server to deserialize.java.lang.Exception
- If an error occurs during deserialization.protected void initSerialization() throws java.lang.Exception
java.lang.Exception
- if there is an issue during initialization.