blob: acdca74f384365f1756a4e0524e66fa8a2c1cdd0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/* Copyright (c) 2017 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
package org.onap.multicloud.openstack.vmware;
import java.util.Timer;
import java.util.TimerTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class TimerExtend extends Timer{
public TimerExtend(){
VesTimer.hasStarted = true;
}
public boolean hasRunStarted() {
return VesTimer.hasStarted;
}
}
class TaskTimeout extends TimerTask{
private static JsonStoreMap map;
private final Logger log = LoggerFactory.getLogger(TaskTimeout.class);
@SuppressWarnings("static-access")
public TaskTimeout(JsonStoreMap map) {
TaskTimeout.map = map;
}
public static void run1(){
VesTimer.timeoutCheck = true;
map.deleteAllFromMap();
VesTimer.hasStarted=false;
}
@SuppressWarnings("resource")
@Override
public void run() {
run1();
log.info("In Time out before deleting the entries from Map");
}
}
public class VesTimer {
TimerExtend tt = null;
TaskTimeout timeout = null;
static boolean hasStarted = false;
static boolean timeoutCheck = false;
private JsonStoreMap map;
private final Logger log = LoggerFactory.getLogger(VesTimer.class);
public VesTimer(JsonStoreMap map){
this.map = map;
}
public void startTimer(Integer duration){
tt = new TimerExtend();
timeout= new TaskTimeout(this.map);
log.info("timer started.................");
tt.schedule(timeout, duration);
}
public void stopTimer(){
tt.cancel();
log.info("timer stopped");
}
public boolean isTimerRunning(){
if(VesTimer.hasStarted == true){
log.info("timer started....");
return true;
}
else {
log.info("timer is not running");
return false;
}
}
public String isTimeout(){
if(VesTimer.timeoutCheck){
log.info("expired");
return "expired";
}
return "not expired";
}
}
|