[jboss-remoting-commits] JBoss Remoting SVN: r5514 - remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Sep 16 23:49:59 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-09-16 23:49:59 -0400 (Wed, 16 Sep 2009)
New Revision: 5514

Modified:
   remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MarshallingProtocol.java
   remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionHandler.java
   remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionProvider.java
   remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexOptions.java
Log:
point commit

Modified: remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MarshallingProtocol.java
===================================================================
--- remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MarshallingProtocol.java	2009-09-17 03:49:31 UTC (rev 5513)
+++ remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MarshallingProtocol.java	2009-09-17 03:49:59 UTC (rev 5514)
@@ -22,25 +22,78 @@
 
 package org.jboss.remoting3.multiplex;
 
-import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.ObjectTable;
+import org.jboss.marshalling.ClassExternalizerFactory;
+import org.jboss.marshalling.ClassResolver;
+import org.jboss.marshalling.ObjectResolver;
+import org.jboss.xnio.Pool;
 
 /**
- * A registered marshalling protocol, which consists of the combination of a factory and the version.
+ * A registered marshalling protocol.
+ *
+ * @remoting.implement
  */
-final class MarshallingProtocol {
-    private final MarshallerFactory marshallerFactory;
-    private final int configuredVersion;
+public interface MarshallingProtocol {
 
-    MarshallingProtocol(final MarshallerFactory marshallerFactory, final int configuredVersion) {
-        this.marshallerFactory = marshallerFactory;
-        this.configuredVersion = configuredVersion;
-    }
+    /**
+     * Get a configured unmarshaller pool.
+     *
+     * @param configuration the configuration to use
+     * @return the pool
+     */
+    Pool<Unmarshaller> getUnmarshallerPool(Configuration configuration);
 
-    public MarshallerFactory getMarshallerFactory() {
-        return marshallerFactory;
-    }
+    /**
+     * Get a configured marshaller pool.
+     *
+     * @param configuration the configuration to use
+     * @return the pool
+     */
+    Pool<Marshaller> getMarshallerPool(Configuration configuration);
 
-    public int getConfiguredVersion() {
-        return configuredVersion;
+    /**
+     * The configuration for a marshalling protocol.
+     *
+     * @remoting.consume
+     */
+    interface Configuration {
+
+        /**
+         * Get a user class table, if any.
+         *
+         * @return the user class table or {@code null} if none is configured
+         */
+        ClassTable getUserClassTable();
+
+        /**
+         * Get a user object table, if any.
+         *
+         * @return the user object table or {@code null} if none is configured
+         */
+        ObjectTable getUserObjectTable();
+
+        /**
+         * Get a user externalizer factory, if any.
+         *
+         * @return the user externalizer factory
+         */
+        ClassExternalizerFactory getUserExternalizerFactory();
+
+        /**
+         * Get a user class resolver, if any.
+         *
+         * @return the user class resolver
+         */
+        ClassResolver getUserClassResolver();
+
+        /**
+         * Get a user object resolver, if any.
+         *
+         * @return the user object resolver
+         */
+        ObjectResolver getUserObjectResolver();
     }
 }

Modified: remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionHandler.java
===================================================================
--- remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionHandler.java	2009-09-17 03:49:31 UTC (rev 5513)
+++ remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionHandler.java	2009-09-17 03:49:59 UTC (rev 5514)
@@ -48,50 +48,64 @@
 
     public Cancellable open(final String serviceName, final String groupName, final Result<RequestHandler> result) {
         final EstablishedConnection establishedConnection = this.establishedConnection;
-        final int id = establishedConnection.nextRemoteClient();
-        final BufferAllocator<ByteBuffer> allocator = establishedConnection.getAllocator();
-        final ByteBuffer buffer = allocator.allocate();
-        final AllocatedMessageChannel channel = establishedConnection.getChannel();
-        final RemoteClient remoteClient = new RemoteClient(result, new MultiplexRequestHandler(id, establishedConnection));
-        establishedConnection.addOutstandingClient(id, remoteClient);
-        buffer.put((byte) MessageType.CLIENT_OPEN);
-        buffer.putInt(id);
-        final byte[] serviceNameBytes = serviceName.getBytes(charset);
-        buffer.putShort((short) serviceNameBytes.length);
-        buffer.put(serviceNameBytes);
-        final byte[] groupNameBytes = groupName.getBytes(charset);
-        buffer.putShort((short) groupNameBytes.length);
-        buffer.put(groupNameBytes);
-        buffer.flip();
+        final PermitManager.Permit permit = establishedConnection.nextRemoteClient();
+        boolean ok = false;
         try {
-            Channels.sendBlocking(channel, buffer);
-        } catch (IOException e) {
-            result.setException(e);
-            establishedConnection.removeRemoteClient(id);
-        }
-        return new Cancellable() {
-            private final AtomicBoolean cancelled = new AtomicBoolean();
-
-            public void cancel() {
-                if (cancelled.getAndSet(true)) {
-                    // cancel already sent
-                    return;
-                }
-                if (remoteClient.getRequestHandler() != null) {
-                    // already done; don't waste the bandwidth
-                    return;
-                }
+            final int id = permit.getId();
+            final RemoteClient remoteClient = new RemoteClient(result, new MultiplexRequestHandler(id, establishedConnection));
+            establishedConnection.addRemoteClient(id, remoteClient);
+            try {
+                final BufferAllocator<ByteBuffer> allocator = establishedConnection.getAllocator();
                 final ByteBuffer buffer = allocator.allocate();
-                buffer.put((byte) MessageType.CLIENT_OPEN_CANCEL);
+                final AllocatedMessageChannel channel = establishedConnection.getChannel();
+                buffer.put((byte) MessageType.CLIENT_OPEN);
                 buffer.putInt(id);
+                final byte[] serviceNameBytes = serviceName.getBytes(charset);
+                buffer.putShort((short) serviceNameBytes.length);
+                buffer.put(serviceNameBytes);
+                final byte[] groupNameBytes = groupName.getBytes(charset);
+                buffer.putShort((short) groupNameBytes.length);
+                buffer.put(groupNameBytes);
                 buffer.flip();
                 try {
                     Channels.sendBlocking(channel, buffer);
                 } catch (IOException e) {
-                    log.trace("Sending a request to cancel a client open failed");
+                    result.setException(e);
                 }
+                ok = true;
+                return new Cancellable() {
+                    private final AtomicBoolean cancelled = new AtomicBoolean();
+
+                    public void cancel() {
+                        if (cancelled.getAndSet(true)) {
+                            // cancel already sent
+                            return;
+                        }
+                        if (remoteClient.getRequestHandler() != null) {
+                            // already done; don't waste the bandwidth
+                            return;
+                        }
+                        final ByteBuffer buffer = allocator.allocate();
+                        buffer.put((byte) MessageType.CLIENT_OPEN_CANCEL);
+                        buffer.putInt(id);
+                        buffer.flip();
+                        try {
+                            Channels.sendBlocking(channel, buffer);
+                        } catch (IOException e) {
+                            log.trace("Sending a request to cancel a client open failed");
+                        }
+                    }
+                };
+            } finally {
+                if (! ok) {
+                    establishedConnection.removeRemoteClient(id);
+                }
             }
-        };
+        } finally {
+            if (! ok) {
+                permit.release();
+            }
+        }
     }
 
     public RequestHandlerConnector createConnector(final RequestHandler localHandler) {

Modified: remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionProvider.java
===================================================================
--- remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionProvider.java	2009-09-17 03:49:31 UTC (rev 5513)
+++ remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexConnectionProvider.java	2009-09-17 03:49:59 UTC (rev 5514)
@@ -28,7 +28,7 @@
 import org.jboss.remoting3.spi.Result;
 import org.jboss.remoting3.spi.SpiUtils;
 import org.jboss.remoting3.spi.ConnectionProviderContext;
-import org.jboss.remoting3.OptionMap;
+import org.jboss.xnio.OptionMap;
 import org.jboss.xnio.FutureConnection;
 import org.jboss.xnio.IoFuture;
 import org.jboss.xnio.IoHandlerFactory;

Modified: remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexOptions.java
===================================================================
--- remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexOptions.java	2009-09-17 03:49:31 UTC (rev 5513)
+++ remoting3-multiplex/trunk/src/main/java/org/jboss/remoting3/multiplex/MultiplexOptions.java	2009-09-17 03:49:59 UTC (rev 5514)
@@ -22,7 +22,7 @@
 
 package org.jboss.remoting3.multiplex;
 
-import org.jboss.remoting3.Option;
+import org.jboss.xnio.Option;
 
 /**
  * Options which may be used to configure a multiplex connection.



More information about the jboss-remoting-commits mailing list