I have implemented a version of the solution I suggested above and checked it in to the
Remoting HEAD and remoting_2_x branches.
1. There are a couple of changes. First, the listener interface,
org.jboss.remoting.socketfactory.SocketCreationListener, is
| 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;
| }
|
and there are two distinct configuration keys for incorporating listeners into socket
factories and server sockets:
org.jboss.Remoting.SOCKET_CREATION_CLIENT_LISTENER (with value
"socketCreationClientListener")
and
org.jboss.Remoting.SOCKET_CREATION_SERVER_LISTENER (with value
"socketCreationServerListener")
The reason for distinguishing these is that the same configuration Map can get passed to
both a server and a client. For example, it could be passed to a Connector and then later
to a Client used by the Connector to push callbacks. Finally, to support configuration by
InvokerLocator or xml, the value of the listener parameter can be the name of a class that
implements SocketCreationListener and has a default constructor.
2. The solution works for the following transports: bisocket, sslbisocket, https,
multiplex, sslmultiplex, rmi, sslrmi, socket, and sslsocket. It does not work for the
http transport and for the server side of the servlet transport. The reason it
doesn't work for http is that HttpURLConnection does not expose its socket factory
(though HttpsURLConnection does). It should be possible to write a custom http protocol
handler for this purpose, but I won't unless is there is a specific request. And
invocations with the servlet transport go through a servlet container, which is outside
the scope of Remoting.
3. The implementation is based on the classes: CreationListenerSocketFactory,
CreationListenerServerSocketFactory, and
CreationListenerServerSocket in the package org.jboss.remoting.socketfactory.
CreationListenerSocketFactory wraps the SocketFactory that would otherwise be used, and
calls the listener whenever a socket is created. CreationListenerServerSocketFactory
wraps the ServerSocketFactory that would otherwise be used, and whenever a ServerSocket is
created, it wraps that ServerSocket in a CreationListenerServerSocket, which calls the
listener whenever it creates a socket.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4002613#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...