[jboss-remoting-commits] JBoss Remoting SVN: r5574 - in remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3: spi and 1 other directory.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Oct 30 23:21:28 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-10-30 23:21:28 -0400 (Fri, 30 Oct 2009)
New Revision: 5574

Added:
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
Modified:
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java
Log:
Consolidate the different protocol service type registration methods into one.  This allows us to add more types later on without adding methods to the interface.

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java	2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java	2009-10-31 03:21:28 UTC (rev 5574)
@@ -6,14 +6,9 @@
 import org.jboss.remoting3.spi.ConnectionProviderFactory;
 import org.jboss.remoting3.spi.RequestHandler;
 import org.jboss.remoting3.spi.ConnectionProviderRegistration;
+import org.jboss.remoting3.spi.ProtocolServiceType;
 import org.jboss.xnio.IoFuture;
 import org.jboss.xnio.OptionMap;
-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.marshalling.MarshallerFactory;
 
 /**
  * A potential participant in a JBoss Remoting communications relationship.
@@ -196,78 +191,18 @@
     <T> ConnectionProviderRegistration<T> addConnectionProvider(String uriScheme, ConnectionProviderFactory<T> providerFactory) throws DuplicateRegistrationException;
 
     /**
-     * Register a named marshalling protocol.
-     * <p/>
-     * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
+     * Register a protocol service.
      *
-     * @param name the protocol name
-     * @param marshallerFactory the implementation
+     * @param type the type of service being registered
+     * @param name the name of the protocol provider
+     * @param provider the provider instance
+     * @param <T> the provider type
      * @return a handle which may be used to remove the registration
      * @throws DuplicateRegistrationException if there is already a protocol registered to that name
      */
