[jboss-remoting-commits] JBoss Remoting SVN: r4023 - in remoting3/trunk: http-se6/src/main/java/org/jboss/cx/remoting/http/se6 and 1 other directory.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Apr 18 23:58:16 EDT 2008


Author: david.lloyd at jboss.com
Date: 2008-04-18 23:58:16 -0400 (Fri, 18 Apr 2008)
New Revision: 4023

Removed:
   remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpProtocolSupport.java
   remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpSession.java
Modified:
   remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java
Log:
Remove old http protocol support

Deleted: 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-04-19 03:29:10 UTC (rev 4022)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpProtocolSupport.java	2008-04-19 03:58:16 UTC (rev 4023)
@@ -1,131 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-import java.io.IOException;
-import java.net.URI;
-import java.security.SecureRandom;
-import java.util.Random;
-import java.util.concurrent.ConcurrentMap;
-import org.jboss.cx.remoting.Endpoint;
-import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.spi.Registration;
-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.util.AttributeMap;
-import org.jboss.cx.remoting.util.CollectionUtil;
-
-/**
- *
- */
-public final class HttpProtocolSupport {
-
-    public HttpProtocolSupport() {/* empty */}
-
-    // Accessors: dependency
-
-    private Endpoint endpoint;
-    private Random random;
-
-    public Endpoint getEndpoint() {
-        return endpoint;
-    }
-
-    public void setEndpoint(final Endpoint endpoint) {
-        this.endpoint = endpoint;
-    }
-
-    public Random getRandom() {
-        return random;
-    }
-
-    public void setRandom(final Random random) {
-        this.random = random;
-    }
-
-    // Accessors: configuration
-    // (none)
-
-    // Lifecycle
-
-    private Registration registration;
-
-    public void create() throws RemotingException {
-        registration = endpoint.registerProtocol("http", new ProtocolHandlerFactory() {
-            public boolean isLocal(final URI uri) {
-                return false;
-            }
-
-            public ProtocolHandler createHandler(final ProtocolContext context, final URI remoteUri, final AttributeMap attributeMap) throws IOException {
-                final RemotingHttpSession session = new RemotingHttpSession();
-                final String sessionId;
-                for (;;) {
-                    final String generatedId = generateSessionId();
-                    if (sessionMap.putIfAbsent(generatedId, session) == null) {
-                        sessionId = generatedId;
-                        break;
-                    }
-                }
-                session.intialize(HttpProtocolSupport.this, sessionId, context);
-                return session.getProtocolHandler();
-            }
-
-            public void close() {
-            }
-        });
-        if (random == null) {
-            random = new SecureRandom();
-        }
-    }
-
-    public void start() {
-        registration.start();
-    }
-
-    public void stop() {
-        registration.stop();
-    }
-
-    public void destroy() {
-        try {
-            registration.unregister();
-        } finally {
-            endpoint = null;
-            random = null;
-            registration = null;
-        }
-    }
-
-    // Session management
-
-    private final ConcurrentMap<String, RemotingHttpSession> sessionMap = CollectionUtil.concurrentWeakValueMap();
-
-    public String generateSessionId() {
-        final byte[] bytes = new byte[16];
-        StringBuilder builder = new StringBuilder(bytes.length * 2);
-        random.nextBytes(bytes);
-        for (byte b : bytes) {
-            builder.append(Character.forDigit(b >>> 4 & 15, 16));
-            builder.append(Character.forDigit(b & 15, 16));
-        }
-        return builder.toString();
-    }
-
-    // todo - additional marshaller negotiation
-    public void establishInboundSession() throws RemotingException {
-        final RemotingHttpSession session = new RemotingHttpSession();
-        final String sessionId;
-        for (;;) {
-            final String generatedId = generateSessionId();
-            if (sessionMap.putIfAbsent(generatedId, session) == null) {
-                sessionId = generatedId;
-                break;
-            }
-        }
-        final ProtocolContext protocolContext = endpoint.openIncomingSession(session.getProtocolHandler());
-        session.intialize(this, sessionId, protocolContext);
-    }
-
-    RemotingHttpSession lookupSession(String sessionId) {
-        return sessionMap.get(sessionId);
-    }
-}

Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpSession.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpSession.java	2008-04-19 03:29:10 UTC (rev 4022)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpSession.java	2008-04-19 03:58:16 UTC (rev 4023)
@@ -1,293 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Executor;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.http.spi.AbstractOutgoingHttpMessage;
-import org.jboss.cx.remoting.http.spi.IncomingHttpMessage;
-import org.jboss.cx.remoting.http.spi.RemotingHttpSessionContext;
-import org.jboss.cx.remoting.util.ByteMessageOutput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
-import org.jboss.cx.remoting.spi.protocol.ClientIdentifier;
-import org.jboss.cx.remoting.spi.protocol.ProtocolContext;
-import org.jboss.cx.remoting.spi.protocol.ProtocolHandler;
-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.util.AtomicStateMachine;
-import static org.jboss.cx.remoting.util.AtomicStateMachine.start;
-import org.jboss.cx.remoting.util.CollectionUtil;
-
-/**
- *
- */
-public final class RemotingHttpSession {
-//    private final RemotingHttpSessionContext context = new SessionContext();
-    private ProtocolContext protocolContext;
-    private ProtocolHandler protocolHandler = new ProtocolHandlerImpl();
-    private final BlockingQueue<IncomingHttpMessage> incomingQueue = CollectionUtil.synchronizedQueue(new LinkedList<IncomingHttpMessage>());
-    private final BlockingQueue<OutputAction> outgoingQueue = CollectionUtil.synchronizedQueue(new LinkedList<OutputAction>());
-
-    private String sessionId;
-
-    public void setSessionId(final String sessionId) {
-        this.sessionId = sessionId;
-    }
-
-    public void intialize(final HttpProtocolSupport httpProtocolSupport, final String sessionId, final ProtocolContext protocolContext) {
-        
-    }
-
-    private enum State implements org.jboss.cx.remoting.util.State<State> {
-        INITIAL,
-        UP,
-        DOWN,
-        ;
-
-        public boolean isReachable(final State dest) {
-            return compareTo(dest) < 0;
-        }
-    }
-
-    private final AtomicStateMachine<State> state = start(State.INITIAL);
-
-    private static final int PROTOCOL_VERSION = 0;
-
-    public RemotingHttpSession() {
-    }
-
-    public String getSessionId() {
-        return sessionId;
-    }
-
-    public RemotingHttpSessionContext getContext() {
-//        return context;
-        return null;
-    }
-
-    public ProtocolHandler getProtocolHandler() {
-        return protocolHandler;
-    }
-
-//    private final class SessionContext implements RemotingHttpSessionContext {
-//        private final Set<ReadyNotifier> readyNotifiers = CollectionUtil.synchronizedSet(new HashSet<ReadyNotifier>());
-//
-//        public void queueMessage(IncomingHttpMessage message) {
-//            incomingQueue.add(message);
-//            synchronized(readyNotifiers) {
-//                for (ReadyNotifier notifier : readyNotifiers) {
-//                    notifier.notifyReady(this);
-//                }
-//            }
-//        }
-//
-//        public void addReadyNotifier(ReadyNotifier notifier) {
-//            readyNotifiers.add(notifier);
-//        }
-//
-//        public OutgoingHttpMessage getNextMessageImmediate() {
-//            final List<OutputAction> actions = CollectionUtil.arrayList();
-//            outgoingQueue.drainTo(actions);
-//            if (actions.isEmpty()) {
-//                return null;
-//            }
-//            return new OutgoingActionHttpMessage(actions);
-//        }
-//
-//        public OutgoingHttpMessage getNextMessage(long timeoutMillis) throws InterruptedException {
-//            synchronized(outgoingQueue) {
-//                final OutputAction first = outgoingQueue.poll(timeoutMillis, TimeUnit.MILLISECONDS);
-//                if (first != null) {
-//                    final List<OutputAction> actions = CollectionUtil.arrayList();
-//                    actions.add(first);
-//                    outgoingQueue.drainTo(actions);
-//                    return new OutgoingActionHttpMessage(actions);
-//                } else {
-//                    return null;
-//                }
-//            }
-//        }
-//    }
-
-    private final class ProtocolHandlerImpl implements ProtocolHandler {
-
-        public void sendReply(final ClientIdentifier remoteClientIdentifier, final RequestIdentifier requestIdentifier, final Object reply) throws IOException {
-        }
-
-        public void sendException(final ClientIdentifier remoteClientIdentifier, final RequestIdentifier requestIdentifier, final RemoteExecutionException exception) throws IOException {
-        }
-
-        public void sendCancelAcknowledge(final ClientIdentifier remoteClientIdentifier, final RequestIdentifier requestIdentifier) throws IOException {
-        }
-
-        public void sendServiceClosing(final ServiceIdentifier remoteServiceIdentifier) throws IOException {
-        }
-
-        public void sendClientClosing(final ClientIdentifier remoteClientIdentifier, final boolean done) throws IOException {
-        }
-
-        public ClientIdentifier getLocalRootClientIdentifier() {
-            return null;
-        }
-
-        public ClientIdentifier getRemoteRootClientIdentifier() {
-            return null;
-        }
-
-        public ClientIdentifier openClient(final ServiceIdentifier serviceIdentifier) throws IOException {
-            return null;
-        }
-
-        public void sendClientClose(final ClientIdentifier clientIdentifier, final boolean immediate, final boolean cancel, final boolean interrupt) throws IOException {
-        }
-
-        public RequestIdentifier openRequest(final ClientIdentifier clientIdentifier) throws IOException {
-            return null;
-        }
-
-        public void sendServiceClose(final ServiceIdentifier serviceIdentifier) throws IOException {
-        }
-
-        public void sendRequest(final ClientIdentifier clientIdentifier, final RequestIdentifier requestIdentifier, final Object request, final Executor streamExecutor) throws IOException {
-        }
-
-        public void sendCancelRequest(final ClientIdentifier clientIdentifier, final RequestIdentifier requestIdentifier, final boolean mayInterrupt) throws IOException {
-        }
-
-        public ClientIdentifier openClient() 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;
-        }
-    }
-
-    public class BufferedByteMessageOutput implements ByteMessageOutput, OutputAction {
-        private final int bufsize;
-        private final List<byte[]> bufferList = new ArrayList<byte[]>();
-        private int sizeOfLast;
-
-        public BufferedByteMessageOutput(final int bufsize) {
-            this.bufsize = bufsize;
-        }
-
-        public void write(int b) throws IOException {
-            final byte[] last = bufferList.get(bufferList.size());
-            if (sizeOfLast == last.length) {
-                final byte[] bytes = new byte[bufsize];
-                bufferList.add(bytes);
-                bytes[0] = (byte) b;
-                sizeOfLast = 1;
-            } else {
-                last[sizeOfLast++] = (byte) b;
-            }
-        }
-
-        public void write(byte[] b) throws IOException {
-            write(b, 0, b.length);
-        }
-
-        public void write(byte[] b, int offs, int len) throws IOException {
-            byte[] bytes = bufferList.get(bufferList.size());
-            while (len > 0) {
-                final int copySize = bytes.length - sizeOfLast;
-                if (len <= copySize) {
-                    System.arraycopy(b, offs, bytes, sizeOfLast, len);
-                    sizeOfLast += len;
-                    return;
-                } else {
-                    System.arraycopy(b, offs, bytes, sizeOfLast, copySize);
-                    bytes = new byte[bufsize];
-                    bufferList.add(bytes);
-                    sizeOfLast = 0;
-                    len -= copySize;
-                    offs += copySize;
-                }
-            }
-        }
-
-        public void commit() throws IOException {
-            outgoingQueue.add(this);
-        }
-
-        public int getBytesWritten() throws IOException {
-            Iterator<byte[]> it = bufferList.iterator();
-            if (! it.hasNext()) {
-                return 0;
-            }
-            int t = 0;
-            for (;;) {
-                byte[] b = it.next();
-                if (it.hasNext()) {
-                    t += b.length;
-                } else {
-                    return t + sizeOfLast;
-                }
-            }
-        }
-
-        public void close() throws IOException {
-            bufferList.clear();
-        }
-
-        public void flush() throws IOException {
-        }
-
-        public void run(ByteMessageOutput output) throws IOException {
-            final Iterator<byte[]> iterator = bufferList.iterator();
-            if (! iterator.hasNext()) {
-                return;
-            }
-            for (;;) {
-                byte[] bytes = iterator.next();
-                if (iterator.hasNext()) {
-                    output.write(bytes);
-                } else {
-                    output.write(bytes, 0, sizeOfLast);
-                    return;
-                }
-            }
-        }
-    }
-
-    private final class OutgoingActionHttpMessage extends AbstractOutgoingHttpMessage {
-        private final List<OutputAction> actions;
-
-        public OutgoingActionHttpMessage(final List<OutputAction> actions) {
-            this.actions = actions;
-        }
-
-        public void writeMessageData(ByteMessageOutput byteOutput) throws IOException {
-            final ObjectMessageOutput msgOut = protocolContext.getMessageOutput(byteOutput);
-            msgOut.writeInt(PROTOCOL_VERSION);
-            msgOut.commit();
-            for (OutputAction action : actions) {
-                action.run(byteOutput);
-            }
-        }
-    }
-}

