1 Reply Latest reply: Nov 23, 2009 2:59 PM by David Lloyd RSS

Remoting 3 protocol SPI

Ron Sigal Master

Some discussion about protocol independent proxies in the thread "Naming over Remoting 3" in the JBoss AS Development forum (http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266845#4266845) has suggested to me the following idea. I'd like to be able to do something like

...
Endpoint clientEndpoint = Remoting.createEndpoint("clientEndpoint");
Protocol protocol = Remoting.getProtocol(url.getProtocol());
protocol.registerClientTransport(clientEndpoint, clientExecutor, "localhost");
Connection connection = clientEndpoint.connect(url), OptionMap.EMPTY).get();
Client<String, String> client = connection.openClient("servicetype", "group", String.class, String.class).get();


The idea is that

1. the protocol class hides the details involved in endowing an endpoint with the ability to communicate over a particular protocol, and

2. making the protocol class accessible this way would facilitate protocol neutral code.

The org.jboss.remoting3.samples.socket.SocketProtocol class, for example, which is based on a similar class from an earlier sample protocol, looks more or less like this:

public class SocketProtocol {

 /**
 * Register ConnectionProvider.
 * This endpoint can be a socket transport client.
 */
 static public <T, I, O> void registerClientTransport(final Endpoint endpoint, final Executor executor, final String host) {
 ...
 }

 /**
 * Register ConnectionProvider and start its listening facility.
 * This endpoint can be both a client and server for the socket transport.
 */
 static public <T, I, O> Cancellable registerServerTransport(Endpoint endpoint, Executor executor, final String host, final int port) {
 ...
 }

 /**
 * Register a service with an endpoint.
 * This endpoint must be acting as a socket transport server.
 */
 static public <I, O> void startService(Endpoint endpoint, Executor executor, SocketServiceConfiguration<I, O> socketConfig, final RequestListener<I, O> requestListener) throws IOException; {
 ...
 }
}


So, I'm suggesting abstracting that to an interface.

WDYT?

  • 1. Re: Remoting 3 protocol SPI
    David Lloyd Master

    When creating an endpoint via Remoting.createEndpoint(), all the protocol transports that exist on the classpath will be automatically installed into the endpoint. When creating an endpoint via AS, the deployer system will be used instead, but the results are the same - the protocols are installed automatically.

    So essentially, if you remove the second and third lines from your first example, it should just work, as long as the protocol exists on the classpath.

    You can still install additional protocols manually via Endpoint.addConnectionProvider().

    I do want a better solution for servers though. Problem is, there's really no truly generic representation for servers. You can't just throw a SocketAddress and an OptionMap at it, because (a) it might not even involve a socket, and (b) you may need more information that can't be specified by an OptionMap (such as the Executor in your example). Right now, if you are the one who registers the connection provider, you can use the return value from that method to get an interface to control the server, though the interface type is specific to the ConnectionProviderFactory. But if not (e.g. if the provider was detected), you're S.O.L. Perhaps a method on Endpoint like this could solve the problem:

    T getProviderInterface(String uriScheme, Class<T> interfaceType)