[jboss-remoting-commits] JBoss Remoting SVN: r4369 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi/remote and 4 other directories.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Jul 10 10:56:19 EDT 2008


Author: david.lloyd at jboss.com
Date: 2008-07-10 10:56:19 -0400 (Thu, 10 Jul 2008)
New Revision: 4369

Modified:
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
   remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
   remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Move responsibility for creating Client and ClientSource instances to the Endpoint

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -18,5 +18,5 @@
      *
      * @return the new context
      */
-    Client<I, O> createContext() throws RemotingException;
+    Client<I, O> createClient() throws RemotingException;
 }

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -35,8 +35,9 @@
      * @param <O> the reply type
      * @param requestListener the request listener
      * @return the client
+     * @throws RemotingException if an error occurs
      */
-    <I, O> RemoteClientEndpoint<I, O> createClient(RequestListener<I, O> requestListener) throws RemotingException;
+    <I, O> RemoteClientEndpoint<I, O> createClientEndpoint(RequestListener<I, O> requestListener) throws RemotingException;
 
     /**
      * Create a client source that can be used to acquire clients associated with a request listener on this endpoint.
@@ -49,6 +50,29 @@
      * @param <O> the reply type
      * @param requestListener the request listener
      * @return the context source
+     * @throws RemotingException if an error occurs
      */
-    <I, O> RemoteServiceEndpoint<I, O> createService(RequestListener<I, O> requestListener) throws RemotingException;
+    <I, O> RemoteServiceEndpoint<I, O> createServiceEndpoint(RequestListener<I, O> requestListener) throws RemotingException;
+
+    /**
+     * Create a client from a remote client endpoint.
+     *
+     * @param <I> the request type
+     * @param <O> the reply type
+     * @param endpoint the remote client endpoint
+     * @return the client
+     * @throws RemotingException if an error occurs
+     */
+    <I, O> Client<I, O> createClient(RemoteClientEndpoint<I, O> endpoint) throws RemotingException;
+
+    /**
+     * Create a client source from a remote service endpoint.
+     *
+     * @param <I> the request type
+     * @param <O> the reply type
+     * @param endpoint the remote service endpoint
+     * @return the client source
+     * @throws RemotingException if an error occurs
+     */
+    <I, O> ClientSource<I, O> createClientSource(RemoteServiceEndpoint<I, O> endpoint) throws RemotingException;
 }

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteClientEndpoint.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -65,14 +65,6 @@
     Handle<RemoteClientEndpoint<I, O>> getHandle() throws RemotingException;
 
     /**
-     * Get a local client which can be used to make invocations.
-     *
-     * @return the client
-     * @throws RemotingException if a client could not be acquired
-     */
-    Client<I, O> getClient() throws RemotingException;
-
-    /**
      * Automatically close this client endpoint when all handles and local client instances are closed.
      */
     void autoClose() throws RemotingException;

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteServiceEndpoint.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -29,7 +29,9 @@
 
 /**
  * A remote service endpoint, which can be passed to remote endpoints.  Remote systems can then use the service endpoint
- * to acquire client endpoints, or they may pass it on to other systems.
+ * to acquire client endpoints, or they may pass it on to other systems.  Acquiring a client endpoint using this method
+ * has the advantage that a round trip to the remote side is not necessary; the local side can spawn a client endpoint
+ * and simply notify the remote side of the change.
  */
 public interface RemoteServiceEndpoint<I, O> extends Closeable<RemoteServiceEndpoint<I, O>> {
 
@@ -53,13 +55,6 @@
     Handle<RemoteServiceEndpoint<I, O>> getHandle() throws RemotingException;
 
     /**
-     * Get a local client source which can be used to access this service.
-     *
-     * @return the client source
-     */
-    ClientSource<I, O> getClientSource() throws RemotingException;
-
-    /**
      * Automatically close this service endpoint when all handles and local client source instances
      * are closed.
      */

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -44,7 +44,7 @@
     /**
      * {@inheritDoc}  This implementation calls the same method on the delegate object.
      */
-    public Client<I, O> createContext() throws RemotingException {
-        return delegate.createContext();
+    public Client<I, O> createClient() throws RemotingException {
+        return delegate.createClient();
     }
 }

Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -4,6 +4,8 @@
 import org.jboss.cx.remoting.Endpoint;
 import org.jboss.cx.remoting.RemotingException;
 import org.jboss.cx.remoting.RequestListener;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.ClientSource;
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
 import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
 
@@ -39,14 +41,28 @@
     /**
      * {@inheritDoc}  This implementation calls the same method on the delegate object.
      */
-    public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) throws RemotingException {
-        return delegate.createClient(requestListener);
+    public <I, O> RemoteClientEndpoint<I, O> createClientEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
+        return delegate.createClientEndpoint(requestListener);
     }
 
     /**
      * {@inheritDoc}  This implementation calls the same method on the delegate object.
      */
