1 package org.onap.so.bpmn.common.workflow.context;
3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
24 import java.util.concurrent.Delayed;
25 import java.util.concurrent.TimeUnit;
30 * Workflow context object used to send timeout response, if workflow instance does not write the response in time
32 public class WorkflowContext implements Delayed {
33 private final String processKey;
34 private final String requestId;
36 private final long startTime;
37 private final long timeout;
39 private final WorkflowResponse workflowResponse;
41 public WorkflowContext(String processKey, String requestId, long timeout, WorkflowResponse workflowResponse) {
42 this.processKey = processKey;
43 this.requestId = requestId;
44 this.timeout = timeout;
45 this.startTime = System.currentTimeMillis();
46 this.workflowResponse = workflowResponse;
49 public String getRequestId() {
53 public String getProcessKey() {
58 public long getTimeout() {
62 public long getStartTime() {
66 public WorkflowResponse getWorkflowResponse() {
67 return workflowResponse;
71 * Required implementation by Delay queue
72 * Returns the elapsed time for this context
75 public long getDelay(TimeUnit unit) {
76 // 0 or negative means this object is considered to be expired
77 return unit.convert(startTime + timeout - System.currentTimeMillis(), unit);
81 * Required implementation by Delay queue
82 * Compares the object to determine whether the object can be marked as expired
85 public int compareTo(Delayed object) {
86 WorkflowContext that = (WorkflowContext) object;
87 long thisEndTime = startTime + timeout;
88 long thatEndTime = that.startTime + that.timeout;
90 if (thisEndTime < thatEndTime) {
92 } else if (thisEndTime > thatEndTime) {