Gain access to sockets from your application
Every Remoting transport uses Sockets, but the creation and management of the Sockets is generally inaccessible from the application code. Remoting has a hook that can provide access to Sockets, in the form of a listener interface in the org.jboss.remoting.socketfactory package: public interface SocketCreationListener { /** * Called when a socket has been created. * * @param socket socket that has been created * @param source SocketFactory or ServerSocket that created the socket * @throws IOException */ void socketCreated(Socket socket, Object source) throws IOException; } Socket creation listeners can be registered to be informed every time a socket is created by a SocketFactory or ServerSocket. The mechanisms for registering listeners are the usual ones, e.g., by putting them in configuration maps passed to client and server invokers. (See Section General transport configuration for a general discussion of parameter configuration in Remoting.) In any case they should be associated with one of the following keys from org.jboss.remoting.Remoting: /** * Key for the configuration map passed to a Client or Connector to indicate * a socket creation listener for sockets created by a SocketFactory. */ public static final String SOCKET_CREATION_CLIENT_LISTENER = "socketCreationClientListener"; /** * Key for the configuration map passed to a Client or Connector to indicate * a socket creation listener for sockets created by a ServerSocket. */ public static final String SOCKET_CREATION_SERVER_LISTENER = "socketCreationServerListener"; The value associated with either of these keys can be an actual object, or, to facilitate configuration by InvokerLocator or xml, it can be the name of a class that implements SocketCreationListener and has a default constructor Note that client and server invokers always use the respective keys SOCKET_CREATION_CLIENT_LISTENER and SOCKET_CREATION_SERVER_LISTENER, whether they are on the client side or server side. For example, a callback client invoker would be configured by putting a listener with the key SOCKET_CREATION_CLIENT_LISTENER in the configuration map passed to the server side Connector, which will find its way to the callback client invoker when a callback handler is registered. The creation listener facility currently is supported by the following transports: bisocket, sslbisocket, https, rmi, sslrmi, socket, and sslsocket. It is not supported by http because HttpURLConnection does not expose its socket factory (though HttpsURLConnection does). It is not supported by the servlet transport because invocations with the servlet transport go through a servlet container, which is outside the scope of Remoting.