/**
- * @version 1.0
- * Workflow context object used to send timeout response, if workflow instance does not write the response in time
+ * @version 1.0 Workflow context object used to send timeout response, if workflow instance does not write the response
+ * in time
*/
public class WorkflowContext implements Delayed {
- private final String processKey;
- private final String requestId;
-
- private final long startTime;
- private final long timeout;
-
- private final WorkflowResponse workflowResponse;
-
- public WorkflowContext(String processKey, String requestId, long timeout, WorkflowResponse workflowResponse) {
- this.processKey = processKey;
- this.requestId = requestId;
- this.timeout = timeout;
- this.startTime = System.currentTimeMillis();
- this.workflowResponse = workflowResponse;
- }
-
- public String getRequestId() {
- return requestId;
- }
-
- public String getProcessKey() {
- return processKey;
- }
-
-
- public long getTimeout() {
- return timeout;
- }
-
- public long getStartTime() {
- return startTime;
- }
-
- public WorkflowResponse getWorkflowResponse() {
- return workflowResponse;
- }
-
- /**
- * Required implementation by Delay queue
- * Returns the elapsed time for this context
- */
- @Override
- public long getDelay(TimeUnit unit) {
- // 0 or negative means this object is considered to be expired
- return unit.convert(startTime + timeout - System.currentTimeMillis(), unit);
- }
-
- /**
- * Required implementation by Delay queue
- * Compares the object to determine whether the object can be marked as expired
- */
- @Override
- public int compareTo(Delayed object) {
- WorkflowContext that = (WorkflowContext) object;
- long thisEndTime = startTime + timeout;
- long thatEndTime = that.startTime + that.timeout;
-
- if (thisEndTime < thatEndTime) {
- return -1;
- } else if (thisEndTime > thatEndTime) {
- return 1;
- } else {
- return 0;
- }
- }
+ private final String processKey;
+ private final String requestId;
+
+ private final long startTime;
+ private final long timeout;
+
+ private final WorkflowResponse workflowResponse;
+
+ public WorkflowContext(String processKey, String requestId, long timeout, WorkflowResponse workflowResponse) {
+ this.processKey = processKey;
+ this.requestId = requestId;
+ this.timeout = timeout;
+ this.startTime = System.currentTimeMillis();
+ this.workflowResponse = workflowResponse;
+ }
+
+ public String getRequestId() {
+ return requestId;
+ }
+
+ public String getProcessKey() {
+ return processKey;
+ }
+
+
+ public long getTimeout() {
+ return timeout;
+ }
+
+ public long getStartTime() {
+ return startTime;
+ }
+
+ public WorkflowResponse getWorkflowResponse() {
+ return workflowResponse;
+ }
+
+ /**
+ * Required implementation by Delay queue Returns the elapsed time for this context
+ */
+ @Override
+ public long getDelay(TimeUnit unit) {
+ // 0 or negative means this object is considered to be expired
+ return unit.convert(startTime + timeout - System.currentTimeMillis(), unit);
+ }
+
+ /**
+ * Required implementation by Delay queue Compares the object to determine whether the object can be marked as
+ * expired
+ */
+ @Override
+ public int compareTo(Delayed object) {
+ WorkflowContext that = (WorkflowContext) object;
+ long thisEndTime = startTime + timeout;
+ long thatEndTime = that.startTime + that.timeout;
+
+ if (thisEndTime < thatEndTime) {
+ return -1;
+ } else if (thisEndTime > thatEndTime) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
}