[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    svn commit: r452948 - in
From:       olegk () apache ! org
Date:       2006-10-04 17:33:59
Message-ID: 20061004173400.4C7461A981D () eris ! apache ! org
[Download RAW message or body]

Author: olegk
Date: Wed Oct  4 10:33:58 2006
New Revision: 452948

URL: http://svn.apache.org/viewvc?view=rev&rev=452948
Log:
* Some refactoring of the existing NIO code
* I/O reactor is now able to asynchronously establish outgoing connections (first \
                cut, untested)
* Added async HTTP client connection

Added:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java \
(with props)  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java \
(with props)  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java \
(with props)  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java
                
      - copied, changed from r450187, \
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOSession.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestHandle.java \
(with props)  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java \
(with props) Removed:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOSession.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultListeningIOReactor.java
 Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncEchoServer.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpServer.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/ElementalEchoServer.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/IOReactor.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataReceiver.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataTransmitter.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpServerConnection.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionHandle.java


Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncEchoServer.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/examples/org/apache/http/nio/examples/AsyncEchoServer.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncEchoServer.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncEchoServer.java \
Wed Oct  4 10:33:58 2006 @@ -10,9 +10,9 @@
 import org.apache.http.nio.IOProducer;
 import org.apache.http.nio.IOSession;
 import org.apache.http.nio.IOReactor;
+import org.apache.http.nio.impl.AbstractIOReactor;
 import org.apache.http.nio.impl.AsyncHttpDataReceiver;
 import org.apache.http.nio.impl.AsyncHttpDataTransmitter;
-import org.apache.http.nio.impl.DefaultListeningIOReactor;
 import org.apache.http.params.HttpParams;
 
 public class AsyncEchoServer {
@@ -20,9 +20,9 @@
     public static void main(String[] args) throws Exception {
         HttpParams params = new DefaultHttpParams(); 
         IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch();
-        IOReactor ioReactor = new DefaultListeningIOReactor(
-                new InetSocketAddress(8080), params);
+        IOReactor ioReactor = new AbstractIOReactor(params);
         try {
+            ioReactor.listen(new InetSocketAddress(8080));
             ioReactor.execute(ioEventDispatch);
         } catch (InterruptedIOException ex) {
             System.err.println("Interrupted");

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpServer.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/examples/org/apache/http/nio/examples/AsyncHttpServer.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpServer.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpServer.java \
Wed Oct  4 10:33:58 2006 @@ -28,8 +28,8 @@
 import org.apache.http.nio.IOProducer;
 import org.apache.http.nio.IOSession;
 import org.apache.http.nio.IOReactor;
+import org.apache.http.nio.impl.AbstractIOReactor;
 import org.apache.http.nio.impl.AsyncHttpServerConnection;
-import org.apache.http.nio.impl.DefaultListeningIOReactor;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -63,8 +63,9 @@
         globalContext.setAttribute("server.docroot", args[0]);
         
         IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch(params, \
                globalContext);
-        IOReactor ioReactor = new DefaultListeningIOReactor(new \
InetSocketAddress(8080), params); +        IOReactor ioReactor = new \
AbstractIOReactor(params);  try {
+            ioReactor.listen(new InetSocketAddress(8080));
             ioReactor.execute(ioEventDispatch);
         } catch (InterruptedIOException ex) {
             System.err.println("Interrupted");

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/ElementalEchoServer.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/examples/org/apache/http/nio/examples/ElementalEchoServer.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/ElementalEchoServer.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/ElementalEchoServer.java \
Wed Oct  4 10:33:58 2006 @@ -10,7 +10,7 @@
 import org.apache.http.nio.IOEventDispatch;
 import org.apache.http.nio.IOSession;
 import org.apache.http.nio.IOReactor;
-import org.apache.http.nio.impl.DefaultListeningIOReactor;
+import org.apache.http.nio.impl.AbstractIOReactor;
 import org.apache.http.params.HttpParams;
 
 public class ElementalEchoServer {
@@ -18,8 +18,8 @@
     public static void main(String[] args) throws Exception {
         HttpParams params = new DefaultHttpParams(); 
         IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch();
-        IOReactor ioReactor = new DefaultListeningIOReactor(
-                new InetSocketAddress(8080), params);
+        IOReactor ioReactor = new AbstractIOReactor(params);
+        ioReactor.listen(new InetSocketAddress(8080));
         try {
             ioReactor.execute(ioEventDispatch);
         } catch (InterruptedIOException ex) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/IOReactor.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/IOReactor.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/IOReactor.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/IOReactor.java \
Wed Oct  4 10:33:58 2006 @@ -30,6 +30,7 @@
 package org.apache.http.nio;
 
 import java.io.IOException;
+import java.net.SocketAddress;
 
 public interface IOReactor {
 
@@ -37,6 +38,12 @@
         throws IOException;
 
     void shutdown() 
+        throws IOException;
+    
+    SessionRequest connect(SocketAddress remoteAddress, SocketAddress localAddress) 
+        throws IOException;
+        
+    void listen(SocketAddress address) 
         throws IOException;
     
 }

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java?view=auto&rev=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java \
                (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java \
Wed Oct  4 10:33:58 2006 @@ -0,0 +1,48 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio;
+
+public interface SessionRequest {
+
+    boolean isCompleted();
+    
+    IOSession getSession();
+
+    void waitFor() throws InterruptedException;
+    
+    void setConnectTimeout(int timeout);
+    
+    int getConnectTimeout();
+    
+    void setCallback(SessionRequestCallback callback);
+    
+    void cancel();
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java?view=auto&rev=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java \
                (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java \
Wed Oct  4 10:33:58 2006 @@ -0,0 +1,38 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio;
+
+public interface SessionRequestCallback {
+
+    void completed(SessionRequest request);
+    
+    void timeout(SessionRequest request);
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/AbstractIOReactor.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.java \
Wed Oct  4 10:33:58 2006 @@ -31,6 +31,7 @@
 
 import java.io.IOException;
 import java.net.Socket;
+import java.net.SocketAddress;
 import java.nio.channels.CancelledKeyException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
@@ -42,45 +43,43 @@
 import org.apache.http.nio.IOEventDispatch;
 import org.apache.http.nio.IOReactor;
 import org.apache.http.nio.IOSession;
+import org.apache.http.nio.SessionRequest;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
 
-public abstract class AbstractIOReactor implements IOReactor {
+public class AbstractIOReactor implements IOReactor {
 
     public static int TIMEOUT_CHECK_INTERVAL = 1000;
     
     private volatile boolean closed = false;
+    
+    private final HttpParams params;
     private final Selector selector;
     private final SessionSet sessions;
     private final SessionQueue closedSessions;
+    
     private long lastTimeoutCheck;
     
     private IOEventDispatch eventDispatch = null;
     
-    public AbstractIOReactor() throws IOException {
+    public AbstractIOReactor(final HttpParams params) throws IOException {
         super();
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        this.params = params;
         this.selector = Selector.open();
         this.sessions = new SessionSet();
         this.closedSessions = new SessionQueue();
         this.lastTimeoutCheck = System.currentTimeMillis();
     }
 
-    protected abstract void onExecute() throws IOException;
-    
-    protected abstract void onShutdown() throws IOException;
-    
-    protected abstract void onNewSocket(Socket socket) throws IOException;
-
-    protected Selector getSelector() {
-        return this.selector;
-    }
-    
-    public synchronized void execute(final IOEventDispatch eventDispatch) throws \
IOException { +    public void execute(final IOEventDispatch eventDispatch) throws \
IOException {  if (eventDispatch == null) {
             throw new IllegalArgumentException("Event dispatcher may not be null");
         }
         this.eventDispatch = eventDispatch;
         
-        onExecute();
-        
         try {
             for (;;) {
                 int readyCount = this.selector.select(TIMEOUT_CHECK_INTERVAL);
@@ -96,7 +95,7 @@
                     this.lastTimeoutCheck = currentTime;
                     Set keys = this.selector.keys();
                     if (keys != null) {
-                        processSessionTimeouts(keys);
+                        processTimeouts(keys);
                     }
                 }
                 
@@ -105,7 +104,6 @@
             }
         } finally {
             closeSessions();
-            this.eventDispatch = null;
         }
     }
     
@@ -121,34 +119,50 @@
 
     private void processEvent(final SelectionKey key) throws IOException {
         try {
+            
             if (key.isAcceptable()) {
                 
                 ServerSocketChannel serverChannel = (ServerSocketChannel) \
key.channel();  SocketChannel socketChannel = serverChannel.accept();
                 if (socketChannel != null) {
-                    
                     // Configure new socket
                     onNewSocket(socketChannel.socket());
                     // Register new channel with the selector
                     socketChannel.configureBlocking(false);
                     SelectionKey newkey = socketChannel.register(this.selector, 0);
+                    // Set up new session
+                    IOSession session = newSession(newkey);
+
+                    // Attach session handle to the selection key
+                    SessionHandle handle = new SessionHandle(session); 
+                    newkey.attach(handle);
                     
+                    this.eventDispatch.connected(session);
+                }
+            }
+            
+            if (key.isConnectable()) {
+
+                SocketChannel socketChannel = (SocketChannel) key.channel();
+                if (socketChannel != null) {
+                    // Configure new socket
+                    onNewSocket(socketChannel.socket());
                     // Set up new session
-                    IOSession session = new DefaultIOSession(newkey, new \
SessionClosedCallback() { +                    IOSession session = newSession(key);
 
-                        public void sessionClosed(IOSession session) {
-                            closedSessions.push(session);
-                        }
-                        
-                    });
-                    this.sessions.add(session);
+                    // Get request handle
+                    SessionRequestHandle requestHandle = (SessionRequestHandle) \
key.attachment(); +                    SessionRequestImpl sessionRequest = \
requestHandle.getSessionRequest();  
                     // Attach session handle to the selection key
                     SessionHandle handle = new SessionHandle(session); 
-                    newkey.attach(handle);
+                    key.attach(handle);
                     
                     this.eventDispatch.connected(session);
+                    
+                    sessionRequest.completed(session);
                 }
+
             }
             
             if (key.isReadable()) {
@@ -177,20 +191,56 @@
         }
     }
 
-    private void processSessionTimeouts(final Set keys) {
+    private IOSession newSession(final SelectionKey key) throws IOException {
+        IOSession session = new IOSessionImpl(key, new SessionClosedCallback() {
+
+            public void sessionClosed(IOSession session) {
+                closedSessions.push(session);
+            }
+            
+        });
+        session.setSocketTimeout(HttpConnectionParams.getSoTimeout(this.params));
+        this.sessions.add(session);
+        return session;
+    }
+    
+    protected void onNewSocket(final Socket socket) throws IOException {
+        socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(this.params));
+        socket.setSoTimeout(HttpConnectionParams.getSoTimeout(this.params));
+        int linger = HttpConnectionParams.getLinger(this.params);
+        if (linger >= 0) {
+            socket.setSoLinger(linger > 0, linger);
+        }
+    }
+
+    private void processTimeouts(final Set keys) {
         long now = System.currentTimeMillis();
         for (Iterator it = keys.iterator(); it.hasNext();) {
             SelectionKey key = (SelectionKey) it.next();
-            SessionHandle handle = (SessionHandle) key.attachment();
-            if (handle != null) {
+            Object attachment = key.attachment();
+            
+            if (attachment instanceof SessionHandle) {
+                SessionHandle handle = (SessionHandle) key.attachment();
                 IOSession session = handle.getSession();
                 int timeout = session.getSocketTimeout();
                 if (timeout > 0) {
-                    if (handle.getLastRead() + timeout < now) {
+                    if (handle.getLastReadTime() + timeout < now) {
                         this.eventDispatch.timeout(session);
                     }
                 }
             }
+
+            if (attachment instanceof SessionRequestHandle) {
+                SessionRequestHandle handle = (SessionRequestHandle) \
key.attachment(); +                SessionRequestImpl sessionRequest = \
handle.getSessionRequest(); +                int timeout = \
sessionRequest.getConnectTimeout(); +                if (timeout > 0) {
+                    if (handle.getRequestTime() + timeout < now) {
+                        sessionRequest.timeout();
+                    }
+                }
+            }
+            
         }
     }
 
@@ -215,6 +265,34 @@
         this.sessions.clear();
     }
     
+    public void listen(
+            final SocketAddress address) throws IOException {
+        ServerSocketChannel serverChannel = ServerSocketChannel.open();
+        serverChannel.configureBlocking(false);
+        serverChannel.socket().bind(address);
+        SelectionKey key = serverChannel.register(this.selector, \
SelectionKey.OP_ACCEPT); +        key.attach(null);
+    }
+
+    public SessionRequest connect(
+            final SocketAddress remoteAddress, 
+            final SocketAddress localAddress) throws IOException {
+        SocketChannel socketChannel = SocketChannel.open();
+        socketChannel.configureBlocking(false);
+        if (localAddress != null) {
+            socketChannel.socket().bind(localAddress);
+        }
+        socketChannel.connect(remoteAddress);
+        SelectionKey key = socketChannel.register(this.selector, \
SelectionKey.OP_CONNECT); +        
+        SessionRequestImpl sessionRequest = new SessionRequestImpl(key);
+        sessionRequest.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(this.params));
 +
+        SessionRequestHandle requestHandle = new \
SessionRequestHandle(sessionRequest);  +        key.attach(requestHandle);
+        return sessionRequest;
+    }
+
     public void shutdown() throws IOException {
         if (this.closed) {
             return;
@@ -222,7 +300,6 @@
         this.closed = true;
         // Stop dispatching I/O events
         this.selector.close();
-        onShutdown();
     }
-    
+        
 }

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java?view=auto&rev=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java \
                (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java \
Wed Oct  4 10:33:58 2006 @@ -0,0 +1,123 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.nio.impl;
+
+import java.io.IOException;
+
+import org.apache.http.HttpHost;
+import org.apache.http.impl.AbstractHttpClientConnection;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.entity.DefaultEntityDeserializer;
+import org.apache.http.impl.entity.DefaultEntitySerializer;
+import org.apache.http.nio.IOConsumer;
+import org.apache.http.nio.IOProducer;
+import org.apache.http.nio.IOSession;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+public class AsyncHttpClientConnection extends AbstractHttpClientConnection {
+
+    private final HttpHost targetHost;
+    private final IOSession session;
+    private final IOProducer ioProducer;
+    private final IOConsumer ioConsumer;
+    
+    public AsyncHttpClientConnection(
+            final HttpHost targetHost, 
+            final IOSession session, 
+            final HttpParams params) {
+        super();
+        if (targetHost == null) {
+            throw new IllegalArgumentException("Target host may not be null");
+        }
+        if (session == null) {
+            throw new IllegalArgumentException("IO session may not be null");
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        this.session = session;
+        this.targetHost = targetHost;
+        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
+        
+        AsyncHttpDataReceiver datareceiver = new AsyncHttpDataReceiver(
+                session, buffersize);
+        datareceiver.reset(params);
+        AsyncHttpDataTransmitter datatransmitter = new AsyncHttpDataTransmitter(
+                session, buffersize);
+        datatransmitter.reset(params);
+
+        this.ioConsumer = datareceiver;
+        this.ioProducer = datatransmitter;
+        
+        setHttpDataReceiver(datareceiver);
+        setHttpDataTransmitter(datatransmitter);
+        setResponseFactory(new DefaultHttpResponseFactory());
+        setEntitySerializer(new DefaultEntitySerializer());
+        setEntityDeserializer(new DefaultEntityDeserializer());
+    }
+
+    public HttpHost getTargetHost() {
+        return this.targetHost;
+    }
+    
+    public IOConsumer getIOConsumer() {
+        return this.ioConsumer;
+    }
+
+    public IOProducer getIOProducer() {
+        return this.ioProducer;
+    }
+
+    protected void assertOpen() throws IllegalStateException {
+        if (this.session.isClosed()) {
+            throw new IllegalStateException("Connection is closed");
+        }
+    }
+
+    public void close() throws IOException {
+        flush();
+        shutdown();
+    }
+
+    public boolean isOpen() {
+        return !this.session.isClosed();
+    }
+
+    public boolean isStale() {
+        return this.session.isClosed();
+    }
+
+    public void shutdown() throws IOException {
+        this.ioProducer.shutdown();
+        this.ioConsumer.shutdown();
+        this.session.close();
+    }
+
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataReceiver.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/AsyncHttpDataReceiver.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataReceiver.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataReceiver.java \
Wed Oct  4 10:33:58 2006 @@ -1,3 +1,31 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
 package org.apache.http.nio.impl;
 
 import java.io.IOException;

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataTransmitter.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/AsyncHttpDataTransmitter.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataTransmitter.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpDataTransmitter.java \
Wed Oct  4 10:33:58 2006 @@ -1,3 +1,31 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
 package org.apache.http.nio.impl;
 
 import java.io.IOException;

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpServerConnection.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/AsyncHttpServerConnection.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpServerConnection.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpServerConnection.java \
Wed Oct  4 10:33:58 2006 @@ -1,3 +1,31 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
 package org.apache.http.nio.impl;
 
 import java.io.IOException;

Copied: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java \
(from r450187, jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOSession.java)
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/IOSessionImpl.java?view=diff&rev=452948&p1=jakarta \
/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/Defau \
ltIOSession.java&r1=450187&p2=jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOSession.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java \
Wed Oct  4 10:33:58 2006 @@ -38,7 +38,7 @@
 
 import org.apache.http.nio.IOSession;
 
-public class DefaultIOSession implements IOSession {
+public class IOSessionImpl implements IOSession {
     
     private volatile boolean closed = false;
     
@@ -48,7 +48,7 @@
     
     private int socketTimeout;
     
-    public DefaultIOSession(final SelectionKey key, final SessionClosedCallback \
callback) { +    public IOSessionImpl(final SelectionKey key, final \
SessionClosedCallback callback) {  super();
         if (key == null) {
             throw new IllegalArgumentException("Selection key may not be null");

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionHandle.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/SessionHandle.java?view=diff&rev=452948&r1=452947&r2=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionHandle.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionHandle.java \
Wed Oct  4 10:33:58 2006 @@ -34,10 +34,10 @@
 public class SessionHandle {
 
     private final IOSession session;
-    private final long started;
+    private final long startedTime;
 
-    private long lastRead;
-    private long lastWrite;
+    private long lastReadTime;
+    private long lastWriteTime;
     
     public SessionHandle(final IOSession session) {
         super();
@@ -46,33 +46,33 @@
         }
         this.session = session;
         long now = System.currentTimeMillis();
-        this.started = now;
-        this.lastRead = now;
-        this.lastWrite = now;
+        this.startedTime = now;
+        this.lastReadTime = now;
+        this.lastWriteTime = now;
     }
 
     public IOSession getSession() {
         return this.session;
     }
 
-    public long getStarted() {
-        return this.started;
+    public long getStartedTime() {
+        return this.startedTime;
     }
 
-    public long getLastRead() {
-        return this.lastRead;
+    public long getLastReadTime() {
+        return this.lastReadTime;
     }
 
-    public long getLastWrite() {
-        return this.lastWrite;
+    public long getLastWriteTime() {
+        return this.lastWriteTime;
     }
     
     public void resetLastRead() {
-        this.lastRead = System.currentTimeMillis();
+        this.lastReadTime = System.currentTimeMillis();
     }
     
     public void resetLastWrite() {
-        this.lastWrite = System.currentTimeMillis();
+        this.lastWriteTime = System.currentTimeMillis();
     }
     
 }

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestHandle.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/impl/SessionRequestHandle.java?view=auto&rev=452948 \
                ==============================================================================
                
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestHandle.java \
                (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestHandle.java \
Wed Oct  4 10:33:58 2006 @@ -0,0 +1,54 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio.impl;
+
+public class SessionRequestHandle {
+
+    private final SessionRequestImpl sessionRequest;
+    private final long requestTime;
+    
+    public SessionRequestHandle(final SessionRequestImpl sessionRequest) {
+        super();
+        if (sessionRequest == null) {
+            throw new IllegalArgumentException("Session request may not be null");
+        }
+        this.sessionRequest = sessionRequest;
+        this.requestTime = System.currentTimeMillis();
+    }
+    
+    public SessionRequestImpl getSessionRequest() {
+        return this.sessionRequest;
+    }
+    
+    public long getRequestTime() {
+        return this.requestTime;
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestHandle.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestHandle.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java?view=auto&rev=452948
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java \
                (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java \
Wed Oct  4 10:33:58 2006 @@ -0,0 +1,129 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio.impl;
+
+import java.nio.channels.SelectionKey;
+
+import org.apache.http.nio.SessionRequest;
+import org.apache.http.nio.IOSession;
+import org.apache.http.nio.SessionRequestCallback;
+
+public class SessionRequestImpl implements SessionRequest {
+
+    private volatile boolean completed;
+
+    private final SelectionKey key;
+    
+    private int connectTimeout;
+    private SessionRequestCallback callback;
+    private IOSession session = null;
+    
+    public SessionRequestImpl(final SelectionKey key) {
+        super();
+        this.key = key;
+        this.connectTimeout = 0;
+    }
+    
+    public boolean isCompleted() {
+        return this.completed;
+    }
+    
+    public void waitFor() throws InterruptedException {
+        if (this.completed) {
+            return;
+        }
+        synchronized (this) {
+            while (!this.completed) {
+                wait();
+            }
+        }
+    }
+    
+    public IOSession getSession() {
+        synchronized (this) {
+            return this.session;
+        }
+    }
+    
+    public void completed(final IOSession session) {
+        if (session == null) {
+            throw new IllegalArgumentException("Session may not be null");
+        }
+        if (this.completed) {
+            throw new IllegalStateException("Session request already completed");
+        }
+        this.completed = true;
+        synchronized (this) {
+            this.session = session;
+            if (this.callback != null) {
+                this.callback.completed(this);
+            }
+            notifyAll();
+        }
+    }
+ 
+    public synchronized void timeout() {
+        if (this.completed) {
+            throw new IllegalStateException("Session request already completed");
+        }
+        this.completed = true;
+        synchronized (this) {
+            if (this.callback != null) {
+                this.callback.timeout(this);
+            }
+            notifyAll();
+        }
+    }
+ 
+    public int getConnectTimeout() {
+        return this.connectTimeout;
+    }
+
+    public void setConnectTimeout(int timeout) {
+        if (this.connectTimeout != timeout) {
+            this.connectTimeout = timeout;
+            this.key.selector().wakeup();
+        }
+    }
+
+    public void setCallback(final SessionRequestCallback callback) {
+        if (this.completed) {
+            throw new IllegalStateException("Session request already completed");
+        }
+        synchronized (this) {
+            this.callback = callback;
+        }
+    }
+
+    public void cancel() {
+        this.key.cancel();
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic