net.spy.pool
Class PoolAble

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.pool.PoolAble
Direct Known Subclasses:
JDBCPoolAble, SNPPPoolAble

public abstract class PoolAble
extends SpyObject

PoolAble is the object container that is used to store objects in the pool.

The system property net.spy.pool.debug can be set to a file where the debugging output will go.


Field Summary
static int MAY_CLEAN
          Minimum value returned from pruneStatus() if we may clean the object.
static int MUST_CLEAN
          Minimum value returned from pruneStatus() if we must clean the object.
 
Constructor Summary
PoolAble(java.lang.Object o, int h)
          Get a PoolAble representation for an object.
PoolAble(java.lang.Object o, long a, int h)
          Get a PoolAble representation for an object, including a given maximum lifetime the object can have.
 
Method Summary
 void activate()
          Activate this PoolAble object.
 void checkIn()
          Check the object back in.
 void checkOut()
          Check the object out.
protected  void debug(java.lang.String msg)
          Debugging info.
 void discard()
          Discard the object.
 java.lang.Object getObject()
          Get the object we're pooling.
 int getObjectID()
          Get the object ID of this object.
protected  java.lang.Object intGetObject()
          Internal version of getObject().
 boolean isAlive()
          Find out of the PoolAble represents a usable object.
 boolean isAvailable()
          Find out if the object is available for a requestor
 boolean isCheckedOut()
          Find out if the object is checked out.
 int pruneStatus()
          Find out if an object is prunable
protected  void setAvailable()
          Mark this object as available.
 void setMaxAge(long to)
          Set the maximum age of this PoolAble.
 void setObjectID(int id)
          Set the internal object ID.
 void setPoolName(java.lang.String to)
          Set the pool name this thing sits in.
protected  void setUnavailable()
          Mark this object as unavailable.
 java.lang.String toString()
          Return a string representation of this object.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAY_CLEAN

public static final int MAY_CLEAN
Minimum value returned from pruneStatus() if we may clean the object.

See Also:
Constant Field Values

MUST_CLEAN

public static final int MUST_CLEAN
Minimum value returned from pruneStatus() if we must clean the object.

See Also:
Constant Field Values
Constructor Detail

PoolAble

public PoolAble(java.lang.Object o,
                int h)
Get a PoolAble representation for an object.


PoolAble

public PoolAble(java.lang.Object o,
                long a,
                int h)
Get a PoolAble representation for an object, including a given maximum lifetime the object can have.

Parameters:
maxAge - the amount of time, in milliseconds, that the object will be valid. Objects will not be checked out if they are older than their maximum lifetime.
Method Detail

setMaxAge

public void setMaxAge(long to)
Set the maximum age of this PoolAble.


isAlive

public boolean isAlive()
Find out of the PoolAble represents a usable object. Objects extending PoolAble should implement isAlive() methods for their particular needs.

Objects implementing isAlive() should turn off object availability if they determine the object no longer isAlive().

Returns:
true if the object will be usable

getObject

public java.lang.Object getObject()
                           throws PoolException
Get the object we're pooling.

Returns:
the object.
Throws:
PoolException - if something bad happens (i.e. the object is not checked out)

intGetObject

protected java.lang.Object intGetObject()
Internal version of getObject(). Returns regardless of whether the object has been checked out.


setObjectID

public void setObjectID(int id)
Set the internal object ID. This probably shouldn't be called outside of the pool container.

Parameters:
id - ObjectId of this object.

setPoolName

public void setPoolName(java.lang.String to)
Set the pool name this thing sits in. This is for debugging, but it's useful information, nonetheless.


getObjectID

public int getObjectID()
Get the object ID of this object.

Returns:
the object ID

activate

public void activate()
Activate this PoolAble object.


checkIn

public void checkIn()
Check the object back in. The PoolAble will not be usable again until it's checked back out from the pooler.

checkIn also does some checks such as making sure the item is not too old, and that it is still alive.


setAvailable

protected void setAvailable()
Mark this object as available.


setUnavailable

protected void setUnavailable()
Mark this object as unavailable.


checkOut

public void checkOut()
Check the object out. Called from the PoolContainer


isCheckedOut

public boolean isCheckedOut()
Find out if the object is checked out.


isAvailable

public boolean isAvailable()
Find out if the object is available for a requestor


pruneStatus

public int pruneStatus()
Find out if an object is prunable

Returns:
0 if not available, 1 if we may clean, greater than one if we must clean.

discard

public void discard()
Discard the object. Anything that extends from this class needs to call super.discard() when it's done.


debug

protected final void debug(java.lang.String msg)
Debugging info.


toString

public java.lang.String toString()
Return a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.


Copyright © 1995-2005 SPY Internetworking. All Rights Reserved.