Modified: remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java
===================================================================
--- remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java	2008-04-19 03:29:10 UTC (rev 4022)
+++ remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java	2008-04-19 03:58:16 UTC (rev 4023)
@@ -4,9 +4,10 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.List;
+import java.util.Random;
 import java.util.concurrent.ConcurrentMap;
+import java.security.SecureRandom;
 import org.jboss.cx.remoting.http.AbstractHttpChannel;
-import org.jboss.cx.remoting.http.HttpProtocolSupport;
 import org.jboss.cx.remoting.http.cookie.Cookie;
 import org.jboss.cx.remoting.http.cookie.CookieParser;
 import org.jboss.cx.remoting.http.spi.AbstractIncomingHttpMessage;
@@ -46,18 +47,10 @@
 
     // Dependencies
 
-    private HttpProtocolSupport protocolSupport;
     private RemotingHttpServerContext serverContext;
     private HttpContext httpContext;
+    private Random random;
 
-    public HttpProtocolSupport getProtocolSupport() {
-        return protocolSupport;
-    }
-
-    public void setProtocolSupport(final HttpProtocolSupport protocolSupport) {
-        this.protocolSupport = protocolSupport;
-    }
-
     public RemotingHttpServerContext getServerContext() {
         return serverContext;
     }
