TimeoutJob.java
2.96 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.osgi.service.event.Event
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.workflow.job;
import com.day.cq.workflow.exec.WorkItem;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.service.event.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TimeoutJob
implements Serializable {
private static final Logger log = LoggerFactory.getLogger(TimeoutJob.class);
private static final long serialVersionUID = 5670996916430565635L;
public static final String TIMEOUT_JOB_TOPIC = "com/day/cq/workflow/timeout/job";
public static final String TIMEOUT_JOB = "com.day.cq.workflow.timeout.job";
protected String itemId;
String handler;
protected long timeStarted = 0;
public TimeoutJob(WorkItem item, String handler) {
if (item == null || handler == null) {
throw new IllegalArgumentException("item or handler must not be null.");
}
this.itemId = item.getId();
this.timeStarted = item.getTimeStarted().getTime();
this.handler = handler;
}
public String getWorkItemId() {
return this.itemId;
}
public String getHandler() {
return this.handler;
}
public Event createEvent(boolean executeParallel, long seconds, boolean addOffset) {
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("com.day.cq.workflow.timeout.job", this);
props.put("event.job.parallel", executeParallel);
props.put("event.topic.timed", "org/apache/sling/event/job");
props.put("event.job.topic", "com/day/cq/workflow/timeout/job");
props.put("event.job.id", this.itemId + "_" + this.timeStarted);
Date date = this.calculateDate(seconds, addOffset);
props.put("event.timed.date", date);
log.debug("create timeout event {} ", props);
return new Event("org/apache/sling/event/timed", props);
}
public Event cancelEvent(boolean executeParallel) {
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("com.day.cq.workflow.timeout.job", this);
props.put("event.job.parallel", executeParallel);
props.put("event.topic.timed", "org/apache/sling/event/job");
props.put("event.job.topic", "com/day/cq/workflow/timeout/job");
props.put("event.job.id", this.itemId + "_" + this.timeStarted);
log.debug("create timeout cancel event {}", props);
return new Event("org/apache/sling/event/timed", props);
}
private Date calculateDate(long seconds, boolean addOffset) {
Calendar cal = Calendar.getInstance();
long millies = seconds * 1000;
if (addOffset) {
millies += cal.getTimeInMillis();
}
cal.setTimeInMillis(millies);
return cal.getTime();
}
}