Package com.tailf.conf
Class SocketFactory
Object
com.tailf.conf.SocketFactory
Class for creation and control of sockets.
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 Summary
Modifier and TypeMethodDescriptionstatic SocketDeprecated.static SocketgetSocket(Object caller, InetAddress address, int port) Deprecated.static SocketDeprecated.UsegetSocket(Socket).static SocketgetSocket(Object caller, SocketAddress address) Deprecated.static SocketRetrieve a socket connected to a specified destinationstatic SocketgetSocket(InetAddress address, int port) Retrieve a socket connected to a specified destinationstatic SocketRetrieve a socket connected to the same remote address as a given socketstatic SocketgetSocket(SocketAddress address) Retrieve a socket connected to a specified address.static SocketFactoryCallbackRetrieve the SocketFactoryCallback.static SocketgetUnconnectedSocket(Object caller, ProtocolFamily family) Deprecated.static SocketgetUnconnectedSocket(ProtocolFamily family) Retrieve an unconnected socket.static voidRegister a SocketFactoryCallback that will be responsible for all socket connectionstatic SocketwrapSocket(Socket socket) Wrap an already connected socket.
-
Method Details
-
getUnconnectedSocket
@Deprecated public static Socket getUnconnectedSocket(Object caller, ProtocolFamily family) throws IOException, ConfException Deprecated.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 instancefamily- The protocol family- Returns:
- An unconnected socket
- Throws:
IOExceptionConfException
-
getUnconnectedSocket
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:
family- The protocol family- Returns:
- An unconnected socket
- Throws:
IOExceptionConfException
-
getSocket
@Deprecated public static Socket getSocket(Object caller, Socket socket) throws IOException, ConfException Deprecated.UsegetSocket(Socket).Retrieve a socket connected to the same remote address as a given socket- Parameters:
caller- The requestor object instancesocket- The socket to base the new socket on- Returns:
- the resulting socket
- Throws:
IOExceptionConfException
-
getSocket
Retrieve a socket connected to the same remote address as a given socket- Parameters:
socket- The socket to base the new socket on- Returns:
- the resulting socket
- Throws:
IOExceptionConfException
-
getSocket
@Deprecated public static Socket getSocket(Object caller, String hostname, int port) throws IOException, ConfException Deprecated.Retrieve a socket connected to a specified destination- Parameters:
caller- The requestor object instancehostname- The preferred hostport- The preferred port- Returns:
- the socket connected to hostname, port
- Throws:
IOExceptionConfException
-
getSocket
Retrieve a socket connected to a specified destination- Parameters:
hostname- The preferred hostport- The preferred port- Returns:
- the socket connected to hostname, port
- Throws:
IOExceptionConfException
-
getSocket
@Deprecated public static Socket getSocket(Object caller, InetAddress address, int port) throws IOException, ConfException Deprecated.Retrieve a socket connected to a specified destination- Parameters:
caller- The requestor object instanceaddress- The preferred addressport- The preferred port- Returns:
- the socket connection to iaddr, port
- Throws:
IOExceptionConfException
-
getSocket
Retrieve a socket connected to a specified destination- Parameters:
address- The preferred addressport- The preferred port- Returns:
- the socket connection to iaddr, port
- Throws:
IOExceptionConfException
-
getSocket
@Deprecated public static Socket getSocket(Object caller, SocketAddress address) throws IOException, ConfException Deprecated.Retrieve a socket connected to a specified address.- Parameters:
caller- The requestor object instanceaddress- The address to connect to- Returns:
- the resulting socket
- Throws:
IOExceptionConfException
-
getSocket
Retrieve a socket connected to a specified address.- Parameters:
address- The address to connect to- Returns:
- the resulting socket
- Throws:
IOExceptionConfException
-
wrapSocket
Wrap an already connected socket. The default implementation will only return the given socket as is- Parameters:
socket- The socket to wrap
-
registerCallback
Register a SocketFactoryCallback that will be responsible for all socket connection- Parameters:
cb- SocketFactoryCallback instance
-
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
-
getSocket(String, int).