Package com.kheops.util
Class KSocketConnectionPool
- All Implemented Interfaces:
KSchedulerClient
This class encapsulates a pool of socket connections
- See Also:
-
Field Summary
Fields inherited from class com.kheops.util.KObjectPool
cleanupPeriod, recyclePeriod, shrinkTime, TIMEOUT_UNDEFINED, TIMEOUT_UNLIMITED
-
Constructor Summary
ConstructorDescriptionKSocketConnectionPool
(String host, int port, int initialSize) Constructs the KSocketConnectionPool instance with the specified parameters -
Method Summary
Modifier and TypeMethodDescriptionGets a free socket from the connection poolborrowSocket
(long timeout, TimeUnit unit) Gets a free socket from the connection poolcreate()
Creates an new socket with the appropriate port and hostvoid
Closes the specified socketvoid
This method will free up the specified Socket instance to be used laterboolean
This method checks if the object qualifies for connectionsMethods inherited from class com.kheops.util.KObjectPool
apply, checkIn, checkOut, checkOut, close, createUnlockedInstance, getDefaultTimeout, getId, getMonitoringInfo, getPoolMaximumSize, getPoolSize, getPoolUsageCount, getPoolUsagePeak, getSystemDefaultTimeout, initialize, initialize, initialize, internalErrorOccurred, reset, resourceAdded, schCallback, setDefaultTimeout, setPoolMaximumSize, setPoolMinimumSize
-
Constructor Details
-
KSocketConnectionPool
Constructs the KSocketConnectionPool instance with the specified parameters- Parameters:
host
- the corresponding hostport
- the port used for connectioninitialSize
- the initial number of connections- Throws:
Exception
-
-
Method Details
-
create
Creates an new socket with the appropriate port and host- Specified by:
create
in classKObjectPool<Socket>
- Returns:
- the new Socket instance
- Throws:
IOException
-
validate
This method checks if the object qualifies for connections- Specified by:
validate
in classKObjectPool<Socket>
- Parameters:
socket
- the socket instance- Returns:
- true if the object qualifies for connection false otherwise
-
expire
Closes the specified socket- Specified by:
expire
in classKObjectPool<Socket>
- Parameters:
socket
- the socket instance
-
borrowSocket
Gets a free socket from the connection pool- Returns:
- a free Socket instance from the connection pool
- Throws:
IOException
-
borrowSocket
Gets a free socket from the connection pool- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- a free Socket instance from the connection pool
- Throws:
IOException
-
returnSocket
This method will free up the specified Socket instance to be used later- Parameters:
s
- the corresponding Socket instance to be freed
-