Class KSocketConnectionPool

java.lang.Object
com.kheops.util.KObjectPool<Socket>
com.kheops.util.KSocketConnectionPool
All Implemented Interfaces:
KSchedulerClient

public class KSocketConnectionPool extends KObjectPool<Socket>
This class encapsulates a pool of socket connections
See Also:
  • Constructor Details

    • KSocketConnectionPool

      public KSocketConnectionPool(String host, int port, int initialSize) throws Exception
      Constructs the KSocketConnectionPool instance with the specified parameters
      Parameters:
      host - the corresponding host
      port - the port used for connection
      initialSize - the initial number of connections
      Throws:
      Exception
  • Method Details

    • create

      public Socket create() throws IOException
      Creates an new socket with the appropriate port and host
      Specified by:
      create in class KObjectPool<Socket>
      Returns:
      the new Socket instance
      Throws:
      IOException
    • validate

      public boolean validate(Socket socket)
      This method checks if the object qualifies for connections
      Specified by:
      validate in class KObjectPool<Socket>
      Parameters:
      socket - the socket instance
      Returns:
      true if the object qualifies for connection false otherwise
    • expire

      public void expire(Socket socket)
      Closes the specified socket
      Specified by:
      expire in class KObjectPool<Socket>
      Parameters:
      socket - the socket instance
    • borrowSocket

      public Socket borrowSocket() throws IOException
      Gets a free socket from the connection pool
      Returns:
      a free Socket instance from the connection pool
      Throws:
      IOException
    • borrowSocket

      public Socket borrowSocket(long timeout, TimeUnit unit) throws IOException
      Gets a free socket from the connection pool
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      a free Socket instance from the connection pool
      Throws:
      IOException
    • returnSocket

      public void returnSocket(Socket s)
      This method will free up the specified Socket instance to be used later
      Parameters:
      s - the corresponding Socket instance to be freed