-    public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) throws RemotingException {
-        return delegate.createService(requestListener);
+    public <I, O> RemoteServiceEndpoint<I, O> createServiceEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
+        return delegate.createServiceEndpoint(requestListener);
     }
+
+    /**
+     * {@inheritDoc}  This implementation calls the same method on the delegate object.
+     */
+    public <I, O> Client<I, O> createClient(final RemoteClientEndpoint<I, O> endpoint) throws RemotingException {
+        return delegate.createClient(endpoint);
+    }
+
+    /**
+     * {@inheritDoc}  This implementation calls the same method on the delegate object.
+     */
+    public <I, O> ClientSource<I, O> createClientSource(final RemoteServiceEndpoint<I, O> endpoint) throws RemotingException {
+        return delegate.createClientSource(endpoint);
+    }
 }

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -25,27 +25,30 @@
 import org.jboss.cx.remoting.ClientSource;
 import org.jboss.cx.remoting.Client;
 import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.Endpoint;
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
-import java.util.concurrent.Executor;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
 
 /**
  *
  */
 public final class ClientSourceImpl<I, O> extends AbstractCloseable<ClientSource<I, O>> implements ClientSource<I, O> {
 
-    private final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint;
+    private final RemoteServiceEndpoint<I, O> serviceEndpoint;
+    private final Endpoint endpoint;
 
-    ClientSourceImpl(final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint, final Executor executor) {
-        super(executor);
+    ClientSourceImpl(final RemoteServiceEndpoint<I, O> serviceEndpoint, final EndpointImpl endpoint) {
+        super(endpoint.getExecutor());
         this.serviceEndpoint = serviceEndpoint;
+        this.endpoint = endpoint;
     }
 
-    public Client<I, O> createContext() throws RemotingException {
+    public Client<I, O> createClient() throws RemotingException {
         if (! isOpen()) {
             throw new RemotingException("Client source is not open");
         }
         final RemoteClientEndpoint<I,O> clientEndpoint = serviceEndpoint.openClient();
-        final Client<I, O> client = clientEndpoint.getClient();
+        final Client<I, O> client = endpoint.createClient(clientEndpoint);
         clientEndpoint.autoClose();
         return client;
     }

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -11,9 +11,12 @@
 import org.jboss.cx.remoting.RequestListener;
 import org.jboss.cx.remoting.RemotingException;
 import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.ClientSource;
 import org.jboss.cx.remoting.core.util.OrderedExecutorFactory;
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
 import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
+import org.jboss.cx.remoting.spi.remote.Handle;
 import org.jboss.cx.remoting.util.CollectionUtil;
 import org.jboss.cx.remoting.util.NamingThreadFactory;
 import org.jboss.cx.remoting.version.Version;
@@ -118,20 +121,58 @@
         return endpointMap;
     }
 
-    public <I, O> RemoteClientEndpoint<I, O> createClient(final RequestListener<I, O> requestListener) throws RemotingException {
+    public <I, O> RemoteClientEndpoint<I, O> createClientEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
         final RemoteClientEndpointLocalImpl<I, O> clientEndpoint = new RemoteClientEndpointLocalImpl<I, O>(executor, requestListener);
         clientEndpoint.addCloseHandler(remover);
         clientEndpoint.open();
         return clientEndpoint;
     }
 
-    public <I, O> RemoteServiceEndpoint<I, O> createService(final RequestListener<I, O> requestListener) throws RemotingException {
+    public <I, O> RemoteServiceEndpoint<I, O> createServiceEndpoint(final RequestListener<I, O> requestListener) throws RemotingException {
         final RemoteServiceEndpointLocalImpl<I, O> serviceEndpoint = new RemoteServiceEndpointLocalImpl<I, O>(executor, requestListener);
         serviceEndpoint.addCloseHandler(remover);
         serviceEndpoint.open();
         return serviceEndpoint;
     }
 
+    public <I, O> Client<I, O> createClient(final RemoteClientEndpoint<I, O> endpoint) throws RemotingException {
+        boolean ok = false;
+        final Handle<RemoteClientEndpoint<I,O>> handle = endpoint.getHandle();
+        try {
+            final ClientImpl<I, O> client = new ClientImpl<I, O>(endpoint, executor);
+            client.addCloseHandler(new CloseHandler<Client<I, O>>() {
+                public void handleClose(final Client<I, O> closed) {
+                    IoUtils.safeClose(handle);
+                }
+            });
+            ok = true;
+            return client;
+        } finally {
+            if (! ok) {
+                IoUtils.safeClose(handle);
+            }
+        }
+    }
+
+    public <I, O> ClientSource<I, O> createClientSource(final RemoteServiceEndpoint<I, O> endpoint) throws RemotingException {
+        boolean ok = false;
+        final Handle<RemoteServiceEndpoint<I,O>> handle = endpoint.getHandle();
+        try {
+            final ClientSourceImpl<I, O> client = new ClientSourceImpl<I, O>(endpoint, executor);
+            client.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
+                public void handleClose(final ClientSource<I, O> closed) {
+                    IoUtils.safeClose(handle);
+                }
+            });
+            ok = true;
+            return client;
+        } finally {
+            if (! ok) {
+                IoUtils.safeClose(handle);
+            }
+        }
+    }
+
     private final ResourceRemover remover = new ResourceRemover();
 
     private final class ResourceRemover implements CloseHandler<Closeable> {

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteClientEndpointLocalImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -27,7 +27,6 @@
 import org.jboss.cx.remoting.spi.remote.ReplyHandler;
 import org.jboss.cx.remoting.spi.SpiUtils;
 import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.Client;
 import org.jboss.cx.remoting.RequestListener;
 import org.jboss.cx.remoting.RemoteExecutionException;
 import org.jboss.cx.remoting.CloseHandler;
@@ -93,25 +92,6 @@
         };
     }
 
