01: /*
02: * Timer.java
03: *
04: * $Author: ss150821 $
05: *
06: * $Date: 2005/11/30 11:27:23 $ $Revision: 1.3 $
07: *
08: * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
09: *
10: * Developed by SunPS and SunIR
11: */
12:
13: package com.sun.portal.rproxy.connectionhandler;
14:
15: /**
16: * This is a simple timer implementation that runs in its own thread and calls
17: * the client interface method on timer expiration.
18: *
19: * @author Kevin Hartig
20: */
21:
22: public class Timer extends Thread {
23: long _duration = 0;
24:
25: TimerClient _client = null;
26:
27: boolean _active = false;
28:
29: /**
30: * Constructor for the basic timer.
31: *
32: * @param client
33: * The client object that wishes to be notified of the timer
34: * expiration.
35: * @param duration
36: * time to expiration
37: */
38: public Timer(TimerClient client, long duration) {
39: _client = client;
40: _duration = duration;
41: _active = true;
42: setDaemon(true);
43: start();
44: }
45:
46: /**
47: * The timer count down.
48: */
49: public void run() {
50: if (_active) {
51: try {
52: sleep(_duration);
53: } catch (InterruptedException e) {
54: _active = false;
55: }
56: }
57:
58: _active = false;
59: if (_client != null)
60: _client.timeOut();
61: }
62:
63: /**
64: * Stop the timer thread.
65: */
66: public void stopTimer() {
67: _active = false;
68: interrupt();
69: }
70:
71: /**
72: * Get the timer state.
73: */
74: public boolean isActive() {
75: return _active;
76: }
77:
78: }
|