-    Registration addMarshallingProtocol(String name, MarshallerFactory marshallerFactory) throws DuplicateRegistrationException;
+    <T> Registration addProtocolService(ProtocolServiceType<T> type, String name, T provider) throws DuplicateRegistrationException;
 
     /**
-     * Register a named class table for marshalling.
-     * <p/>
-     * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
-     *
-     * @param name the protocol name
-     * @param classTable the class table
-     * @return a handle which may be used to remove the registration
-     * @throws DuplicateRegistrationException if there is already a class table registered to that name
-     */
-    Registration addUserClassTable(String name, ClassTable classTable) throws DuplicateRegistrationException;
-
-    /**
-     * Register a named object table for marshalling.
-     * <p/>
-     * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
-     *
-     * @param name the protocol name
-     * @param objectTable the object table
-     * @return a handle which may be used to remove the registration
-     * @throws DuplicateRegistrationException if there is already an object table registered to that name
-     */
-    Registration addUserObjectTable(String name, ObjectTable objectTable) throws DuplicateRegistrationException;
-
-    /**
-     * Register a named class externalizer factory for marshalling.
-     * <p/>
-     * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
-     *
-     * @param name the protocol name
-     * @param classExternalizerFactory the class externalizer factory
-     * @return a handle which may be used to remove the registration
-     * @throws DuplicateRegistrationException if there is already a class externalizer factory registered to that name
-     */
-    Registration addUserExternalizerFactory(String name, ClassExternalizerFactory classExternalizerFactory) throws DuplicateRegistrationException;
-
-    /**
-     * Register a named class resolver for marshalling.
-     * <p/>
-     * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
-     *
-     * @param name the protocol name
-     * @param classResolver the class resolver
-     * @return a handle which may be used to remove the registration
-     * @throws DuplicateRegistrationException if there is already a class resolver registered to that name
-     */
-    Registration addUserClassResolver(String name, ClassResolver classResolver) throws DuplicateRegistrationException;
-
-    /**
-     * Register a named object resolver for marshalling.
-     * <p/>
-     * You must have the {@link org.jboss.remoting3.EndpointPermission addMarshallingProtocol EndpointPermission} to invoke this method.
-     *
-     * @param name the protocol name
-     * @param objectResolver the class resolver
-     * @return a handle which may be used to remove the registration
-     * @throws DuplicateRegistrationException if there is already an object resolver registered to that name
-     */
-    Registration addUserObjectResolver(String name, ObjectResolver objectResolver) throws DuplicateRegistrationException;
-
-    /**
      * Flags which can be passed in to listener registration methods.
      */
     enum ListenerFlag {

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java	2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java	2009-10-31 03:21:28 UTC (rev 5574)
@@ -47,6 +47,7 @@
 import org.jboss.remoting3.spi.RequestHandlerConnector;
 import org.jboss.remoting3.spi.ConnectionProviderRegistration;
 import org.jboss.remoting3.spi.ConnectionHandlerContext;
+import org.jboss.remoting3.spi.ProtocolServiceType;
 import org.jboss.xnio.log.Logger;
 import org.jboss.xnio.Cancellable;
 import org.jboss.xnio.FailedIoFuture;
@@ -121,6 +122,9 @@
     private final ConcurrentMap<String, ConcurrentMap<String, ServiceRegistration>> registeredLocalServices = concurrentMap(serviceRegistrationLock);
 
     private final ConcurrentMap<String, ConnectionProvider<?>> connectionProviders = concurrentMap();
+
+    private final ConcurrentMap[] providerMaps = new ConcurrentMap[ProtocolServiceType.getServiceTypes().length];
+
     private final ConcurrentMap<String, MarshallerFactory> marshallerFactories = concurrentMap();
     private final ConcurrentMap<String, ClassTable> classTables = concurrentMap();
     private final ConcurrentMap<String, ObjectTable> objectTables = concurrentMap();
@@ -137,8 +141,11 @@
     private static final EndpointPermission ADD_CONNECTION_PROVIDER_PERM = new EndpointPermission("addConnectionProvider");
     private static final EndpointPermission ADD_MARSHALLING_PROTOCOL_PERM = new EndpointPermission("addMarshallingProtocol");
 
-    public EndpointImpl(final Executor executor, final String name) {
+    EndpointImpl(final Executor executor, final String name) {
         super(executor);
+        for (int i = 0; i < providerMaps.length; i++) {
+            providerMaps[i] = concurrentMap();
+        }
         final SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             sm.checkPermission(CREATE_ENDPOINT_PERM);
@@ -158,7 +165,10 @@
         return executor;
     }
 
-    // Endpoint implementation
+    @SuppressWarnings({ "unchecked" })
+    private <T> ConcurrentMap<String, T> getMapFor(ProtocolServiceType<T> type) {
+        return (ConcurrentMap<String, T>)providerMaps[type.getIndex()];
+    }
 
     public String getName() {
         return name;
@@ -510,30 +520,10 @@
         return new MapRegistration<T>(map, name, target);
     }
 
-    public Registration addMarshallingProtocol(final String name, final MarshallerFactory marshallerFactory) throws DuplicateRegistrationException {
-        return addMarshallingRegistration(name, marshallerFactory, marshallerFactories, "Marshalling protocol factory");
+    public <T> Registration addProtocolService(final ProtocolServiceType<T> type, final String name, final T provider) throws DuplicateRegistrationException {
+        return addMarshallingRegistration(name, provider, getMapFor(type), type.getDescription());
     }
 
-    public Registration addUserClassTable(final String name, final ClassTable classTable) throws DuplicateRegistrationException {
-        return addMarshallingRegistration(name, classTable, classTables, "Class table");
-    }
-
-    public Registration addUserObjectTable(final String name, final ObjectTable objectTable) throws DuplicateRegistrationException {
-        return addMarshallingRegistration(name, objectTable, objectTables, "Object table");
-    }
-
-    public Registration addUserExternalizerFactory(final String name, final ClassExternalizerFactory classExternalizerFactory) throws DuplicateRegistrationException {
-        return addMarshallingRegistration(name, classExternalizerFactory, classExternalizerFactories, "Class externalizer factory");
-    }
-
-    public Registration addUserClassResolver(final String name, final ClassResolver classResolver) throws DuplicateRegistrationException {
-        return addMarshallingRegistration(name, classResolver, classResolvers, "Class resolver");
-    }
-
-    public Registration addUserObjectResolver(final String name, final ObjectResolver objectResolver) throws DuplicateRegistrationException {
-        return addMarshallingRegistration(name, objectResolver, objectResolvers, "Object resolver");
-    }
-
     public String toString() {
         return "endpoint \"" + name + "\" <" + Integer.toHexString(hashCode()) + ">";
     }
@@ -663,6 +653,10 @@
         public void accept(final ConnectionHandlerFactory connectionHandlerFactory) {
             connectionHandlerFactory.createInstance(localConnectionContext);
         }
+
+        public <T> Iterable<Map.Entry<String, T>> getProtocolServiceProviders(final ProtocolServiceType<T> serviceType) {
+            return getMapFor(serviceType).entrySet();
+        }
     }
 
     private final ConnectionHandler loopbackConnectionHandler = new LoopbackConnectionHandler();

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java	2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java	2009-10-31 03:21:28 UTC (rev 5574)
@@ -103,4 +103,16 @@
      * required.
      */
     public static final Option<Boolean> REQUIRE_SECURE = Option.simple(Options.class, "REQUIRE_SECURE", Boolean.class);
+
+    public static final Option<Integer> MAX_TRANSMIT_SIZE = Option.simple(Options.class, "MAX_TRANSMIT_SIZE", Integer.class);
+
+    public static final Option<Integer> MAX_RECEIVE_SIZE = Option.simple(Options.class, "MAX_RECEIVE_SIZE", Integer.class);
+
+    public static final Option<Integer> TRANSMIT_WINDOW_SIZE = Option.simple(Options.class, "TRANSMIT_WINDOW_SIZE", Integer.class);
+
+    public static final Option<Integer> RECEIVE_WINDOW_SIZE = Option.simple(Options.class, "RECEIVE_WINDOW_SIZE", Integer.class);
+
+    public static final Option<Integer> MAX_OUTBOUND_CHANNELS = Option.simple(Options.class, "MAX_OUTBOUND_CHANNELS", Integer.class);
+
+    public static final Option<Integer> MAX_INBOUND_CHANNELS = Option.simple(Options.class, "MAX_INBOUND_CHANNELS", Integer.class);
 }

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java	2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java	2009-10-31 03:21:28 UTC (rev 5574)
@@ -35,6 +35,7 @@
 import org.jboss.remoting3.spi.RequestHandler;
 import org.jboss.remoting3.spi.RemotingServiceDescriptor;
 import org.jboss.remoting3.spi.ConnectionProviderFactory;
+import org.jboss.remoting3.spi.ProtocolServiceType;
 import org.jboss.xnio.CloseableExecutor;
 import org.jboss.xnio.IoUtils;
 import org.jboss.xnio.OptionMap;
@@ -117,15 +118,15 @@
                     if (serviceType == ConnectionProviderFactory.class) {
                         endpoint.addConnectionProvider(name, (ConnectionProviderFactory<?>) service);
                     } else if (serviceType == ClassTable.class) {
-                        endpoint.addUserClassTable(name, (ClassTable) service);
+                        endpoint.addProtocolService(ProtocolServiceType.CLASS_TABLE, name, (ClassTable) service);
                     } else if (serviceType == ObjectTable.class) {
-                        endpoint.addUserObjectTable(name, (ObjectTable) service);
+                        endpoint.addProtocolService(ProtocolServiceType.OBJECT_TABLE, name, (ObjectTable) service);
                     } else if (serviceType == ClassResolver.class) {
-                        endpoint.addUserClassResolver(name, (ClassResolver) service);
+                        endpoint.addProtocolService(ProtocolServiceType.CLASS_RESOLVER, name, (ClassResolver) service);
                     } else if (serviceType == ObjectResolver.class) {
-                        endpoint.addUserObjectResolver(name, (ObjectResolver) service);
+                        endpoint.addProtocolService(ProtocolServiceType.OBJECT_RESOLVER, name, (ObjectResolver) service);
                     } else if (serviceType == ClassExternalizerFactory.class) {
-                        endpoint.addUserExternalizerFactory(name, (ClassExternalizerFactory) service);
+                        endpoint.addProtocolService(ProtocolServiceType.CLASS_EXTERNALIZER_FACTORY, name, (ClassExternalizerFactory) service);
                     }
                 } catch (DuplicateRegistrationException e) {
                     log.debug("Duplicate registration for '" + name + "' of " + serviceType);
@@ -142,7 +143,7 @@
             for (String name : found.keySet()) {
                 final MarshallerFactory marshallerFactory = found.get(name).getMarshallerFactory();
                 try {
-                    endpoint.addMarshallingProtocol(name, marshallerFactory);
+                    endpoint.addProtocolService(ProtocolServiceType.MARSHALLER_FACTORY, name, marshallerFactory);
                 } catch (DuplicateRegistrationException e) {
                     log.debug("Duplicate registration for '" + name + "' of " + MarshallerFactory.class);
                 }

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java	2009-10-30 22:18:09 UTC (rev 5573)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProviderContext.java	2009-10-31 03:21:28 UTC (rev 5574)
@@ -23,6 +23,7 @@
 package org.jboss.remoting3.spi;
 
 import org.jboss.remoting3.HandleableCloseable;
+import java.util.Map;
 
 /**
  * A context for a connection provider which provides a means to accept a connection.
@@ -37,4 +38,13 @@
      * @param connectionHandlerFactory the connection handler factory
      */
     void accept(ConnectionHandlerFactory connectionHandlerFactory);
+
+    /**
+     * Get the currently-registered protocol service providers of the given type.
+     *
+     * @param serviceType the service type
+     * @param <T> the type of the provider interface
+     * @return the currently-registered providers
+     */
+    <T> Iterable<Map.Entry<String, T>> getProtocolServiceProviders(ProtocolServiceType<T> serviceType);
 }

Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java	2009-10-31 03:21:28 UTC (rev 5574)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.spi;
+
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.ObjectTable;
+import org.jboss.marshalling.ClassResolver;
+import org.jboss.marshalling.ObjectResolver;
+import org.jboss.marshalling.ClassExternalizerFactory;
+import java.io.Serializable;
+
+public final class ProtocolServiceType<T> implements Serializable {
+
+    private final Class<T> valueClass;
+    private final String name;
+    private transient final int index;
+    private static final long serialVersionUID = -4972423526582260641L;
+    private final String description;
+
+    private ProtocolServiceType(Class<T> type, final String name, final String description, final int index) {
+        valueClass = type;
+        this.name = name;
+        this.description = description;
+        this.index = index;
+    }
+
+    public Class<T> getValueClass() {
+        return valueClass;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    protected Object readResolve() {
+        try {
+            return ProtocolServiceType.class.getField(name).get(null);
+        } catch (Exception e) {
+            throw new IllegalStateException("Cannot resolve service type object", e);
+        }
+    }
+
+    public static final ProtocolServiceType<MarshallerFactory> MARSHALLER_FACTORY;
+
+    public static final ProtocolServiceType<ClassTable> CLASS_TABLE;
+
+    public static final ProtocolServiceType<ObjectTable> OBJECT_TABLE;
+
+    public static final ProtocolServiceType<ClassResolver> CLASS_RESOLVER;
+
+    public static final ProtocolServiceType<ObjectResolver> OBJECT_RESOLVER;
+
+    public static final ProtocolServiceType<ClassExternalizerFactory> CLASS_EXTERNALIZER_FACTORY;
+
+    private static final ProtocolServiceType<?>[] SERVICE_TYPES;
+
+    public static ProtocolServiceType<?>[] getServiceTypes() {
+        return SERVICE_TYPES.clone();
+    }
+
+    public static ProtocolServiceType<?> getServiceType(int index) {
+        return SERVICE_TYPES[index];
+    }
+
+    static {
+        int index = 0;
+        SERVICE_TYPES = new ProtocolServiceType<?>[] {
+                MARSHALLER_FACTORY = new ProtocolServiceType<MarshallerFactory>(MarshallerFactory.class, "MARSHALLER_FACTORY", "Marshaller factory", index++),
+                CLASS_TABLE = new ProtocolServiceType<ClassTable>(ClassTable.class, "CLASS_TABLE", "Class table", index++),
+                OBJECT_TABLE = new ProtocolServiceType<ObjectTable>(ObjectTable.class, "OBJECT_TABLE", "Object table", index++),
+                CLASS_RESOLVER = new ProtocolServiceType<ClassResolver>(ClassResolver.class, "CLASS_RESOLVER", "Class resolver", index++),
+                OBJECT_RESOLVER = new ProtocolServiceType<ObjectResolver>(ObjectResolver.class, "OBJECT_RESOLVER", "Object resolver", index++),
+                CLASS_EXTERNALIZER_FACTORY = new ProtocolServiceType<ClassExternalizerFactory>(ClassExternalizerFactory.class, "CLASS_EXTERNALIZER_FACTORY", "Class externalizer factory", index++),
+        };
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}



More information about the jboss-remoting-commits mailing list