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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Mon Mar 17 17:59:58 EDT 2008


Author: david.lloyd at jboss.com
Date: 2008-03-17 17:59:58 -0400 (Mon, 17 Mar 2008)
New Revision: 3660

Added:
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java
Removed:
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistration.java
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistrationSpec.java
Modified:
   remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.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/CoreEndpoint.java
   remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
   remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpProtocolSupport.java
   remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java
   remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppServer.java
   remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
   remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
Log:
Start off a new local protocol handler using the new "system" - need to work out the best way to supply a root context to an incoming session

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-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -3,8 +3,10 @@
 import java.net.URI;
 import java.util.concurrent.ConcurrentMap;
 import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistrationSpec;
+import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
+import org.jboss.cx.remoting.spi.Registration;
 
 /**
  * A potential participant in a JBoss Remoting communications relationship.
@@ -14,19 +16,23 @@
      * Get the endpoint attribute map.  This is a storage area for any data associated with this endpoint, including
      * (but not limited to) connection and protocol information, and application information.
      *
+     * You must have the TODO permission to invoke this method.
+     *
      * @return the endpoint map
      */
     ConcurrentMap<Object, Object> getAttributes();
 
     /**
-     * Open a session with another endpoint.  The protocol used is determined by the URI scheme.  The URI user-info part
+     * Open an outbound session to another endpoint.  The protocol used is determined by the URI scheme.  The URI user-info part
      * must be {@code null} unless the specific protocol has an additional authentication scheme (e.g. HTTP BASIC).  The
      * authority is used to locate the server (the exact interpretation is dependent upon the protocol). The path may be
      * relative to a protocol-specific deployment path.
      *
+     * You must have the TODO permission to invoke this method.
+     *
      * @param remoteUri the URI of the server to connect to
      * @param attributeMap the attribute map to use to configure this session
-     * @param rootContext the root context for the new session
+     * @param rootContext the (local side of the) root context for the new session
      * @return a new session
      *
      * @throws RemotingException if there is a problem creating the session, or if the request or reply type does not
@@ -35,6 +41,17 @@
     <I, O> Session openSession(URI remoteUri, AttributeMap attributeMap, Context<I, O> rootContext) throws RemotingException;
 
     /**
+     * Open an inbound session from another endpoint.  Used by protocol handlers.
+     *
+     * You must have the TODO permission to invoke this method.
+     *
+     * @param handler the protocol handler to use
+     * @param rootContext the (local side of the) root context for this session
+     * @return the protocol context
+     */
+    <I, O> ProtocolContext openIncomingSession(ProtocolHandler handler, Context<I, O> rootContext) throws RemotingException;
+
+    /**
      * Get the name of this endpoint.
      *
      * @return the endpoint name, or {@code null} if there is no name
@@ -44,19 +61,23 @@
     /**
      * Register a protocol specification for this endpoint.
      *
-     * @param spec the protocol specification
+     * You must have the TODO permission to invoke this method.
      *
+     * @param scheme the URI scheme
+     * @param protocolHandlerFactory the protocol handler factory
      * @return a registration that may be used to control this deployment
      *
      * @throws RemotingException if the protocol registration failed
      * @throws IllegalArgumentException if the specification failed validation
      */
