2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.common.workflow.service;
23 import java.util.concurrent.Delayed;
24 import java.util.concurrent.TimeUnit;
26 import org.jboss.resteasy.spi.AsynchronousResponse;
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;
35 private final AsynchronousResponse asynchronousResponse;
36 private final long startTime;
37 private final long timeout;
39 public WorkflowContext(String processKey, String requestId,
40 AsynchronousResponse asynchronousResponse, long timeout) {
41 this.processKey = processKey;
42 this.requestId = requestId;
43 this.asynchronousResponse = asynchronousResponse;
44 this.timeout = timeout;
45 this.startTime = System.currentTimeMillis();
48 public String getRequestId() {
52 public String getProcessKey() {
56 public AsynchronousResponse getAsynchronousResponse() {
57 return asynchronousResponse;
60 public long getTimeout() {
64 public long getStartTime() {
69 * Required implementation by Delay queue
70 * Returns the elapsed time for this context
73 public long getDelay(TimeUnit unit) {
74 // 0 or negative means this object is considered to be expired
75 return unit.convert(startTime + timeout - System.currentTimeMillis(), unit);
79 * Required implementation by Delay queue
80 * Compares the object to determine whether the object can be marked as expired
83 public int compareTo(Delayed object) {
84 WorkflowContext that = (WorkflowContext) object;
85 long thisEndTime = startTime + timeout;
86 long thatEndTime = that.startTime + that.timeout;
88 if (thisEndTime < thatEndTime) {
90 } else if (thisEndTime > thatEndTime) {