01: package com.xoetrope.task;
02:
03: /**
04: * <p>A object that calls a method/function after a specified time. The object can be used only once.</p>
05: *
06: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
07: * the GNU Public License (GPL), please see license.txt for more details. If
08: * you make commercial use of this software you must purchase a commercial
09: * license from Xoetrope.</p>
10: * <p> $Revision: 1.4 $</p>
11: */
12: public class XCallback extends Thread {
13: private long sleepTime;
14: private XCallbackListener target;
15:
16: /**
17: * Constructs a new object that makes the method call once.
18: * @param obj The target object/method to invoke
19: * @param sleepFor The time to sleep prior to make the callback
20: */
21: public XCallback(XCallbackListener obj, long sleepFor) {
22: target = obj;
23: sleepTime = sleepFor;
24: start();
25: }
26:
27: /**
28: * Do the callback's work. Calls the XCallbackListener's callback method
29: * once the thread wakes up from its sleep time.
30: */
31: public void run() {
32: try {
33: sleep(sleepTime);
34: } catch (Exception e) {
35: }
36:
37: target.callback();
38: }
39: }
|