-    public Client<I, O> getClient() throws RemotingException {
-        inc();
-        boolean ok = false;
-        try {
-            final ClientImpl<I, O> client = new ClientImpl<I, O>(this, executor);
-            client.addCloseHandler(new CloseHandler<Client<I, O>>() {
-                public void handleClose(final Client<I, O> closed) {
-                    safeDec();
-                }
-            });
-            ok = true;
-            return client;
-        } finally {
-            if (! ok) {
-                safeDec();
-            }
-        }
-    }
-
     void open() throws RemotingException {
         try {
             requestListener.handleClientOpen(clientContext);

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RemoteServiceEndpointLocalImpl.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -26,7 +26,6 @@
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
 import org.jboss.cx.remoting.RequestListener;
 import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.ClientSource;
 import org.jboss.cx.remoting.CloseHandler;
 import org.jboss.xnio.log.Logger;
 import java.util.concurrent.Executor;
@@ -59,25 +58,6 @@
         }
     }
 
-    public ClientSource<I, O> getClientSource() throws RemotingException {
-        inc();
-        boolean ok = false;
-        try {
-            final ClientSourceImpl<I, O> clientSource = new ClientSourceImpl<I, O>(this, executor);
-            clientSource.addCloseHandler(new CloseHandler<ClientSource<I, O>>() {
-                public void handleClose(final ClientSource<I, O> closed) {
-                    safeDec();
-                }
-            });
-            ok = true;
-            return clientSource;
-        } finally {
-            if (! ok) {
-                safeDec();
-            }
-        }
-    }
-
     void open() throws RemotingException {
         try {
             requestListener.handleServiceOpen(serviceContext);

Modified: remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -78,7 +78,7 @@
             endpoint.setExecutor(executorService);
             endpoint.start();
             try {
-                final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClient(new AbstractRequestListener<Object, Object>() {
+                final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClientEndpoint(new AbstractRequestListener<Object, Object>() {
                     public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
                         assertEquals(request, requestObj);
                         try {
@@ -98,7 +98,7 @@
                             clientEndpointClosed.set(true);
                         }
                     });
-                    final Client<Object,Object> client = clientEndpoint.getClient();
+                    final Client<Object,Object> client = endpoint.createClient(clientEndpoint);
                     try {
                         client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
                             public void handleClose(final Client<Object, Object> closed) {
@@ -137,7 +137,7 @@
             endpoint.setExecutor(executorService);
             endpoint.start();
             try {
-                final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClient(new AbstractRequestListener<Object, Object>() {
+                final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClientEndpoint(new AbstractRequestListener<Object, Object>() {
                     public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
                         assertEquals(request, requestObj);
                         try {
@@ -157,7 +157,7 @@
                             clientEndpointClosed.set(true);
                         }
                     });
-                    final Client<Object,Object> client = clientEndpoint.getClient();
+                    final Client<Object,Object> client = endpoint.createClient(clientEndpoint);
                     try {
                         client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
                             public void handleClose(final Client<Object, Object> closed) {

Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java	2008-07-08 04:45:53 UTC (rev 4368)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java	2008-07-10 14:56:19 UTC (rev 4369)
@@ -31,20 +31,20 @@
     }
 
     public static <I, O> Client<I, O> createLocalClient(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
-        final RemoteClientEndpoint<I, O> clientEndpoint = endpoint.createClient(requestListener);
+        final RemoteClientEndpoint<I, O> clientEndpoint = endpoint.createClientEndpoint(requestListener);
         try {
-            return clientEndpoint.getClient();
+            return endpoint.createClient(clientEndpoint);
         } finally {
             clientEndpoint.autoClose();
         }
     }
 
     public static <I, O> ClientSource<I, O> createLocalClientSource(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
-        final RemoteServiceEndpoint<I, O> clientEndpoint = endpoint.createService(requestListener);
+        final RemoteServiceEndpoint<I, O> serviceEndpoint = endpoint.createServiceEndpoint(requestListener);
         try {
-            return clientEndpoint.getClientSource();
+            return endpoint.createClientSource(serviceEndpoint);
         } finally {
-            clientEndpoint.autoClose();
+            serviceEndpoint.autoClose();
         }
     }
 




More information about the jboss-remoting-commits mailing list