@@ -74,12 +67,23 @@
         this.httpContext = httpContext;
     }
 
+    public Random getRandom() {
+        return random;
+    }
+
+    public void setRandom(final Random random) {
+        this.random = random;
+    }
+
     // Lifecycle
 
     public void create() {
         if (serverContext == null) {
             throw new NullPointerException("serverContext is null");
         }
+        if (random == null) {
+            random = new SecureRandom();
+        }
     }
 
     public void start() {
@@ -97,6 +101,7 @@
     public void destroy() {
         serverContext = null;
         httpContext = null;
+        random = null;
     }
 
     // Implementation
@@ -147,7 +152,7 @@
             final StringBuilder setCookieBuilder = new StringBuilder(60);
             setCookieBuilder.append("JSESSIONID=");
             for (;;) {
-                String jsessionid = protocolSupport.generateSessionId();
+                String jsessionid = generateSessionId();
                 if (sessions.putIfAbsent(jsessionid, context) == null) {
                     setCookieBuilder.append(jsessionid);
                     break;
@@ -169,4 +174,15 @@
             IoUtil.closeSafely(outputStream);
         }
     }
+
+    private String generateSessionId() {
+        final byte[] bytes = new byte[16];
+        StringBuilder builder = new StringBuilder(bytes.length * 2);
+        random.nextBytes(bytes);
+        for (byte b : bytes) {
+            builder.append(Character.forDigit(b >>> 4 & 15, 16));
+            builder.append(Character.forDigit(b & 15, 16));
+        }
+        return builder.toString();
+    }
 }




More information about the jboss-remoting-commits mailing list