From httpclient-commits-returnsmithmelissa@example.com Wed Oct 04 17:34:05 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 35998 invoked from network); 4 Oct 2006 17:34:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 4 Oct 2006 17:34:04 -0000 Received: (qmail 19778 invoked by uid 500); 4 Oct 2006 17:34:04 -0000 Mailing-List: contact smithmelissa@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:smithmelissa@example.com> List-Unsubscribe: <mailto:smithmelissa@example.com> List-Post: <mailto:smithmelissa@example.com> List-Id: <httpclient-commits.jakarta.apache.org> Reply-To: smithmelissa@example.com Delivered-To: mailing list smithmelissa@example.com Received: (qmail 19767 invoked by uid 99); 4 Oct 2006 17:34:04 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Oct 2006 10:34:04 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [83.161.120.155] ([83.161.120.155:54761] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 83.161.120.155 r(12930)) with ESMTP id 78/93-17684-A80F3254 for <smithmelissa@example.com>; Wed, 04 Oct 2006 10:34:02 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 4C7461A981D; Wed, 4 Oct 2006 10:34:00 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r452948 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src: examples/org/apache/http/nio/examples/ main/java/org/apache/http/nio/ main/java/org/apache/http/nio/impl/ Date: Wed, 04 Oct 2006 17:33:59 -0000 To: smithmelissa@example.com From: smithmelissa@example.com X-Mailer: svnmailer-1.1.0 Message-Id: <smithmelissa@example.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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/DefaultIOSession.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 From httpclient-commits-returnsmithmelissa@example.com Wed Oct 04 17:35:48 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 36542 invoked from network); 4 Oct 2006 17:35:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 4 Oct 2006 17:35:48 -0000 Received: (qmail 22009 invoked by uid 500); 4 Oct 2006 17:35:48 -0000 Mailing-List: contact smithmelissa@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:smithmelissa@example.com> List-Unsubscribe: <mailto:smithmelissa@example.com> List-Post: <mailto:smithmelissa@example.com> List-Id: <httpclient-commits.jakarta.apache.org> Reply-To: smithmelissa@example.com Delivered-To: mailing list smithmelissa@example.com Received: (qmail 21997 invoked by uid 99); 4 Oct 2006 17:35:48 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Oct 2006 10:35:48 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [83.161.120.155] ([83.161.120.155:53933] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 83.161.120.155 r(12930)) with ESMTP id 03/A3-17684-3F0F3254 for <smithmelissa@example.com>; Wed, 04 Oct 2006 10:35:47 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B91621A981A; Wed, 4 Oct 2006 10:35:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r452949 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src: examples/org/apache/http/nio/examples/ main/java/org/apache/http/nio/impl/ Date: Wed, 04 Oct 2006 17:35:44 -0000 To: smithmelissa@example.com From: smithmelissa@example.com X-Mailer: svnmailer-1.1.0 Message-Id: <smithmelissa@example.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Wed Oct 4 10:35:43 2006 New Revision: 452949 URL: http://svn.apache.org/viewvc?view=rev&rev=452949 Log: Renamed AbstractIOReactor (which is no longer abstract) to DefaultIOReactor Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java - copied, changed from r452948, jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.java Removed: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.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 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=452949&r1=452948&r2=452949 ============================================================================== --- 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:35:43 2006 @@ -10,7 +10,7 @@ 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.DefaultIOReactor; import org.apache.http.nio.impl.AsyncHttpDataReceiver; import org.apache.http.nio.impl.AsyncHttpDataTransmitter; import org.apache.http.params.HttpParams; @@ -20,7 +20,7 @@ public static void main(String[] args) throws Exception { HttpParams params = new DefaultHttpParams(); IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch(); - IOReactor ioReactor = new AbstractIOReactor(params); + IOReactor ioReactor = new DefaultIOReactor(params); try { ioReactor.listen(new InetSocketAddress(8080)); ioReactor.execute(ioEventDispatch); 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=452949&r1=452948&r2=452949 ============================================================================== --- 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:35:43 2006 @@ -28,7 +28,7 @@ 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.DefaultIOReactor; import org.apache.http.nio.impl.AsyncHttpServerConnection; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; @@ -63,7 +63,7 @@ globalContext.setAttribute("server.docroot", args[0]); IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch(params, globalContext); - IOReactor ioReactor = new AbstractIOReactor(params); + IOReactor ioReactor = new DefaultIOReactor(params); try { ioReactor.listen(new InetSocketAddress(8080)); ioReactor.execute(ioEventDispatch); 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=452949&r1=452948&r2=452949 ============================================================================== --- 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:35:43 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.AbstractIOReactor; +import org.apache.http.nio.impl.DefaultIOReactor; import org.apache.http.params.HttpParams; public class ElementalEchoServer { @@ -18,7 +18,7 @@ public static void main(String[] args) throws Exception { HttpParams params = new DefaultHttpParams(); IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch(); - IOReactor ioReactor = new AbstractIOReactor(params); + IOReactor ioReactor = new DefaultIOReactor(params); ioReactor.listen(new InetSocketAddress(8080)); try { ioReactor.execute(ioEventDispatch); Copied: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java (from r452948, 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/DefaultIOReactor.java?view=diff&rev=452949&p1=jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AbstractIOReactor.java&r1=452948&p2=jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java&r2=452949 ============================================================================== --- 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/DefaultIOReactor.java Wed Oct 4 10:35:43 2006 @@ -47,7 +47,7 @@ import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; -public class AbstractIOReactor implements IOReactor { +public class DefaultIOReactor implements IOReactor { public static int TIMEOUT_CHECK_INTERVAL = 1000; @@ -62,7 +62,7 @@ private IOEventDispatch eventDispatch = null; - public AbstractIOReactor(final HttpParams params) throws IOException { + public DefaultIOReactor(final HttpParams params) throws IOException { super(); if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); From httpclient-commits-returnsmithmelissa@example.com Thu Oct 05 10:13:09 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 4093 invoked from network); 5 Oct 2006 10:13:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 5 Oct 2006 10:13:09 -0000 Received: (qmail 60451 invoked by uid 500); 5 Oct 2006 10:13:09 -0000 Mailing-List: contact smithmelissa@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:smithmelissa@example.com> List-Unsubscribe: <mailto:smithmelissa@example.com> List-Post: <mailto:smithmelissa@example.com> List-Id: <httpclient-commits.jakarta.apache.org> Reply-To: smithmelissa@example.com Delivered-To: mailing list smithmelissa@example.com Received: (qmail 60440 invoked by uid 99); 5 Oct 2006 10:13:08 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Oct 2006 03:13:08 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [83.161.120.155] ([83.161.120.155:52329] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 83.161.120.155 r(12930)) with ESMTP id C9/A2-20288-DAAD4254 for <smithmelissa@example.com>; Thu, 05 Oct 2006 03:13:05 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B9F641A981C; Thu, 5 Oct 2006 03:12:33 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453172 - in /jakarta/httpcomponents/httpcore/trunk: module-main/src/examples/org/apache/http/examples/ module-main/src/main/java/org/apache/http/ module-main/src/main/java/org/apache/http/impl/ module-main/src/main/java/org/apache/http/pro... Date: Thu, 05 Oct 2006 10:12:33 -0000 To: smithmelissa@example.com From: smithmelissa@example.com X-Mailer: svnmailer-1.1.0 Message-Id: <smithmelissa@example.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Thu Oct 5 03:12:32 2006 New Revision: 453172 URL: http://svn.apache.org/viewvc?view=rev&rev=453172 Log: [HTTPCLIENT-602] refactor HttpClientConnection and HttpProxyConnection Changelog: ---------- * Removed #getTargetHost() method from the HttpClientConnection interface Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java Thu Oct 5 03:12:32 2006 @@ -84,9 +84,12 @@ httpexecutor.setParams(params); HttpContext context = new HttpExecutionContext(null); - HttpHost host = new HttpHost("localhost", 8080); + context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, host); + DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); + ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); + try { String[] targets = { @@ -94,12 +97,10 @@ "/servlets-examples/servlet/RequestInfoExample", "/somewhere%20in%20pampa"}; - ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); - for (int i = 0; i < targets.length; i++) { if (!conn.isOpen()) { Socket socket = new Socket(host.getHostName(), host.getPort()); - conn.bind(socket, host, params); + conn.bind(socket, params); } HttpGet request = new HttpGet(targets[i]); System.out.println(">> Request URI: " + request.getRequestLine().getUri()); Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java Thu Oct 5 03:12:32 2006 @@ -91,7 +91,11 @@ HttpContext context = new HttpExecutionContext(null); HttpHost host = new HttpHost("localhost", 8080); + context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, host); + DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); + ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); + try { HttpEntity[] requestBodies = { @@ -105,12 +109,10 @@ .getBytes("UTF-8")), -1) }; - ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); - for (int i = 0; i < requestBodies.length; i++) { if (!conn.isOpen()) { Socket socket = new Socket(host.getHostName(), host.getPort()); - conn.bind(socket, host, params); + conn.bind(socket, params); } HttpPost request = new HttpPost("/servlets-examples/servlet/RequestInfoExample"); request.setEntity(requestBodies[i]); Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java Thu Oct 5 03:12:32 2006 @@ -48,13 +48,6 @@ public interface HttpClientConnection extends HttpConnection { /** - * Returns the current target host. - * - * @return the target host of this connection - */ - HttpHost getTargetHost(); - - /** * Checks if response data is available from the connection. May wait for * the specified time until some data becomes available. Note that some * implementations may completely ignore the timeout parameter. Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java Thu Oct 5 03:12:32 2006 @@ -32,7 +32,6 @@ import java.io.IOException; import java.net.Socket; -import org.apache.http.HttpHost; import org.apache.http.params.HttpParams; /** @@ -52,9 +51,8 @@ public void bind( final Socket socket, - final HttpHost targethost, final HttpParams params) throws IOException { - super.bind(socket, targethost, params); + super.bind(socket, params); } } Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java Thu Oct 5 03:12:32 2006 @@ -32,7 +32,6 @@ import java.io.IOException; import java.net.Socket; -import org.apache.http.HttpHost; import org.apache.http.impl.entity.DefaultEntityDeserializer; import org.apache.http.impl.entity.DefaultEntitySerializer; import org.apache.http.impl.io.SocketHttpDataReceiver; @@ -54,8 +53,6 @@ */ public class SocketHttpClientConnection extends AbstractHttpClientConnection { - private HttpHost targethost = null; - protected volatile boolean open; protected Socket socket = null; @@ -77,14 +74,10 @@ protected void bind( final Socket socket, - final HttpHost targethost, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } - if (targethost == null) { - throw new IllegalArgumentException("Target host may not be null"); - } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } @@ -99,7 +92,6 @@ } this.socket = socket; - this.targethost = targethost; int buffersize = HttpConnectionParams.getSocketBufferSize(params); HttpDataTransmitter transmitter = new SocketHttpDataTransmitter(socket, buffersize); @@ -116,10 +108,6 @@ this.open = true; } - public HttpHost getTargetHost() { - return this.targethost; - } - public boolean isOpen() { return this.open; } Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java Thu Oct 5 03:12:32 2006 @@ -29,14 +29,8 @@ package org.apache.http.protocol; -import java.io.IOException; - -import org.apache.http.HttpException; -import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; -import org.apache.http.HttpResponse; import org.apache.http.HttpResponseInterceptor; - /** * Performs interceptor processing of requests and responses. Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java Thu Oct 5 03:12:32 2006 @@ -141,7 +141,6 @@ throw new IllegalArgumentException("HTTP context may not be null"); } - context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, conn.getTargetHost()); context.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn); context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request); Modified: jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java (original) +++ jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java Thu Oct 5 03:12:32 2006 @@ -112,12 +112,14 @@ port = 80; } + this.context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, targetHost); + for (int i = 0; i < count; i++) { try { resetHeader(request); if (!conn.isOpen()) { Socket socket = new Socket(hostname, port); - conn.bind(socket, targetHost, params); + conn.bind(socket, params); } response = this.httpexecutor.execute(request, conn, this.context); if (this.verbosity >= 3) { Modified: jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java?view=diff&rev=453172&r1=453171&r2=453172 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java (original) +++ jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java Thu Oct 5 03:12:32 2006 @@ -71,12 +71,14 @@ HttpContext context = new HttpExecutionContext(null); DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); + context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, host); + HttpRequestFactory requestfactory = (HttpRequestFactory) beanfactory.getBean("http-request-factory"); ConnectionReuseStrategy connStrategy = (ConnectionReuseStrategy) beanfactory.getBean("conn-reuse-strategy"); try { if (!conn.isOpen()) { Socket socket = new Socket(host.getHostName(), host.getPort()); - conn.bind(socket, host, params); + conn.bind(socket, params); } HttpRequest request1 = requestfactory.newHttpRequest("GET", "/"); HttpResponse response1 = httpexec.execute(request1, conn, context); @@ -91,7 +93,7 @@ } if (!conn.isOpen()) { Socket socket = new Socket(host.getHostName(), host.getPort()); - conn.bind(socket, host, params); + conn.bind(socket, params); } HttpRequest request2 = requestfactory.newHttpRequest("GET", "/stuff"); HttpResponse response2 = httpexec.execute(request2, conn, context); From httpclient-commits-returnsmithmelissa@example.com Thu Oct 05 10:14:13 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 4626 invoked from network); 5 Oct 2006 10:14:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 5 Oct 2006 10:14:13 -0000 Received: (qmail 61698 invoked by uid 500); 5 Oct 2006 10:14:13 -0000 Mailing-List: contact smithmelissa@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:smithmelissa@example.com> List-Unsubscribe: <mailto:smithmelissa@example.com> List-Post: <mailto:smithmelissa@example.com> List-Id: <httpclient-commits.jakarta.apache.org> Reply-To: smithmelissa@example.com Delivered-To: mailing list smithmelissa@example.com Received: (qmail 61669 invoked by uid 99); 5 Oct 2006 10:14:13 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Oct 2006 03:14:13 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [83.161.120.155] ([83.161.120.155:54609] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 83.161.120.155 r(12930)) with ESMTP id 2D/A2-20288-AEAD4254 for <smithmelissa@example.com>; Thu, 05 Oct 2006 03:14:07 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 020F91A981F; Thu, 5 Oct 2006 03:13:22 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453175 - in /jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async: HttpAsyncClientConnection.java impl/SimpleHttpAsyncClientConnection.java Date: Thu, 05 Oct 2006 10:13:21 -0000 To: smithmelissa@example.com From: smithmelissa@example.com X-Mailer: svnmailer-1.1.0 Message-Id: <smithmelissa@example.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Thu Oct 5 03:13:19 2006 New Revision: 453175 URL: http://svn.apache.org/viewvc?view=rev&rev=453175 Log: [HTTPCLIENT-602] refactor HttpClientConnection and HttpProxyConnection Changelog: ---------- * Removed #getTargetHost() method from the HttpClientConnection interface Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpAsyncClientConnection.java jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpAsyncClientConnection.java Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpAsyncClientConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpAsyncClientConnection.java?view=diff&rev=453175&r1=453174&r2=453175 ============================================================================== --- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpAsyncClientConnection.java (original) +++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/HttpAsyncClientConnection.java Thu Oct 5 03:13:19 2006 @@ -45,7 +45,9 @@ public interface HttpAsyncClientConnection extends HttpClientConnection { void open(HttpParams params) throws IOException; - + + HttpHost getTargetHost(); + void setTargetHost(HttpHost targethost); } Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpAsyncClientConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpAsyncClientConnection.java?view=diff&rev=453175&r1=453174&r2=453175 ============================================================================== --- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpAsyncClientConnection.java (original) +++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpAsyncClientConnection.java Thu Oct 5 03:13:19 2006 @@ -72,9 +72,13 @@ port = 80; } Socket socket = new Socket(hostname, port); - bind(socket, this.targethost, params); + bind(socket, params); } + public HttpHost getTargetHost() { + return this.targethost; + } + public void setTargetHost(final HttpHost targethost) { if (targethost == null) { throw new IllegalArgumentException("Target host may not be null"); From httpclient-commits-returnsmithmelissa@example.com Thu Oct 05 14:42:28 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 1112 invoked from network); 5 Oct 2006 14:42:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 5 Oct 2006 14:42:28 -0000 Received: (qmail 62457 invoked by uid 500); 5 Oct 2006 14:42:28 -0000 Mailing-List: contact smithmelissa@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:smithmelissa@example.com> List-Unsubscribe: <mailto:smithmelissa@example.com> List-Post: <mailto:smithmelissa@example.com> List-Id: <httpclient-commits.jakarta.apache.org> Reply-To: smithmelissa@example.com Delivered-To: mailing list smithmelissa@example.com Received: (qmail 62434 invoked by uid 99); 5 Oct 2006 14:42:27 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Oct 2006 07:42:27 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [83.161.120.155] ([83.161.120.155:63000] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 83.161.120.155 r(12930)) with ESMTP id 77/E5-20288-FB915254 for <smithmelissa@example.com>; Thu, 05 Oct 2006 07:42:09 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 96CDA1A981A; Thu, 5 Oct 2006 07:40:40 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453255 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src: examples/org/apache/http/nio/examples/ main/java/org/apache/http/nio/ main/java/org/apache/http/nio/impl/ Date: Thu, 05 Oct 2006 14:40:40 -0000 To: smithmelissa@example.com From: smithmelissa@example.com X-Mailer: svnmailer-1.1.0 Message-Id: <smithmelissa@example.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Thu Oct 5 07:40:39 2006 New Revision: 453255 URL: http://svn.apache.org/viewvc?view=rev&rev=453255 Log: [HTTPCORE-9] Provide non-blocking (async) server side I/O transport based on NIO [HTTPCORE-10] Provide non-blocking (async) client side I/O transport based on NIO Changelog: ========= * A number of bug fixes * Correctly implemented connect finisning logic * Connect timeout does not cancel the session request. The connect timeout can be optionally increased * I/O exception that occurred during the process of establishing a connection is now correctly propagated to the caller * Added a rudimentary async client example Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java (with props) Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java?view=auto&rev=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java (added) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java Thu Oct 5 07:40:39 2006 @@ -0,0 +1,257 @@ +package org.apache.http.nio.examples; + +import java.io.IOException; +import java.io.InterruptedIOException; +import java.net.InetSocketAddress; +import java.net.SocketTimeoutException; + +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpClientConnection; +import org.apache.http.HttpConnection; +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.impl.DefaultConnectionReuseStrategy; +import org.apache.http.impl.DefaultHttpParams; +import org.apache.http.message.HttpGet; +import org.apache.http.nio.IOConsumer; +import org.apache.http.nio.IOEventDispatch; +import org.apache.http.nio.IOProducer; +import org.apache.http.nio.IOReactor; +import org.apache.http.nio.IOSession; +import org.apache.http.nio.SessionRequest; +import org.apache.http.nio.SessionRequestCallback; +import org.apache.http.nio.impl.AsyncHttpClientConnection; +import org.apache.http.nio.impl.DefaultIOReactor; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; +import org.apache.http.protocol.BasicHttpProcessor; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpExecutionContext; +import org.apache.http.protocol.HttpRequestExecutor; +import org.apache.http.protocol.RequestConnControl; +import org.apache.http.protocol.RequestContent; +import org.apache.http.protocol.RequestExpectContinue; +import org.apache.http.protocol.RequestTargetHost; +import org.apache.http.protocol.RequestUserAgent; +import org.apache.http.util.EntityUtils; + +public class AsyncHttpClient { + + public static void main(String[] args) throws Exception { + HttpParams params = new DefaultHttpParams(null); + params + .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000) + .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000) + .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024) + .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false) + .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true) + .setParameter(HttpProtocolParams.USER_AGENT, "Jakarta-HttpComponents-NIO/1.1"); + + final IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch(params); + final IOReactor ioReactor = new DefaultIOReactor(params); + + SessionRequestCallback sessionReqCallback = new DefaultSessionRequestCallback(params); + + SessionRequest req1 = ioReactor.connect( + new InetSocketAddress("www.yahoo.com", 80), null); + req1.setCallback(sessionReqCallback); + + SessionRequest req2 = ioReactor.connect( + new InetSocketAddress("www.google.com", 80), null); + req2.setCallback(sessionReqCallback); + + SessionRequest req3 = ioReactor.connect( + new InetSocketAddress("www.apache.org", 80), null); + req3.setCallback(sessionReqCallback); + + Thread ioThread = new Thread(new Runnable() { + + public void run() { + try { + + ioReactor.execute(ioEventDispatch); + } catch (InterruptedIOException ex) { + System.err.println("Interrupted"); + } catch (IOException e) { + System.err.println("I/O error: " + e.getMessage()); + } + System.out.println("Shutdown"); + } + + }); + ioThread.setDaemon(true); + ioThread.start(); + req1.waitFor(); + req2.waitFor(); + req3.waitFor(); + } + + private static final String CONSUMER = "CONSUMER"; + private static final String PRODUCER = "PRODUCER"; + private static final String CONNECTION = "CONNECTION"; + private static final String TARGET = "TARGET"; + private static final String WORKER = "WORKER"; + + static class DefaultSessionRequestCallback implements SessionRequestCallback { + + private final HttpParams params; + + public DefaultSessionRequestCallback(final HttpParams params) { + super(); + if (params == null) { + throw new IllegalArgumentException("HTTP parameters may nor be null"); + } + this.params = params; + } + + public void completed(final SessionRequest request) { + IOSession session = request.getSession(); + InetSocketAddress address = (InetSocketAddress) request.getRemoteAddress(); + + HttpHost targetHost = new HttpHost(address.getHostName(), address.getPort()); + + AsyncHttpClientConnection conn = new AsyncHttpClientConnection(session, this.params); + session.setAttribute(CONNECTION, conn); + session.setAttribute(TARGET, targetHost); + session.setAttribute(CONSUMER, conn.getIOConsumer()); + session.setAttribute(PRODUCER, conn.getIOProducer()); + + } + + public void failed(final SessionRequest request) { + IOException ex = request.getException(); + System.err.println(request.getRemoteAddress() + ": Connection failed"); + ex.printStackTrace(); + } + + public void timeout(final SessionRequest request) { + request.cancel(); + System.err.println(request.getRemoteAddress() + ": Connection timeout"); + } + + } + + static class DefaultIoEventDispatch implements IOEventDispatch { + + public DefaultIoEventDispatch(final HttpParams params) { + super(); + } + + public void connected(final IOSession session) { + + HttpClientConnection conn = (HttpClientConnection) session.getAttribute(CONNECTION); + HttpHost targetHost = (HttpHost) session.getAttribute(TARGET); + HttpContext localcontext = new HttpExecutionContext(null); + localcontext.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, targetHost); + + // Set up HTTP executor + BasicHttpProcessor httpproc = new BasicHttpProcessor(); + httpproc.addInterceptor(new RequestContent()); + httpproc.addInterceptor(new RequestTargetHost()); + httpproc.addInterceptor(new RequestConnControl()); + httpproc.addInterceptor(new RequestUserAgent()); + httpproc.addInterceptor(new RequestExpectContinue()); + HttpRequestExecutor httpexecutor = new HttpRequestExecutor(httpproc); + + Thread worker = new WorkerThread(httpexecutor, conn, localcontext); + session.setAttribute(WORKER, worker); + + worker.setDaemon(false); + worker.start(); + session.setSocketTimeout(20000); + } + + public void inputReady(final IOSession session) { + IOConsumer consumer = (IOConsumer) session.getAttribute(CONSUMER); + try { + consumer.consumeInput(); + } catch (IOException ex) { + consumer.shutdown(ex); + } + } + + public void outputReady(final IOSession session) { + IOProducer producer = (IOProducer) session.getAttribute(PRODUCER); + try { + producer.produceOutput(); + } catch (IOException ex) { + producer.shutdown(ex); + } + } + + public void timeout(final IOSession session) { + IOConsumer consumer = (IOConsumer) session.getAttribute(CONSUMER); + consumer.shutdown(new SocketTimeoutException("Socket read timeout")); + } + + public void disconnected(final IOSession session) { + HttpConnection conn = (HttpConnection) session.getAttribute(CONNECTION); + try { + conn.shutdown(); + } catch (IOException ex) { + System.err.println("I/O error while shutting down connection"); + } + + Thread worker = (Thread) session.getAttribute(WORKER); + worker.interrupt(); + } + + } + + static class WorkerThread extends Thread { + + private final HttpRequestExecutor httpexecutor; + private final HttpClientConnection conn; + private final HttpContext context; + + public WorkerThread( + final HttpRequestExecutor httpexecutor, + final HttpClientConnection conn, + final HttpContext context) { + super(); + this.httpexecutor = httpexecutor; + this.conn = conn; + this.context = context; + } + + public void run() { + System.out.println("New connection thread"); + try { + String[] targets = { + "/", + "/servlets-examples/servlet/RequestInfoExample", + "/somewhere%20in%20pampa"}; + + ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); + + for (int i = 0; i < targets.length; i++) { + HttpGet request = new HttpGet(targets[i]); + System.out.println(">> Request URI: " + request.getRequestLine().getUri()); + HttpResponse response = httpexecutor.execute(request, this.conn, this.context); + System.out.println("<< Response: " + response.getStatusLine()); + System.out.println(EntityUtils.toString(response.getEntity())); + System.out.println("=============="); + if (!connStrategy.keepAlive(response, this.context)) { + conn.close(); + System.out.println("Connection closed..."); + break; + } else { + System.out.println("Connection kept alive..."); + } + } + } catch (IOException ex) { + System.err.println("I/O error: " + ex.getMessage()); + } catch (HttpException ex) { + System.err.println("Unrecoverable HTTP protocol violation: " + ex.getMessage()); + } finally { + try { + this.conn.shutdown(); + } catch (IOException ignore) {} + } + } + + } + +} Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/examples/org/apache/http/nio/examples/AsyncHttpClient.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: 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=diff&rev=453255&r1=453254&r2=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequest.java Thu Oct 5 07:40:39 2006 @@ -29,11 +29,18 @@ package org.apache.http.nio; +import java.io.IOException; +import java.net.SocketAddress; + public interface SessionRequest { + public SocketAddress getRemoteAddress(); + boolean isCompleted(); IOSession getSession(); + + IOException getException(); void waitFor() throws InterruptedException; Modified: 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=diff&rev=453255&r1=453254&r2=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/SessionRequestCallback.java Thu Oct 5 07:40:39 2006 @@ -33,6 +33,8 @@ void completed(SessionRequest request); - void timeout(SessionRequest request); + void failed(SessionRequest request); + void timeout(SessionRequest request); + } Modified: 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=diff&rev=453255&r1=453254&r2=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/AsyncHttpClientConnection.java Thu Oct 5 07:40:39 2006 @@ -30,7 +30,6 @@ 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; @@ -43,19 +42,14 @@ 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"); } @@ -63,7 +57,6 @@ throw new IllegalArgumentException("HTTP parameters may not be null"); } this.session = session; - this.targetHost = targetHost; int buffersize = HttpConnectionParams.getSocketBufferSize(params); AsyncHttpDataReceiver datareceiver = new AsyncHttpDataReceiver( @@ -83,10 +76,6 @@ setEntityDeserializer(new DefaultEntityDeserializer()); } - public HttpHost getTargetHost() { - return this.targetHost; - } - public IOConsumer getIOConsumer() { return this.ioConsumer; } Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java?view=diff&rev=453255&r1=453254&r2=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java Thu Oct 5 07:40:39 2006 @@ -144,25 +144,34 @@ if (key.isConnectable()) { SocketChannel socketChannel = (SocketChannel) key.channel(); - if (socketChannel != null) { - // Configure new socket - onNewSocket(socketChannel.socket()); - // Set up new session - IOSession session = newSession(key); - - // Get request handle - SessionRequestHandle requestHandle = (SessionRequestHandle) key.attachment(); - SessionRequestImpl sessionRequest = requestHandle.getSessionRequest(); - - // Attach session handle to the selection key - SessionHandle handle = new SessionHandle(session); - key.attach(handle); - - this.eventDispatch.connected(session); - - sessionRequest.completed(session); + // Get request handle + SessionRequestHandle requestHandle = (SessionRequestHandle) key.attachment(); + SessionRequestImpl sessionRequest = requestHandle.getSessionRequest(); + + // Finish connection process + try { + socketChannel.finishConnect(); + } catch (IOException ex) { + sessionRequest.failed(ex); + key.cancel(); + return; } + // Configure new socket + onNewSocket(socketChannel.socket()); + // Set up new session + IOSession session = newSession(key); + + // Attach session handle to the selection key + SessionHandle handle = new SessionHandle(session); + key.attach(handle); + + // Fire the request completion notification first + sessionRequest.completed(session); + + // Followed by session connected notification + this.eventDispatch.connected(session); + } if (key.isReadable()) { @@ -182,11 +191,12 @@ } } catch (CancelledKeyException ex) { - SessionHandle handle = (SessionHandle) key.attachment(); - if (handle != null) { - key.attach(null); + Object attachment = key.attachment(); + if (attachment instanceof SessionHandle) { + SessionHandle handle = (SessionHandle) attachment; IOSession session = handle.getSession(); this.closedSessions.push(session); + key.attach(null); } } } @@ -285,7 +295,7 @@ socketChannel.connect(remoteAddress); SelectionKey key = socketChannel.register(this.selector, SelectionKey.OP_CONNECT); - SessionRequestImpl sessionRequest = new SessionRequestImpl(key); + SessionRequestImpl sessionRequest = new SessionRequestImpl(remoteAddress, key); sessionRequest.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(this.params)); SessionRequestHandle requestHandle = new SessionRequestHandle(sessionRequest); Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.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=453255&r1=453254&r2=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/IOSessionImpl.java Thu Oct 5 07:40:39 2006 @@ -38,7 +38,7 @@ import org.apache.http.nio.IOSession; -public class IOSessionImpl implements IOSession { +class IOSessionImpl implements IOSession { private volatile boolean closed = false; Modified: 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=diff&rev=453255&r1=453254&r2=453255 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java Thu Oct 5 07:40:39 2006 @@ -29,28 +29,43 @@ package org.apache.http.nio.impl; +import java.io.IOException; +import java.net.SocketAddress; 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 { +class SessionRequestImpl implements SessionRequest { private volatile boolean completed; private final SelectionKey key; + private final SocketAddress remoteAddress; private int connectTimeout; private SessionRequestCallback callback; private IOSession session = null; + private IOException exception = null; - public SessionRequestImpl(final SelectionKey key) { + public SessionRequestImpl(final SocketAddress remoteAddress, SelectionKey key) { super(); + if (remoteAddress == null) { + throw new IllegalArgumentException("Remote address may not be null"); + } + if (key == null) { + throw new IllegalArgumentException("Selection key may not be null"); + } + this.remoteAddress = remoteAddress; this.key = key; this.connectTimeout = 0; } + public SocketAddress getRemoteAddress() { + return this.remoteAddress; + } + public boolean isCompleted() { return this.completed; } @@ -72,6 +87,12 @@ } } + public IOException getException() { + synchronized (this) { + return this.exception; + } + } + public void completed(final IOSession session) { if (session == null) { throw new IllegalArgumentException("Session may not be null"); @@ -89,19 +110,34 @@ } } - public synchronized void timeout() { + public void failed(final IOException exception) { + if (exception == null) { + return; + } if (this.completed) { throw new IllegalStateException("Session request already completed"); } this.completed = true; synchronized (this) { + this.exception = exception; if (this.callback != null) { - this.callback.timeout(this); + this.callback.failed(this); } notifyAll(); } } + public void timeout() { + if (this.completed) { + throw new IllegalStateException("Session request already completed"); + } + synchronized (this) { + if (this.callback != null) { + this.callback.timeout(this); + } + } + } + public int getConnectTimeout() { return this.connectTimeout; } @@ -114,16 +150,24 @@ } public void setCallback(final SessionRequestCallback callback) { - if (this.completed) { - throw new IllegalStateException("Session request already completed"); - } synchronized (this) { this.callback = callback; + if (this.completed) { + if (this.session != null) { + callback.completed(this); + } else { + callback.timeout(this); + } + } } } public void cancel() { this.key.cancel(); + this.completed = true; + synchronized (this) { + notifyAll(); + } } } From httpclient-commits-returnsmithmelissa@example.com Fri Oct 06 11:19:35 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 76578 invoked from network); 6 Oct 2006 11:19:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 6 Oct 2006 11:19:35 -0000 Received: (qmail 72578 invoked by uid 500); 6 Oct 2006 11:19:35 -0000 Mailing-List: contact smithmelissa@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:smithmelissa@example.com> List-Unsubscribe: <mailto:smithmelissa@example.com> List-Post: <mailto:smithmelissa@example.com> List-Id: <httpclient-commits.jakarta.apache.org> Reply-To: smithmelissa@example.com Delivered-To: mailing list smithmelissa@example.com Received: (qmail 72566 invoked by uid 99); 6 Oct 2006 11:19:35 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Oct 2006 04:19:35 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [83.161.120.155] ([83.161.120.155:60422] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 83.161.120.155 r(12930)) with ESMTP id 79/76-18133-6CB36254 for <smithmelissa@example.com>; Fri, 06 Oct 2006 04:19:34 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DE7091A981A; Fri, 6 Oct 2006 04:19:31 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453553 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java Date: Fri, 06 Oct 2006 11:19:31 -0000 To: smithmelissa@example.com From: smithmelissa@example.com X-Mailer: svnmailer-1.1.0 Message-Id: <smithmelissa@example.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Fri Oct 6 04:19:31 2006 New Revision: 453553 URL: http://svn.apache.org/viewvc?view=rev&rev=453553 Log: Bug fix Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java Modified: 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=diff&rev=453553&r1=453552&r2=453553 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/SessionRequestImpl.java Fri Oct 6 04:19:31 2006 @@ -153,10 +153,10 @@ synchronized (this) { this.callback = callback; if (this.completed) { - if (this.session != null) { + if (this.exception != null) { + callback.failed(this); + } else if (this.session != null) { callback.completed(this); - } else { - callback.timeout(this); } } } From httpclient-commits-returnsmithmelissa@example.com Sun Oct 08 12:35:31 2006 Return-Path: <httpclient-commits-returnsmithmelissa@example.com> Delivered-To: smithmelissa@example.com Received: (qmail 909 invoked from network); 8 Oct 2006
{'source': 'Apache Software Foundation Public Mail Archives'}