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