public class KSocketConnectionPool extends KObjectPool<java.net.Socket>
KObjectPool
,
Socket
cleanupPeriod, recyclePeriod, shrinkTime, TIMEOUT_UNDEFINED, TIMEOUT_UNLIMITED
Constructor and Description |
---|
KSocketConnectionPool(java.lang.String host,
int port,
int initialSize)
Constructs the KSocketConnectionPool instance with the specified parameters
|
Modifier and Type | Method and Description |
---|---|
java.net.Socket |
borrowSocket()
Gets a free socket from the connection pool
|
java.net.Socket |
borrowSocket(long timeout,
java.util.concurrent.TimeUnit unit)
Gets a free socket from the connection pool
|
java.net.Socket |
create()
Creates an new socket with the appropriate port and host
|
void |
expire(java.net.Socket socket)
Closes the specified socket
|
void |
returnSocket(java.net.Socket s)
This method will free up the specified Socket instance to be used later
|
boolean |
validate(java.net.Socket socket)
This method checks if the object qualifies for connections
|
apply, checkIn, checkOut, checkOut, close, createUnlockedInstance, getDefaultTimeout, getId, getMonitoringInfo, getPoolMaximumSize, getPoolSize, getPoolUsageCount, getPoolUsagePeak, getSystemDefaultTimeout, initialize, initialize, initialize, internalErrorOccurred, reset, resourceAdded, schCallback, setDefaultTimeout, setPoolMaximumSize, setPoolMinimumSize
public KSocketConnectionPool(java.lang.String host, int port, int initialSize) throws java.lang.Exception
host
- the corresponding hostport
- the port used for connectioninitialSize
- the initial number of connectionsjava.lang.Exception
public java.net.Socket create() throws java.io.IOException
create
in class KObjectPool<java.net.Socket>
java.io.IOException
public boolean validate(java.net.Socket socket)
validate
in class KObjectPool<java.net.Socket>
socket
- the socket instancepublic void expire(java.net.Socket socket)
expire
in class KObjectPool<java.net.Socket>
socket
- the socket instancepublic java.net.Socket borrowSocket() throws java.io.IOException
java.io.IOException
public java.net.Socket borrowSocket(long timeout, java.util.concurrent.TimeUnit unit) throws java.io.IOException
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentjava.io.IOException
public void returnSocket(java.net.Socket s)
s
- the corresponding Socket instance to be freed