Class SocketFactory

Object
com.tailf.conf.SocketFactory

public class SocketFactory extends Object
Class for creation and control of sockets, towards NCS/Confd This singleton factory class control all socket connections. It is possible to register a socket factory callback. If such a factory is registered all socket connect calls will be dispatched to this callback. The callback is registered with the SocketFactory.registerCallback(...) method. For Confd this is the preferred way. In NCS which connects its control sockets before any package is instantiated there exist instead a system property TAILF_SOCKET_FACTORY_CB which should be set to the callback class e.g like: java -DTAILF_SOCKET_FACTORY_CB=com.example.myfactory ... This class must exist in the classpath so that it can be found by NcsMain.
  • Method Details

    • setHostname

      public static void setHostname(String hostname)
      Set the default hostname for socket connections.
      Parameters:
      hostname -
    • setPort

      public static void setPort(int port)
      Set the default port number for socket connections
      Parameters:
      port -
    • getUnconnectedSocket

      public static Socket getUnconnectedSocket(Object caller) throws IOException, ConfException
      Retrieve an unconnected socket. Such socket can be used when e.g a bind() call is necessary before the connect() is performed. The connect() call is performed by the requestor.
      Parameters:
      caller - The requestor object instance
      Returns:
      An unconnected socket
      Throws:
      IOException
      ConfException
    • getSocket

      public static Socket getSocket(Object caller) throws IOException, ConfException
      Retrieve a socket which is connected to the default host/port.
      Parameters:
      caller - The requestor object instance
      Returns:
      a socket connected to the default host/port.
      Throws:
      IOException
      ConfException
    • getSocket

      public static Socket getSocket(Object caller, Socket s)
      Retrieve a connected socket using a connected socket as basis. The default implementation of this method will just return the given socket in the argument. If the default host/port is not set, it will be set to the same as the given socket.
      Parameters:
      caller - The requestor object instance
      s -
      Returns:
      the resulting socket
    • getSocket

      public static Socket getSocket(Object caller, String hostname, int port) throws IOException, ConfException
      Retrieve a connected socket to a specified destination If the default host/port is not set, it will be set to the same as the given socket.
      Parameters:
      caller - The requestor object instance
      hostname - The preferred host
      port - The preferred port
      Returns:
      the socket connected to hostname, port
      Throws:
      IOException
      ConfException
    • getSocket

      public static Socket getSocket(Object caller, InetAddress iaddr, int port) throws IOException, ConfException
      Retrieve a connected socket to a specified destination If the default host/port is not set, it will be set to the same as the given socket.
      Parameters:
      caller - The requestor object instance
      iaddr - The preferred address
      port - The preferred port
      Returns:
      the socket connection to iaddr, port
      Throws:
      IOException
      ConfException
    • registerCallback

      public static void registerCallback(SocketFactoryCallback cb)
      Register a SocketFactoryCallback that will be responsible for all socket connection
      Parameters:
      cb - SocketFactoryCallback instance
    • getSocketFactoryCb

      public static SocketFactoryCallback getSocketFactoryCb()
      Retrieve the SocketFactoryCallback. This always exists, if the user have not registered a callback this method will return a DefaultSocketFactoryCb instance
      Returns:
      the current SocketFactoryCallback