com.jpeterson.pool
Class SocketObjectPool

java.lang.Object
  |
  +--com.jpeterson.pool.ObjectPool
        |
        +--com.jpeterson.pool.SocketObjectPool
Direct Known Subclasses:
X10ServerSocketObjectPool

public class SocketObjectPool
extends ObjectPool

A pool of Socket's.


Field Summary
protected  java.net.InetAddress address
          Address of sockets in the pool.
protected  int port
          Port of sockets in the pool.
 
Fields inherited from class com.jpeterson.pool.ObjectPool
DEFAULT_EXPIRATION, locked, unlocked
 
Constructor Summary
SocketObjectPool(java.net.InetAddress address, int port)
          Create an object pool of Socket's for the specified address and port.
SocketObjectPool(java.net.InetAddress address, int port, long expiration)
          Create an object pool of Socket's for the specified address and port with the specified expiration.
SocketObjectPool(java.lang.String hostname, int port)
          Create an object pool of Socket's for the specified hostname and port.
SocketObjectPool(java.lang.String hostname, int port, long expiration)
          Create an object pool of Socket's for the specified hostname and port with the specified expiration.
 
Method Summary
 java.lang.Object borrowObject()
          Borrow an object from the pool.
protected  java.lang.Object create()
          Create a new instance of a Socket.
protected  void expire(java.lang.Object o)
          Clean up resources on this expired object.
 void returnBrokenObject(java.lang.Object o)
          Return a broken borrowed object borrowed from a call to borrowObject.
 void returnObject(java.lang.Object o)
          Return a borrowed object borrowed from a call to borrowObject.
protected  boolean validate(java.lang.Object o)
          Always returns true.
 
Methods inherited from class com.jpeterson.pool.ObjectPool
broken, checkIn, checkOut, getExpiration, setExpiration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

address

protected java.net.InetAddress address
Address of sockets in the pool.

port

protected int port
Port of sockets in the pool.
Constructor Detail

SocketObjectPool

public SocketObjectPool(java.lang.String hostname,
                        int port)
                 throws java.net.UnknownHostException
Create an object pool of Socket's for the specified hostname and port. Expiration is set to the default value.
Parameters:
hostname - Host name or IP address for sockets in the pool.
port - Port for sockets in the pool.

SocketObjectPool

public SocketObjectPool(java.lang.String hostname,
                        int port,
                        long expiration)
                 throws java.net.UnknownHostException
Create an object pool of Socket's for the specified hostname and port with the specified expiration.
Parameters:
hostname - Host name or IP address for sockets in the pool.
port - Port for sockets in the pool.
expiration - Expiration in milliseconds for sockets in the pool.

SocketObjectPool

public SocketObjectPool(java.net.InetAddress address,
                        int port)
Create an object pool of Socket's for the specified address and port. Expiration is set to the default value.
Parameters:
address - Address for sockets in the pool.
port - Port for sockets in the pool.

SocketObjectPool

public SocketObjectPool(java.net.InetAddress address,
                        int port,
                        long expiration)
Create an object pool of Socket's for the specified address and port with the specified expiration.
Parameters:
address - Address for sockets in the pool.
port - Port for sockets in the pool.
expiration - Expiration in milliseconds for sockets in the pool.
Method Detail

create

protected java.lang.Object create()
Create a new instance of a Socket.
Overrides:
create in class ObjectPool
Returns:
A new instance of a Socket or null if unable to create one.

validate

protected boolean validate(java.lang.Object o)
Always returns true.
Overrides:
validate in class ObjectPool
Returns:
Always returns true.

expire

protected void expire(java.lang.Object o)
Clean up resources on this expired object.
Overrides:
expire in class ObjectPool
Parameters:
o - Object that has expired.

borrowObject

public java.lang.Object borrowObject()
Borrow an object from the pool. You are obliged to replace the borrowed object once you are through with it via a call to either returnObject or returnBrokenObject.
Returns:
Available object or null if no objects are available.
See Also:
returnObject, returnBrokenObject

returnObject

public void returnObject(java.lang.Object o)
Return a borrowed object borrowed from a call to borrowObject.
Parameters:
o - Borrowed object being returned.
See Also:
borrowObject, returnBrokenObject

returnBrokenObject

public void returnBrokenObject(java.lang.Object o)
Return a broken borrowed object borrowed from a call to borrowObject.
Parameters:
o - Broken borrowed object being returned.
See Also:
borrowObject, returnObject