01: package com.sun.portal.util;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: /**
07: * author: Noble Paul
08: * Date: May 31, 2004, 3:52:27 PM
09: */
10: public class TaskWrapper implements Runnable {
11: private Runnable task;
12: private long inQueueTime;
13: private long queueTime;
14: // private static List taskWrapperListeners = new ArrayList();
15: // private List taskListeners = new ArrayList();
16: private long taskCreationTime;
17:
18: public long getQueueTime() {
19: return queueTime;
20: }
21:
22: public long getTaskCreationTime() {
23: return taskCreationTime;
24: }
25:
26: public TaskWrapper(Runnable task) {
27: this .task = task;
28: // propogateEvent(taskWrapperListeners,this);
29: // propogateEvent(taskListeners,TaskEvent.TASK_CREATED);
30: }
31:
32: public static TaskWrapper wrap(Runnable task) {
33: if (task instanceof TaskWrapper) {
34: return (TaskWrapper) task;//do not wrap if already wrapped
35: }
36: return new TaskWrapper(task);
37: }
38:
39: public void run() {
40: queueTime = System.currentTimeMillis() - inQueueTime;
41: task.run();
42: }
43:
44: public Runnable getTask() {
45: return task;
46: }
47:
48: public void queued() {
49: inQueueTime = System.currentTimeMillis();
50: taskCreationTime = inQueueTime;
51: // propogateEvent(taskListeners, TaskEvent.TASK_QUEUED);
52: }
53:
54: public void deQueued() {
55: // propogateEvent(taskListeners, TaskEvent.TASK_DEQUEUED);
56: }
57:
58: public static Runnable unwrap(Runnable task) {
59: if (task instanceof TaskWrapper) {
60: return ((TaskWrapper) task).getTask();
61: }
62: return task;
63: }
64:
65: public Runnable unwrap() {
66: return task;
67: }
68:
69: }
|