-    ProtocolRegistration registerProtocol(ProtocolRegistrationSpec spec) throws RemotingException, IllegalArgumentException;
+    Registration registerProtocol(String scheme, ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException;
 
     /**
      * Create a context that can be used to invoke a request listener on this endpoint.  The context may be passed to a
      * remote endpoint as part of a request or a reply, or it may be used locally.
      *
+     * You must have the TODO permission to invoke this method.
+     *
      * @param requestListener the request listener
      * @return the context
      */
@@ -67,6 +88,8 @@
      * The context source may be passed to a remote endpoint as part of a request or a reply, or it may be used locally.
      * The objects that are produced by this method may be used to mass-produce {@code Context} instances.
      *
+     * You must have the TODO permission to invoke this method.
+     *
      * @param requestListener the request listener
      * @return the context source
      */

Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistration.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistration.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistration.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -1,10 +0,0 @@
-package org.jboss.cx.remoting.spi.protocol;
-
-import org.jboss.cx.remoting.spi.Registration;
-
-/**
- *
- */
-public interface ProtocolRegistration extends Registration {
-    ProtocolServerContext getProtocolServerContext();
-}

Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistrationSpec.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistrationSpec.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/protocol/ProtocolRegistrationSpec.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -1,33 +0,0 @@
-package org.jboss.cx.remoting.spi.protocol;
-
-/**
- *
- */
-public final class ProtocolRegistrationSpec {
-    private final String scheme;
-    private final ProtocolHandlerFactory protocolHandlerFactory;
-
-    public static final ProtocolRegistrationSpec DEFAULT = new ProtocolRegistrationSpec(null, null);
-
-    private ProtocolRegistrationSpec(final String scheme, final ProtocolHandlerFactory protocolHandlerFactory) {
-        this.scheme = scheme;
-        this.protocolHandlerFactory = protocolHandlerFactory;
-    }
-
-    public String getScheme() {
-        return scheme;
-    }
-
-    public ProtocolHandlerFactory getProtocolHandlerFactory() {
-        return protocolHandlerFactory;
-    }
-
-    public ProtocolRegistrationSpec setScheme(String scheme) {
-        return new ProtocolRegistrationSpec(scheme, protocolHandlerFactory);
-    }
-
-    public ProtocolRegistrationSpec setProtocolHandlerFactory(ProtocolHandlerFactory protocolHandlerFactory) {
-        return new ProtocolRegistrationSpec(scheme, protocolHandlerFactory);
-    }
-}
-

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-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -10,8 +10,10 @@
 import org.jboss.cx.remoting.ContextSource;
 import org.jboss.cx.remoting.CloseHandler;
 import org.jboss.cx.remoting.util.AttributeMap;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistrationSpec;
+import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
+import org.jboss.cx.remoting.spi.Registration;
 
 /**
  *
@@ -31,12 +33,16 @@
         return delegate.openSession(remoteUri, attributeMap, rootContext);
     }
 
+    public <I, O> ProtocolContext openIncomingSession(final ProtocolHandler handler, final Context<I, O> rootContext) throws RemotingException {
+        return delegate.openIncomingSession(handler, rootContext);
+    }
+
     public String getName() {
         return delegate.getName();
     }
 
-    public ProtocolRegistration registerProtocol(final ProtocolRegistrationSpec spec) throws RemotingException, IllegalArgumentException {
-        return delegate.registerProtocol(spec);
+    public Registration registerProtocol(String scheme, ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException {
+        return delegate.registerProtocol(scheme, protocolHandlerFactory);
     }
 
     public <I, O> Context<I, O> createContext(final RequestListener<I, O> requestListener) {

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -7,7 +7,6 @@
 import java.util.Iterator;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
 import org.jboss.cx.remoting.Endpoint;
 import org.jboss.cx.remoting.RemotingException;
 import org.jboss.cx.remoting.Session;
@@ -24,9 +23,8 @@
 import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
 import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
 import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistrationSpec;
 import org.jboss.cx.remoting.spi.protocol.ProtocolServerContext;
+import org.jboss.cx.remoting.spi.Registration;
 
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
@@ -88,6 +86,10 @@
         state.requireTransition(State.INITIAL, State.UP);
     }
 
+    public void stop() {
+        // todo
+    }
+
     Executor getOrderedExecutor() {
         return orderedExecutorFactory.getOrderedExecutor();
     }
@@ -103,7 +105,7 @@
         }
     }
 
-    public final class CoreProtocolRegistration implements ProtocolRegistration {
+    public final class CoreProtocolRegistration implements Registration {
         private final CoreProtocolServerContext protocolServerContext = new CoreProtocolServerContext();
         private final ProtocolHandlerFactory protocolHandlerFactory;
 
@@ -120,13 +122,9 @@
         public void unregister() {
         }
 
-        public ProtocolHandlerFactory getProtocolHandlerFactory() {
+        private ProtocolHandlerFactory getProtocolHandlerFactory() {
             return protocolHandlerFactory;
         }
-
-        public ProtocolServerContext getProtocolServerContext() {
-            return protocolServerContext;
-        }
     }
 
     public static final class SimpleClientCallbackHandler implements CallbackHandler {
@@ -184,21 +182,25 @@
             }
         }
 
+        public <I, O> ProtocolContext openIncomingSession(final ProtocolHandler handler, final Context<I, O> rootContext) throws RemotingException {
+            return null;
+        }
+
         public String getName() {
             return name;
         }
 
-        public ProtocolRegistration registerProtocol(ProtocolRegistrationSpec spec) throws RemotingException, IllegalArgumentException {
-            if (spec.getScheme() == null) {
-                throw new NullPointerException("spec.getScheme() is null");
+        public Registration registerProtocol(final String scheme, final ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException {
+            if (scheme == null) {
+                throw new NullPointerException("scheme is null");
             }
-            if (spec.getProtocolHandlerFactory() == null) {
-                throw new NullPointerException("spec.getProtocolHandlerFactory() is null");
+            if (protocolHandlerFactory == null) {
+                throw new NullPointerException("protocolHandlerFactory is null");
             }
             state.requireHold(State.UP);
             try {
-                final CoreProtocolRegistration registration = new CoreProtocolRegistration(spec.getProtocolHandlerFactory());
-                protocolMap.put(spec.getScheme(), registration);
+                final CoreProtocolRegistration registration = new CoreProtocolRegistration(protocolHandlerFactory);
+                protocolMap.put(scheme, registration);
                 return registration;
             } finally {
                 state.release();

Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -115,6 +115,9 @@
         final ContextIdentifier remoteIdentifier = protocolHandler.getRemoteRootContextIdentifier();
         final ProtocolContextServerImpl<I, O> contextServer = new ProtocolContextServerImpl<I,O>(remoteIdentifier);
         clientContexts.put(remoteIdentifier, new WeakReference<ServerContextPair>(new ServerContextPair<I, O>(new BaseContextClient(), contextServer)));
+        final CoreOutboundContext<I, O> coreOutboundContext = new CoreOutboundContext<I, O>(executor);
+        coreOutboundContext.initialize(contextServer);
+        this.rootContext = coreOutboundContext.getUserContext();
     }
 
     <I, O> void initializeServer(final ProtocolHandler protocolHandler, final Context<I, O> rootContext) {

Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java	                        (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandler.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -0,0 +1,92 @@
+package org.jboss.cx.remoting.core.protocol;
+
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
+import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
+import org.jboss.cx.remoting.spi.protocol.ContextIdentifier;
+import org.jboss.cx.remoting.spi.protocol.RequestIdentifier;
+import org.jboss.cx.remoting.spi.protocol.ServiceIdentifier;
+import org.jboss.cx.remoting.spi.protocol.StreamIdentifier;
+import org.jboss.cx.remoting.spi.ObjectMessageOutput;
+import org.jboss.cx.remoting.util.AttributeMap;
+import org.jboss.cx.remoting.RemoteExecutionException;
+import java.net.URI;
+import java.io.IOException;
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+public final class LocalProtocolHandler implements ProtocolHandler {
+    public LocalProtocolHandler(final ProtocolContext context, final URI remoteUri, final AttributeMap attributeMap) {
+
+    }
+
+    public void sendReply(final ContextIdentifier remoteContextIdentifier, final RequestIdentifier requestIdentifier, final Object reply) throws IOException {
+    }
+
+    public void sendException(final ContextIdentifier remoteContextIdentifier, final RequestIdentifier requestIdentifier, final RemoteExecutionException exception) throws IOException {
+    }
+
+    public void sendCancelAcknowledge(final ContextIdentifier remoteContextIdentifier, final RequestIdentifier requestIdentifier) throws IOException {
+    }
+
+    public void sendServiceClosing(final ServiceIdentifier remoteServiceIdentifier) throws IOException {
+    }
+
+    public void sendContextClosing(final ContextIdentifier remoteContextIdentifier, final boolean done) throws IOException {
+    }
+
+    public ContextIdentifier getLocalRootContextIdentifier() {
+        return null;
+    }
+
+    public ContextIdentifier getRemoteRootContextIdentifier() {
+        return null;
+    }
+
+    public ContextIdentifier openContext(final ServiceIdentifier serviceIdentifier) throws IOException {
+        return null;
+    }
+
+    public void sendContextClose(final ContextIdentifier contextIdentifier, final boolean immediate, final boolean cancel, final boolean interrupt) throws IOException {
+    }
+
+    public RequestIdentifier openRequest(final ContextIdentifier contextIdentifier) throws IOException {
+        return null;
+    }
+
+    public void sendServiceClose(final ServiceIdentifier serviceIdentifier) throws IOException {
+    }
+
+    public void sendRequest(final ContextIdentifier contextIdentifier, final RequestIdentifier requestIdentifier, final Object request, final Executor streamExecutor) throws IOException {
+    }
+
+    public void sendCancelRequest(final ContextIdentifier contextIdentifier, final RequestIdentifier requestIdentifier, final boolean mayInterrupt) throws IOException {
+    }
+
+    public ContextIdentifier openContext() throws IOException {
+        return null;
+    }
+
+    public ServiceIdentifier openService() throws IOException {
+        return null;
+    }
+
+    public StreamIdentifier openStream() throws IOException {
+        return null;
+    }
+
+    public void closeStream(final StreamIdentifier streamIdentifier) throws IOException {
+    }
+
+    public ObjectMessageOutput sendStreamData(final StreamIdentifier streamIdentifier, final Executor streamExecutor) throws IOException {
+        return null;
+    }
+
+    public void closeSession() throws IOException {
+    }
+
+    public String getRemoteEndpointName() {
+        return null;
+    }
+}

Added: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java	                        (rev 0)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/protocol/LocalProtocolHandlerFactory.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -0,0 +1,48 @@
+package org.jboss.cx.remoting.core.protocol;
+
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
+import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
+import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
+import org.jboss.cx.remoting.spi.Registration;
+import org.jboss.cx.remoting.util.AttributeMap;
+import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.Endpoint;
+import org.jboss.cx.remoting.RemotingException;
+import java.net.URI;
+import java.io.IOException;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ *
+ */
+public final class LocalProtocolHandlerFactory implements ProtocolHandlerFactory {
+    @SuppressWarnings ({"UnusedDeclaration"})
+    private final Endpoint endpoint;
+
+    public LocalProtocolHandlerFactory(final Endpoint endpoint) {
+        this.endpoint = endpoint;
+    }
+
+    private static final ConcurrentMap<String, LocalProtocolHandlerFactory> endpoints = CollectionUtil.concurrentMap();
+
+    public boolean isLocal(final URI uri) {
+        return true;
+    }
+
+    public ProtocolHandler createHandler(final ProtocolContext context, final URI remoteUri, final AttributeMap attributeMap) throws IOException {
+
+        return new LocalProtocolHandler(context, remoteUri, attributeMap);
+    }
+
+    public void close() {
+        
+    }
+
+    public static void addTo(final Endpoint endpoint) throws RemotingException {
+        final String name = endpoint.getName();
+        final LocalProtocolHandlerFactory handlerFactory = new LocalProtocolHandlerFactory(endpoint);
+        final Registration registration = endpoint.registerProtocol("local", handlerFactory);
+        registration.start();
+        endpoints.putIfAbsent(name, handlerFactory);
+    }
+}

Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpProtocolSupport.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpProtocolSupport.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpProtocolSupport.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -15,9 +15,6 @@
 import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
 import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
 import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistrationSpec;
-import org.jboss.cx.remoting.spi.protocol.ProtocolServerContext;
 
 /**
  *
@@ -27,8 +24,6 @@
     private HttpTransporter httpTransporter;
 
     private final Endpoint endpoint;
-    private final ProtocolRegistration registration;
-    private final ProtocolServerContext serverContext;
     // todo - need secure random?
     private final Random random = new Random();
 
@@ -36,9 +31,7 @@
 
     public HttpProtocolSupport(final Endpoint endpoint) throws RemotingException {
         this.endpoint = endpoint;
-        ProtocolRegistrationSpec spec = ProtocolRegistrationSpec.DEFAULT.setScheme("http").setProtocolHandlerFactory(protocolHandlerFactory);
-        registration = endpoint.registerProtocol(spec);
-        serverContext = registration.getProtocolServerContext();
+        endpoint.registerProtocol("http", protocolHandlerFactory);
     }
 
     public void setHttpTransporter(final HttpTransporter httpTransporter) {

Modified: remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java
===================================================================
--- remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -25,9 +25,7 @@
 import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
 import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
 import org.jboss.cx.remoting.spi.protocol.ProtocolHandlerFactory;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistration;
-import org.jboss.cx.remoting.spi.protocol.ProtocolRegistrationSpec;
-import org.jboss.cx.remoting.spi.protocol.ProtocolServerContext;
+import org.jboss.cx.remoting.spi.Registration;
 
 /**
  *
@@ -42,10 +40,8 @@
 
     /** The NIO processor.  Set upon {@code create}. */
     private IoProcessor ioProcessor;
-    /** Protocol server context.  Set upon {@code create}. */
-    private ProtocolServerContext serverContext;
     /** Protocol registration.  Set upon {@code create}. */
-    private ProtocolRegistration registration;
+    private Registration registration;
 
     public JrppProtocolSupport() {
     }
@@ -74,18 +70,12 @@
         return ioProcessor;
     }
 
