01: package net.xoetrope.optional.pool;
02:
03: /**
04: * <p>Provides some basic object management facilities for Pooled Objects</p>
05: * <p>Copyright (c) Xoetrope Ltd. 2001-2003</p>
06: * $Revision: 1.1 $
07: */
08: public abstract class PoolObject {
09: /**
10: * A flag marking the use status of this object
11: */
12: private boolean inUse;
13:
14: /**
15: * The last used timestamp, set at the time of leasing
16: */
17: private long timeStamp;
18:
19: /**
20: * Mark an object as being in use
21: * @return
22: */
23: public synchronized boolean lease() {
24: if (inUse)
25: return false;
26: else {
27: inUse = true;
28: timeStamp = System.currentTimeMillis();
29: return true;
30: }
31: }
32:
33: /**
34: * Check to see if the object is still valid
35: * @return
36: */
37: public abstract boolean validate();
38:
39: /**
40: * Is the object in use?
41: * @return true if the object is in use
42: */
43: public boolean getInUse() {
44: return inUse;
45: }
46:
47: /**
48: * Gets the last use time of the object
49: * @return the time in milliseconds
50: */
51: public long getLastUse() {
52: return timeStamp;
53: }
54:
55: /**
56: * Close the object and return to the pool.
57: * @throws Exception
58: */
59: public abstract void close() throws Exception;
60:
61: /**
62: * Expire the object's lease
63: */
64: public void expireLease() {
65: inUse = false;
66: }
67: }
|