public class SOWRecoveryPointAdapter extends java.lang.Object implements RecoveryPointAdapter
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() |
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 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)
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.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)
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.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