-    ProtocolServerContext getServerContext() {
-        return serverContext;
-    }
-
     // Lifecycle
 
     public void create() throws RemotingException {
         ioProcessor = new NioProcessor(executor);
         protocolHandlerFactory = new ProtocolHandlerFactoryImpl();
-        final ProtocolRegistrationSpec spec = ProtocolRegistrationSpec.DEFAULT.setScheme("jrpp").setProtocolHandlerFactory(protocolHandlerFactory);
-        final ProtocolRegistration registration = endpoint.registerProtocol(spec);
-        serverContext = registration.getProtocolServerContext();
+        final Registration registration = endpoint.registerProtocol("jrpp", protocolHandlerFactory);
         this.registration = registration;
     }
 
@@ -106,7 +96,6 @@
             registration = null;
         }
         protocolHandlerFactory = null;
-        serverContext = null;
     }
 
     // Utilities

Modified: remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppServer.java
===================================================================
--- remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppServer.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppServer.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -74,7 +74,6 @@
 
     @SuppressWarnings ({"unchecked"})
     public void create() {
-        serverContext = protocolSupport.getServerContext();
         executor = protocolSupport.getExecutor();
         ioProcessor = protocolSupport.getIoProcessor();
         ioAcceptor = new NioSocketAcceptor(executor, ioProcessor);

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-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -1,41 +1,38 @@
 package org.jboss.cx.remoting;
 
-import java.io.IOException;
 import java.net.URI;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
-import org.jboss.cx.remoting.util.AttributeHashMap;
-import org.jboss.cx.remoting.util.AttributeMap;
 import org.jboss.cx.remoting.log.Logger;
-import org.jboss.cx.remoting.spi.wrapper.ContextSourceWrapper;
-import org.jboss.cx.remoting.spi.wrapper.SessionWrapper;
-import org.jboss.cx.remoting.spi.wrapper.EndpointWrapper;
 import org.jboss.cx.remoting.core.CoreEndpoint;
+import org.jboss.cx.remoting.core.protocol.LocalProtocolHandlerFactory;
 
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-
 /**
  *
  */
 public final class Remoting {
     private static final Logger log = Logger.getLogger(Remoting.class);
 
-    public static Endpoint createEndpoint(String name) {
+    public static Endpoint createEndpoint(String name) throws RemotingException {
         final CoreEndpoint coreEndpoint = new CoreEndpoint(name);
         final ExecutorService executorService = Executors.newCachedThreadPool();
         coreEndpoint.setExecutor(executorService);
         coreEndpoint.start();
-        final Endpoint userEndpoint = coreEndpoint.getUserEndpoint();
-        userEndpoint.addCloseHandler(new CloseHandler<Endpoint>() {
-            public void handleClose(final Endpoint closed) {
-                executorService.shutdown();
+        boolean ok = false;
+        try {
+            final Endpoint userEndpoint = coreEndpoint.getUserEndpoint();
+            LocalProtocolHandlerFactory.addTo(userEndpoint);
+            userEndpoint.addCloseHandler(new CloseHandler<Endpoint>() {
+                public void handleClose(final Endpoint closed) {
+                    executorService.shutdown();
+                }
+            });
+            return userEndpoint;
+        } finally {
+            if (! ok) {
+                coreEndpoint.stop();
             }
-        });
-        return userEndpoint;
+        }
     }
 
     public static Session createEndpointAndSession(String endpointName, URI remoteUri, final String userName, final char[] password) throws RemotingException {

Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java	2008-03-17 08:17:37 UTC (rev 3659)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java	2008-03-17 21:59:58 UTC (rev 3660)
@@ -12,6 +12,7 @@
 import java.util.Set;
 import java.util.WeakHashMap;
 import java.util.Collections;
+import java.util.Collection;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
@@ -344,4 +345,105 @@
             }
         };
     }
+
+    public static AttributeMap emptyAttributeMap() {
+        return EMPTY_ATTRIBUTE_MAP;
+    }
+
+    private static final AttributeMap EMPTY_ATTRIBUTE_MAP = new EmptyAttributeMap();
+
+    private static final class EmptyAttributeMap implements AttributeMap {
+
+        public <T> T get(final AttributeKey<T> key) {
+            return null;
+        }
+
+        public <T> T put(final AttributeKey<T> key, final T value) {
+            throw new UnsupportedOperationException("put()");
+        }
+
+        public <T> T remove(final AttributeKey<T> key) {
+            return null;
+        }
+
+        public <T> boolean remove(final AttributeKey<T> key, final T value) {
+            return false;
+        }
+
+        public <T> T putIfAbsent(final AttributeKey<T> key, final T value) {
+            throw new UnsupportedOperationException("putIfAbsent()");
+        }
+
+        public <T> boolean replace(final AttributeKey<T> key, final T oldValue, final T newValue) {
+            return false;
+        }
+
+        public <T> boolean containsKey(final AttributeKey<T> key) {
+            return false;
+        }
+
+        public <T> boolean containsValue(final T value) {
+            return false;
+        }
+
+        public Iterable<Entry<?>> entries() {
+            return emptyIterable();
+        }
+
+        public Set<AttributeKey<?>> keySet() {
+            return Collections.emptySet();
+        }
+
+        public Collection<?> values() {
+            return Collections.emptySet();
+        }
+
+        public boolean isEmpty() {
+            return true;
+        }
+
+        public int size() {
+            return 0;
+        }
+
+        public void clear() {
+            // might as well let it succeed
+        }
+    }
+
+    @SuppressWarnings ({"unchecked"})
+    public static <T> Iterable<T> emptyIterable() {
+        return (Iterable<T>) EMPTY_ITERABLE;
+    }
+
+    private static final Iterable<?> EMPTY_ITERABLE = new EmptyIterable();
+
+    private static class EmptyIterable implements Iterable<Object> {
+        public Iterator<Object> iterator() {
+            return emptyIterator();
+        }
+    }
+
+    @SuppressWarnings ({"unchecked"})
+    public static <T> Iterator<T> emptyIterator() {
+        return (Iterator<T>) EMPTY_ITERATOR;
+    }
+
+    private static final Iterator<?> EMPTY_ITERATOR = new EmptyIterator();
+
+    private static final class EmptyIterator implements Iterator {
+
+        public boolean hasNext() {
+            return false;
+        }
+
+        public Object next() {
+            throw new NoSuchElementException("next() past end of iterator");
+        }
+
+        public void remove() {
+            throw new IllegalStateException("next() has not yet been called");
+        }
+
+    }
 }




More information about the jboss-remoting-commits mailing list