Package org.jboss.jbossts.star.client
Class SRAClient
- java.lang.Object
-
- org.jboss.jbossts.star.client.SRAClient
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SRAClientAPI
@RequestScoped public class SRAClient extends java.lang.Object implements SRAClientAPI, java.io.Closeable
A utility class for controlling the lifecycle of Long Running Actions (SRAs) but the prefered mechanism is to use the annotation in theorg.jboss.jbossts.star.annotationpackage
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLIENT_ID_PARAM_NAMEstatic java.lang.StringCOMMITstatic java.lang.StringCOORDINATOR_URL_PROPstatic longDEFAULT_TIMEOUT_MILLISstatic java.lang.StringONEPHASECOMMITstatic java.lang.StringPARENT_SRA_PARAM_NAMEstatic java.lang.StringPREPAREstatic java.lang.StringROLLBACKstatic java.lang.StringRTS_HTTP_CONTEXT_HEADERstatic java.lang.StringRTS_HTTP_RECOVERY_HEADERstatic java.lang.StringSTATUSstatic java.lang.StringTIMELIMIT_PARAM_NAMEstatic java.lang.StringTX_COMMITTEDstatic java.lang.StringTX_ROLLBACK_ONLYstatic java.lang.StringTX_ROLLEDBACK
-
Constructor Summary
Constructors Constructor Description SRAClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringcancelSRA(java.net.URL sraId)Attempt to cancel an SRA Trigger the compensation of the SRA.voidclose()java.lang.StringcommitSRA(java.net.URL sraId)Attempt to close an SRA Trigger the successful completion of the SRA.static java.lang.StringencodeURL(java.net.URL sraId, java.lang.String message)java.util.List<SRAInfo>getActiveSRAs()Lookup active SRAsjava.util.List<SRAInfo>getAllSRAs()Returns all SRAs Gets both active and recovering SRAsjava.net.URLgetCurrent()checks whether there is an SRA associated with the calling threadjava.util.List<SRAInfo>getRecoveringSRAs()List recovering Long Running Actions Returns SRAs that are recovering (ie some compensators still need to be ran)java.util.List<java.lang.String>getResponseData(java.net.URL sraId)static java.lang.StringgetSRAId(java.lang.String sraId)java.util.Map<java.lang.String,java.lang.String>getTerminationUris(java.net.URL aaId, java.lang.Class<?> compensatorClass, javax.ws.rs.core.UriInfo uriInfo, boolean validate)java.lang.StringgetUrl()java.lang.BooleanisActiveSRA(java.net.URL sraId)Indicates whether an SRA is activejava.lang.BooleanisCompensatedSRA(java.net.URL sraId)Indicates whether an SRA was compensatedjava.lang.BooleanisCompletedSRA(java.net.URL sraId)Indicates whether an SRA is completevoidjoinSRA(java.net.URL sraId, java.lang.Long timelimit, java.lang.String compensatorUrl)A SRAParticipant can join with the SRA at any time prior to the completion of an activityjava.lang.StringjoinSRA(java.net.URL sraId, java.lang.Long timelimit, java.lang.String compensateUrl, java.lang.String completeUrl, java.lang.String leaveUrl, java.lang.String statusUrl)Similar toSRAClientAPI.joinSRA(URL, Long, String)but the various compensator urls are passed in explicitlyjava.lang.StringjoinSRAWithLinkHeader(java.net.URL sraUrl, java.lang.Long timelimit, java.lang.String linkHeader)voidpostConstruct()voidsetCurrentSRA(java.net.URL coordinatorUrl)Update the clients notion of the current coordinator.static java.net.URLsraToURL(java.lang.String sraId)static java.net.URLsraToURL(java.lang.String sraId, java.lang.String message)java.net.URLstartSRA(java.lang.String clientID, java.lang.Long timeout)java.net.URLstartSRA(java.net.URL parentSRA, java.lang.String clientID, java.lang.Long timeout, java.util.concurrent.TimeUnit unit)static java.lang.StringstripUid(java.net.URL url)java.net.URLtoURL(java.lang.String sraId)
-
-
-
Field Detail
-
RTS_HTTP_CONTEXT_HEADER
public static final java.lang.String RTS_HTTP_CONTEXT_HEADER
- See Also:
- Constant Field Values
-
RTS_HTTP_RECOVERY_HEADER
public static final java.lang.String RTS_HTTP_RECOVERY_HEADER
- See Also:
- Constant Field Values
-
COORDINATOR_URL_PROP
public static final java.lang.String COORDINATOR_URL_PROP
- See Also:
- Constant Field Values
-
COMMIT
public static final java.lang.String COMMIT
- See Also:
- Constant Field Values
-
PREPARE
public static final java.lang.String PREPARE
- See Also:
- Constant Field Values
-
ROLLBACK
public static final java.lang.String ROLLBACK
- See Also:
- Constant Field Values
-
STATUS
public static final java.lang.String STATUS
- See Also:
- Constant Field Values
-
ONEPHASECOMMIT
public static final java.lang.String ONEPHASECOMMIT
- See Also:
- Constant Field Values
-
TIMELIMIT_PARAM_NAME
public static final java.lang.String TIMELIMIT_PARAM_NAME
- See Also:
- Constant Field Values
-
CLIENT_ID_PARAM_NAME
public static final java.lang.String CLIENT_ID_PARAM_NAME
- See Also:
- Constant Field Values
-
PARENT_SRA_PARAM_NAME
public static final java.lang.String PARENT_SRA_PARAM_NAME
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT_MILLIS
public static final long DEFAULT_TIMEOUT_MILLIS
- See Also:
- Constant Field Values
-
TX_COMMITTED
public static final java.lang.String TX_COMMITTED
- See Also:
- Constant Field Values
-
TX_ROLLEDBACK
public static final java.lang.String TX_ROLLEDBACK
- See Also:
- Constant Field Values
-
TX_ROLLBACK_ONLY
public static final java.lang.String TX_ROLLBACK_ONLY
- See Also:
- Constant Field Values
-
-
Method Detail
-
postConstruct
@PostConstruct public void postConstruct()
-
sraToURL
public static java.net.URL sraToURL(java.lang.String sraId)
-
sraToURL
public static java.net.URL sraToURL(java.lang.String sraId, java.lang.String message)
-
encodeURL
public static java.lang.String encodeURL(java.net.URL sraId, java.lang.String message)
-
getSRAId
public static java.lang.String getSRAId(java.lang.String sraId)
-
stripUid
public static java.lang.String stripUid(java.net.URL url)
-
toURL
public java.net.URL toURL(java.lang.String sraId) throws InvalidSRAId- Throws:
InvalidSRAId
-
setCurrentSRA
public void setCurrentSRA(java.net.URL coordinatorUrl)
Update the clients notion of the current coordinator. Warning all further operations will be performed on the SRA manager that created the passed in coordinator.- Parameters:
coordinatorUrl- the full url of an SRA
-
startSRA
public java.net.URL startSRA(java.lang.String clientID, java.lang.Long timeout) throws GenericSRAException- Throws:
GenericSRAException
-
startSRA
public java.net.URL startSRA(java.net.URL parentSRA, java.lang.String clientID, java.lang.Long timeout, java.util.concurrent.TimeUnit unit) throws GenericSRAException- Specified by:
startSRAin interfaceSRAClientAPI- Parameters:
parentSRA- the parent SRA if this new SRA is nestedclientID- Each client is expected to have a unique identity (which can be a URL). (optional)timeout- Specifies the maximum time in seconds that the SRA will exist for. If the SRA is terminated because of a timeout, the SRA URL is deleted. All further invocations on the URL will return 404. The invoker can assume this was equivalent to a compensate operation. (optional, default to 0)- Returns:
- the id of the new SRA
- Throws:
GenericSRAException
-
cancelSRA
public java.lang.String cancelSRA(java.net.URL sraId) throws GenericSRAExceptionDescription copied from interface:SRAClientAPIAttempt to cancel an SRA Trigger the compensation of the SRA. All compensators will be triggered by the coordinator (ie the compensate message will be sent to each compensators). Upon termination, the URL is implicitly deleted. The invoker cannot know for sure whether the sra completed or compensated without enlisting a io.narayana.sra.- Specified by:
cancelSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)- Returns:
- compensator sepcific data provided by the application for nested SRA the API implementation will combine compensator data into a JSON encoded array. This means that compensators MUST not return any data that starts with the JSON array start token (ie a '[' character)
- Throws:
GenericSRAException- Comms error
-
commitSRA
public java.lang.String commitSRA(java.net.URL sraId) throws GenericSRAExceptionDescription copied from interface:SRAClientAPIAttempt to close an SRA Trigger the successful completion of the SRA. All compensators will be dropped by the coordinator. The complete message will be sent to the compensators. Upon termination, the URL is implicitly deleted. The invoker cannot know for sure whether the sra completed or compensated without enlisting a io.narayana.sra.- Specified by:
commitSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)- Returns:
- compensator sepcific data provided by the application for nested SRA the API implementation will combine compensator data into a JSON encoded array. This means that compensators MUST not return any data that starts with the JSON array start token (ie a '[' character)
- Throws:
GenericSRAException- Comms error
-
joinSRAWithLinkHeader
public java.lang.String joinSRAWithLinkHeader(java.net.URL sraUrl, java.lang.Long timelimit, java.lang.String linkHeader) throws GenericSRAException- Parameters:
sraUrl- the URL of the SRA to jointimelimit- how long the io.narayana.sra is prepared to wait for SRA completionlinkHeader- io.narayana.sra protocol URLs in link header format (RFC 5988)- Returns:
- a recovery URL for this enlistment
- Throws:
GenericSRAException- if the SRA coordinator failed to enlist the io.narayana.sra
-
joinSRA
public void joinSRA(java.net.URL sraId, java.lang.Long timelimit, java.lang.String compensatorUrl) throws GenericSRAExceptionDescription copied from interface:SRAClientAPIA SRAParticipant can join with the SRA at any time prior to the completion of an activity- Specified by:
joinSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)timelimit- The time limit (in seconds) that the SRAParticipant can guarantee that it can compensate the work performed by the io.narayana.sra.demo.service. After this time period has elapsed, it may no longer be possible to undo the work within the scope of this (or any enclosing) SRA. It may therefore be necessary for the application or io.narayana.sra.demo.service to start other activities to explicitly try to compensate this work. The application or coordinator may use this information to control the lifecycle of a SRA. (required)compensatorUrl- The resource path that the SRA coordinator will use to drive the compensator. Performing a GET on the compensator URL will return the current status of the compensator, or 404 if the compensator is no longer present. The following types must be returned by Compensators to indicate their current status: - Compensating: the SRAParticipant is currently compensating for the SRA; - Compensated: the SRAParticipant has successfully compensated for the SRA. - FailedToCompensate: the SRAParticipant was not able to compensate for the SRA. It must maintain information about the work it was to compensate until the coordinator sends it a forget message. - Completing: the SRAParticipant is tidying up after being told to complete. - Completed: the coordinator/io.narayana.sra has confirmed. - FailedToComplete: the SRAParticipant was unable to tidy-up. Performing a POST on URL/compensate will cause the compensator to compensate the work that was done within the scope of the SRA. Performing a POST on URL/complete will cause the compensator to tidy up and it can forget this SRA. (optional)- Throws:
GenericSRAException- Comms error
-
joinSRA
public java.lang.String joinSRA(java.net.URL sraId, java.lang.Long timelimit, java.lang.String compensateUrl, java.lang.String completeUrl, java.lang.String leaveUrl, java.lang.String statusUrl) throws GenericSRAExceptionDescription copied from interface:SRAClientAPISimilar toSRAClientAPI.joinSRA(URL, Long, String)but the various compensator urls are passed in explicitly- Specified by:
joinSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)timelimit- The time limit (in seconds) that the SRAParticipant can guarantee that it can compensate the work performed by the io.narayana.sra.demo.servicecompensateUrl- Performing a POST onthis URL will cause the io.narayana.sra to compensate the work that was done within the scope of the SRA.completeUrl- Performing a POST on this URL will cause the io.narayana.sra to tidy up and it can forget this transaction.leaveUrl- Performing a PUT on this URL with cause the compensator to leave the SRAstatusUrl- Performing a GET on this URL will return the status of the compensator {@see joinSRA}- Throws:
GenericSRAException
-
getAllSRAs
public java.util.List<SRAInfo> getAllSRAs() throws GenericSRAException
Description copied from interface:SRAClientAPIReturns all SRAs Gets both active and recovering SRAs- Specified by:
getAllSRAsin interfaceSRAClientAPI- Returns:
- List
- Throws:
GenericSRAException- Comms error
-
getActiveSRAs
public java.util.List<SRAInfo> getActiveSRAs() throws GenericSRAException
Description copied from interface:SRAClientAPILookup active SRAs- Specified by:
getActiveSRAsin interfaceSRAClientAPI- Throws:
GenericSRAException- Comms error
-
getRecoveringSRAs
public java.util.List<SRAInfo> getRecoveringSRAs() throws GenericSRAException
Description copied from interface:SRAClientAPIList recovering Long Running Actions Returns SRAs that are recovering (ie some compensators still need to be ran)- Specified by:
getRecoveringSRAsin interfaceSRAClientAPI- Throws:
GenericSRAException- Comms error
-
isActiveSRA
public java.lang.Boolean isActiveSRA(java.net.URL sraId) throws GenericSRAExceptionDescription copied from interface:SRAClientAPIIndicates whether an SRA is active- Specified by:
isActiveSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)- Throws:
GenericSRAException- Comms error
-
isCompensatedSRA
public java.lang.Boolean isCompensatedSRA(java.net.URL sraId) throws GenericSRAExceptionDescription copied from interface:SRAClientAPIIndicates whether an SRA was compensated- Specified by:
isCompensatedSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)- Throws:
GenericSRAException- Comms error
-
isCompletedSRA
public java.lang.Boolean isCompletedSRA(java.net.URL sraId) throws GenericSRAExceptionDescription copied from interface:SRAClientAPIIndicates whether an SRA is complete- Specified by:
isCompletedSRAin interfaceSRAClientAPI- Parameters:
sraId- The unique identifier of the SRA (required)- Throws:
GenericSRAException- Comms error
-
getTerminationUris
public java.util.Map<java.lang.String,java.lang.String> getTerminationUris(java.net.URL aaId, java.lang.Class<?> compensatorClass, javax.ws.rs.core.UriInfo uriInfo, boolean validate)
-
getUrl
public java.lang.String getUrl()
-
getCurrent
public java.net.URL getCurrent()
Description copied from interface:SRAClientAPIchecks whether there is an SRA associated with the calling thread- Specified by:
getCurrentin interfaceSRAClientAPI- Returns:
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
getResponseData
public java.util.List<java.lang.String> getResponseData(java.net.URL sraId)
- Specified by:
getResponseDatain interfaceSRAClientAPI
-
-