hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r814229 [1/2] - in /httpcomponents/asynchttpclient/trunk: ./ src/ src/examples/ src/examples/org/ src/examples/org/apache/ src/examples/org/apache/http/ src/examples/org/apache/http/examples/ src/examples/org/apache/http/examples/nio/ src/e...
Date Sat, 12 Sep 2009 20:30:21 GMT
Author: olegk
Date: Sat Sep 12 20:30:20 2009
New Revision: 814229

URL: http://svn.apache.org/viewvc?rev=814229&view=rev
Log:
Initial drop of AsyncHttpClient

Added:
    httpcomponents/asynchttpclient/trunk/pom.xml   (with props)
    httpcomponents/asynchttpclient/trunk/src/
    httpcomponents/asynchttpclient/trunk/src/examples/
    httpcomponents/asynchttpclient/trunk/src/examples/org/
    httpcomponents/asynchttpclient/trunk/src/examples/org/apache/
    httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/
    httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/
    httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/
    httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/
    httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/
    httpcomponents/asynchttpclient/trunk/src/main/java/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/RouteResolver.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPoolForRoute.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/client/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/client/AsyncHttpClient.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/client/HttpExchange.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/BasicFuture.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/FutureCallback.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/conn/
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/conn/IOSessionManager.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/conn/ManagedIOSession.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/conn/PoolStats.java   (with props)
    httpcomponents/asynchttpclient/trunk/src/test/
    httpcomponents/asynchttpclient/trunk/src/test/java/

Added: httpcomponents/asynchttpclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/pom.xml?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/pom.xml (added)
+++ httpcomponents/asynchttpclient/trunk/pom.xml Sat Sep 12 20:30:20 2009
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you 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 />.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>project</artifactId>
+    <groupId>org.apache.httpcomponents</groupId>
+    <version>4.0</version>
+    <relativePath>../project/pom.xml</relativePath>
+  </parent>
+  <artifactId>asynchttpclient</artifactId>
+  <name>AsyncHttpClient</name>
+  <description>
+   HttpComponents Async Client
+  </description>
+  <url>http://hc.apache.org/httpcomponents-client</url>
+  <packaging>jar</packaging>  
+
+  <licenses>
+    <license>
+      <name>Apache License</name>
+      <url>LICENSE.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>${httpcore.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore-nio</artifactId>
+      <version>${httpcore.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>${httpclient.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>${commons-logging.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    <maven.compile.source>1.5</maven.compile.source>
+    <maven.compile.target>1.5</maven.compile.target>
+    <maven.compile.optimize>true</maven.compile.optimize>
+    <maven.compile.deprecation>true</maven.compile.deprecation>
+    <httpcore.version>4.1-alpha1</httpcore.version>
+    <httpclient.version>4.0</httpclient.version>
+    <commons-logging.version>1.1.1</commons-logging.version>
+    <junit.version>3.8.2</junit.version>
+  </properties>
+
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>false</filtering>
+        <includes>
+            <include>META-INF/*</include>
+        </includes>
+      </resource>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <includes>
+            <include>**/*.properties</include>
+        </includes>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>${maven.compile.source}</source>
+          <target>${maven.compile.target}</target>
+          <optimize>${maven.compile.optimize}</optimize>
+          <showDeprecations>${maven.compile.deprecation}</showDeprecations>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: httpcomponents/asynchttpclient/trunk/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,86 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.examples.nio.client;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.impl.nio.client.BasicAsyncHttpClient;
+import org.apache.http.impl.nio.conn.BasicIOSessionManager;
+import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.nio.client.AsyncHttpClient;
+import org.apache.http.nio.client.HttpExchange;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.SyncBasicHttpParams;
+
+public class AsyncClientRequest {
+
+    public static void main(String[] args) throws Exception {
+        HttpParams params = new SyncBasicHttpParams();
+        params
+            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
+            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)
+            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
+            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
+            .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");
+        DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(1, params);
+        BasicIOSessionManager sessmrg = new BasicIOSessionManager(ioReactor);
+        sessmrg.setTotalMax(5);
+        sessmrg.setDefaultMaxPerHost(3);
+
+        AsyncHttpClient asynchttpclient = new BasicAsyncHttpClient(
+                ioReactor, 
+                sessmrg, 
+                params);
+        
+        asynchttpclient.start();
+        
+        HttpHost target = new HttpHost("www.google.ch", 80);
+        BasicHttpRequest request = new BasicHttpRequest("GET", "/"); 
+
+        HttpExchange[] httpx = new HttpExchange[10]; 
+        for (int i = 0; i < httpx.length; i++) {
+            httpx[i] = asynchttpclient.execute(target, request);
+        }
+        
+        for (int i = 0; i < httpx.length; i++) {
+            HttpResponse response = httpx[i].awaitResponse();
+            if (response != null) {
+                System.out.println("Response: " + response.getStatusLine());
+            }
+        }
+
+        System.out.println("Shutting down");
+        
+        asynchttpclient.shutdown();
+        
+        System.out.println("Done");
+    }
+
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/examples/org/apache/http/examples/nio/client/AsyncClientRequest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,176 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.client;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.nio.conn.BasicIOSessionManager;
+import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.nio.client.AsyncHttpClient;
+import org.apache.http.nio.client.HttpExchange;
+import org.apache.http.nio.conn.IOSessionManager;
+import org.apache.http.nio.protocol.AsyncNHttpClientHandler;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
+import org.apache.http.nio.reactor.IOEventDispatch;
+import org.apache.http.nio.reactor.IOReactorException;
+import org.apache.http.nio.reactor.IOReactorStatus;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.SyncBasicHttpParams;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+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;
+
+public class BasicAsyncHttpClient implements AsyncHttpClient {
+
+    private final Log log;
+    private final HttpParams params;
+    private final ConnectingIOReactor ioReactor;
+    private final IOSessionManager<HttpRoute> sessmrg;    
+    
+    private Thread reactorThread;
+    
+    public BasicAsyncHttpClient(
+            final ConnectingIOReactor ioReactor,
+            final IOSessionManager<HttpRoute> sessmrg,
+            final HttpParams params) throws IOReactorException {
+        super();
+        this.log = LogFactory.getLog(getClass());
+        if (params != null) {
+            this.params = params;
+        } else {
+            this.params = createDefaultHttpParams();
+        }
+        this.ioReactor = ioReactor;
+        this.sessmrg = sessmrg;
+    }
+    
+    public BasicAsyncHttpClient(final HttpParams params) throws IOReactorException {
+        super();
+        this.log = LogFactory.getLog(getClass());
+        if (params != null) {
+            this.params = params;
+        } else {
+            this.params = createDefaultHttpParams();
+        }
+        this.ioReactor = new DefaultConnectingIOReactor(2, this.params);
+        this.sessmrg = new BasicIOSessionManager(this.ioReactor);
+    }
+    
+    protected HttpParams createDefaultHttpParams() {
+        HttpParams params = new SyncBasicHttpParams();
+        params
+            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
+            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)
+            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
+            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
+            .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");
+        return params;
+    }
+    
+    protected HttpProcessor createHttpProcessor() {
+        HttpRequestInterceptor[] interceptors = new HttpRequestInterceptor[] {
+                new RequestContent(),
+                new RequestTargetHost(),
+                new RequestConnControl(),
+                new RequestUserAgent(),
+                new RequestExpectContinue()
+        };
+        ImmutableHttpProcessor httpProcessor = new ImmutableHttpProcessor(interceptors); 
+        return httpProcessor;
+    }
+    
+    protected ConnectionReuseStrategy createConnectionReuseStrategy() {
+        return new DefaultConnectionReuseStrategy();
+    }
+    
+    public HttpParams getParams() {
+        return this.params;
+    }
+
+    private void doExecute() {
+        AsyncNHttpClientHandler handler = new AsyncNHttpClientHandler(
+                createHttpProcessor(),
+                new InternalRequestExecutionHandler(),
+                createConnectionReuseStrategy(),
+                this.params);
+        handler.setEventListener(new InternalEventLogger(this.log));
+        IOEventDispatch ioEventDispatch = new InternalClientEventDispatch(handler, this.params);
+        try {
+            this.ioReactor.execute(ioEventDispatch);
+        } catch (IOException ex) {
+            this.log.error("I/O reactor terminated abnormally", ex);
+        }
+    }
+    
+    public IOReactorStatus getStatus() {
+        return this.ioReactor.getStatus();
+    }
+    
+    public synchronized void start() {
+        this.reactorThread = new Thread() {
+
+            @Override
+            public void run() {
+                doExecute();
+            }
+            
+        };
+        this.reactorThread.start();
+    }
+
+    public synchronized void shutdown() throws InterruptedException {
+        this.sessmrg.shutdown();
+        try {
+            this.ioReactor.shutdown(5000);
+        } catch (IOException ex) {
+            this.log.error("I/O error shutting down", ex);
+        }
+        if (this.reactorThread != null) {
+            this.reactorThread.join();
+        }
+    }
+    
+    public HttpExchange execute(final HttpHost target, final HttpRequest request) {
+        HttpRoute route = new HttpRoute(target);
+        return new HttpExchangeImpl(request, route, null, this.sessmrg);
+    }
+    
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicAsyncHttpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,127 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.client;
+
+import java.nio.channels.SelectionKey;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.nio.client.HttpExchange;
+import org.apache.http.nio.concurrent.BasicFuture;
+import org.apache.http.nio.concurrent.FutureCallback;
+import org.apache.http.nio.conn.IOSessionManager;
+import org.apache.http.nio.conn.ManagedIOSession;
+import org.apache.http.nio.reactor.IOSession;
+
+class HttpExchangeImpl implements HttpExchange {
+
+    private final HttpRequest request;
+    private final Future<ManagedIOSession> sessionFuture;
+    private final BasicFuture<HttpResponse> responseFuture;
+
+    private ManagedIOSession managedSession;
+    
+    public HttpExchangeImpl(
+            final HttpRequest request,
+            final HttpRoute route,
+            final Object state,
+            final IOSessionManager<HttpRoute> sessmrg) {
+        super();
+        this.request = request;
+        this.sessionFuture = sessmrg.leaseSession(route, state, new InternalFutureCallback());
+        this.responseFuture = new BasicFuture<HttpResponse>(null);
+    }
+
+    public boolean isCompleted() {
+        return this.responseFuture.isDone();
+    }
+    
+    public HttpRequest getRequest() {
+        return this.request;
+    }
+    
+    public HttpResponse awaitResponse() throws ExecutionException, InterruptedException {
+        return this.responseFuture.get();
+    }
+
+    public synchronized void completed(final HttpResponse response) {
+        if (this.managedSession != null) {
+            this.managedSession.releaseSession();
+        }
+        this.responseFuture.completed(response);
+    }
+    
+    public synchronized void cancel() {
+        this.sessionFuture.cancel(true);
+        if (this.managedSession != null) {
+            this.managedSession.abortSession();
+        }
+        this.responseFuture.cancel(true);
+    }
+
+    private synchronized void sessionRequestCompleted() {
+        try {
+            this.managedSession = this.sessionFuture.get();
+            if (this.managedSession == null || this.sessionFuture.isCancelled()) {
+                this.responseFuture.cancel(true);
+            } else {
+                IOSession iosession = this.managedSession.getSession();
+                iosession.setAttribute(InternalRequestExecutionHandler.HTTP_EXCHANGE, this);
+                iosession.setEvent(SelectionKey.OP_WRITE);
+            }
+        } catch (InterruptedException ex) {
+            this.responseFuture.cancel(true);
+        } catch (ExecutionException ex) {
+            Throwable cause = ex.getCause(); 
+            if (cause != null && cause instanceof Exception) {
+                this.responseFuture.failed((Exception) cause);
+            } else {
+                this.responseFuture.failed(ex);
+            }
+        }
+    }
+    
+    class InternalFutureCallback implements FutureCallback<ManagedIOSession> {
+
+        public void completed(final Future<ManagedIOSession> future) {
+            sessionRequestCompleted();
+        }
+
+        public void failed(final Future<ManagedIOSession> future) {
+            sessionRequestCompleted();
+        }
+        
+        public void cancelled(final Future<ManagedIOSession> future) {
+            sessionRequestCompleted();            
+        }
+
+    }
+    
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,113 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.client;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.impl.nio.DefaultClientIOEventDispatch;
+import org.apache.http.impl.nio.conn.LoggingIOSession;
+import org.apache.http.impl.nio.conn.LoggingNHttpClientConnection;
+import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.HttpParams;
+
+class InternalClientEventDispatch extends DefaultClientIOEventDispatch {
+
+    private static final String HEADERS = "org.apache.http.headers";
+    private static final String WIRE = "org.apache.http.wire";
+    
+    private Log log;
+    
+    InternalClientEventDispatch(
+            final NHttpClientHandler handler, 
+            final HttpParams params) {
+        super(handler, params);
+        this.log = LogFactory.getLog(getClass());
+    }
+
+    @Override
+    protected NHttpClientIOTarget createConnection(IOSession session) {
+        Log log = LogFactory.getLog(session.getClass());
+        Log wirelog = LogFactory.getLog(WIRE);
+        Log headerlog = LogFactory.getLog(HEADERS);
+        if (log.isDebugEnabled() || wirelog.isDebugEnabled()) {
+            session = new LoggingIOSession(session, log, wirelog);
+        }
+        if (headerlog.isDebugEnabled()) {
+            return new LoggingNHttpClientConnection(
+                    headerlog, 
+                    session,
+                    createHttpResponseFactory(),
+                    this.allocator,
+                    this.params); 
+        } else {
+            return super.createConnection(session);
+        }
+    }
+
+    @Override
+    public void connected(final IOSession session) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Session connected: " + session);
+        }
+        super.connected(session);
+    }
+
+    @Override
+    public void disconnected(final IOSession session) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Session disconnected: " + session);
+        }
+        super.disconnected(session);
+    }
+
+    @Override
+    public void inputReady(final IOSession session) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Session input ready: " + session);
+        }
+        super.inputReady(session);
+    }
+
+    @Override
+    public void outputReady(final IOSession session) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Session output ready: " + session);
+        }
+        super.outputReady(session);
+    }
+
+    @Override
+    public void timeout(IOSession session) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Session timed out: " + session);
+        }
+        super.timeout(session);
+    }
+    
+}
\ No newline at end of file

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalClientEventDispatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,75 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.client;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.http.HttpException;
+import org.apache.http.nio.NHttpConnection;
+import org.apache.http.nio.protocol.EventListener;
+
+class InternalEventLogger implements EventListener {
+
+    private final Log log;
+    
+    InternalEventLogger(final Log log) {
+        super();
+        this.log = log;
+    }
+    
+    public void connectionOpen(final NHttpConnection conn) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Connection open: " + conn);
+        }
+    }
+
+    public void connectionTimeout(final NHttpConnection conn) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Connection timed out: " + conn);
+        }
+    }
+
+    public void connectionClosed(final NHttpConnection conn) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("Connection closed: " + conn);
+        }
+    }
+
+    public void fatalIOException(final IOException ex, final NHttpConnection conn) {
+        if (this.log.isErrorEnabled()) {
+            this.log.error("I/O error: " + conn, ex);
+        }
+    }
+
+    public void fatalProtocolException(final HttpException ex, final NHttpConnection conn) {
+        if (this.log.isErrorEnabled()) {
+            this.log.error("Protocol error: " + conn, ex);
+        }
+    }
+    
+}
\ No newline at end of file

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalEventLogger.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,81 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.client;
+
+import java.io.IOException;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.nio.entity.BufferingNHttpEntity;
+import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.protocol.NHttpRequestExecutionHandler;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.protocol.HttpContext;
+
+class InternalRequestExecutionHandler implements NHttpRequestExecutionHandler {
+
+    protected static final String HTTP_EXCHANGE = "http.async.http-exchange";
+    
+    InternalRequestExecutionHandler() {
+        super();
+    }
+
+    public void initalizeContext(final HttpContext context, final Object attachment) {
+    }
+
+    public void finalizeContext(final HttpContext context) {
+        HttpExchangeImpl httpx = (HttpExchangeImpl) context.removeAttribute(HTTP_EXCHANGE);
+        if (httpx != null) {
+            httpx.cancel();
+        }
+    }
+
+    public HttpRequest submitRequest(final HttpContext context) {
+        HttpExchangeImpl httpx = (HttpExchangeImpl) context.getAttribute(HTTP_EXCHANGE);
+        if (httpx != null) {
+            return httpx.getRequest();
+        } else {
+            return null;
+        }
+    }
+    
+    public ConsumingNHttpEntity responseEntity(
+    		final HttpResponse response, final HttpContext context) throws IOException {
+        return new BufferingNHttpEntity(
+                response.getEntity(),
+                new HeapByteBufferAllocator());
+    }
+
+    public void handleResponse(
+    		final HttpResponse response, final HttpContext context) throws IOException {
+        HttpExchangeImpl httpx = (HttpExchangeImpl) context.removeAttribute(HTTP_EXCHANGE);
+        if (httpx != null) {
+            httpx.completed(response);
+        }
+    }
+
+}
\ No newline at end of file

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutionHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,167 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.conn;
+
+import java.util.concurrent.Future;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.nio.pool.PoolEntry;
+import org.apache.http.impl.nio.pool.PoolEntryCallback;
+import org.apache.http.nio.concurrent.BasicFuture;
+import org.apache.http.nio.concurrent.FutureCallback;
+import org.apache.http.nio.conn.ManagedIOSession;
+import org.apache.http.nio.conn.IOSessionManager;
+import org.apache.http.nio.conn.PoolStats;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
+import org.apache.http.nio.reactor.IOSession;
+
+public class BasicIOSessionManager implements IOSessionManager<HttpRoute> {
+
+    private final Log log;
+    private final HttpSessionPool pool;
+
+    public BasicIOSessionManager(final ConnectingIOReactor ioreactor) {
+        super();
+        if (ioreactor == null) {
+            throw new IllegalArgumentException("I/O reactor may not be null");
+        }
+        this.log = LogFactory.getLog(getClass());
+        this.pool = new HttpSessionPool(ioreactor);
+    }
+
+    public synchronized Future<ManagedIOSession> leaseSession(
+            final HttpRoute route,
+            final Object state,
+            final FutureCallback<ManagedIOSession> callback) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session request: route[" + route + "][state: " + state + "]");
+            PoolStats totals = this.pool.getTotalStats();
+            PoolStats stats = this.pool.getStats(route);
+            this.log.debug("Total: " + totals);
+            this.log.debug("Route [" + route + "]: " + stats);
+        }
+        BasicFuture<ManagedIOSession> future = new BasicFuture<ManagedIOSession>(
+                callback);
+        this.pool.lease(route, state, new InternalPoolEntryCallback(future));
+        if (this.log.isDebugEnabled()) {
+            if (!future.isDone()) {
+                this.log.debug("I/O session could not be allocated immediately: " +
+                		"route[" + route + "][state: " + state + "]");
+            }
+        }
+        return future;
+    }
+
+    public synchronized void releaseSession(final ManagedIOSession conn) {
+        if (!(conn instanceof BasicManagedIOSession)) {
+            throw new IllegalArgumentException
+                ("I/O session class mismatch, " +
+                 "I/O session not obtained from this manager");
+        }
+        BasicManagedIOSession adaptor = (BasicManagedIOSession) conn;
+        IOSessionManager<HttpRoute> manager = adaptor.getManager();
+        if (manager != null && manager != this) {
+            throw new IllegalArgumentException
+                ("I/O session not obtained from this manager");
+        }
+        PoolEntry<HttpRoute> entry = adaptor.getEntry();
+        IOSession iosession = entry.getIOSession();
+        if (this.log.isDebugEnabled()) {
+            HttpRoute route = entry.getRoute();
+            PoolStats totals = this.pool.getTotalStats();
+            PoolStats stats = this.pool.getStats(route);
+            this.log.debug("Total: " + totals);
+            this.log.debug("Route [" + route + "]: " + stats);
+            this.log.debug("I/O session released: " + entry);
+        }
+        this.pool.release(entry, adaptor.isReusable() && !iosession.isClosed());
+    }
+
+    public PoolStats getTotalStats() {
+        return this.pool.getTotalStats();
+    }
+
+    public PoolStats getStats(final HttpRoute route) {
+        return this.pool.getStats(route);
+    }
+    
+    public void setTotalMax(int max) {
+    	this.pool.setTotalMax(max);
+    }
+
+    public void setDefaultMaxPerHost(int max) {
+    	this.pool.setDefaultMaxPerHost(max);
+    }
+
+    public void setMaxPerHost(final HttpRoute route, int max) {
+    	this.pool.setMaxPerHost(route, max);
+    }
+    
+    public synchronized void shutdown() {
+        this.log.debug("I/O session manager shut down"); 
+        this.pool.shutdown();
+    }
+
+    class InternalPoolEntryCallback implements PoolEntryCallback<HttpRoute> {
+
+        private final BasicFuture<ManagedIOSession> future;
+        
+        public InternalPoolEntryCallback(
+                final BasicFuture<ManagedIOSession> future) {
+            super();
+            this.future = future;
+        }
+        
+        public void completed(final PoolEntry<HttpRoute> entry) {
+            if (log.isDebugEnabled()) {
+                log.debug("I/O session allocated: " + entry);
+            }
+            BasicManagedIOSession result = new BasicManagedIOSession(
+                    BasicIOSessionManager.this, 
+                    entry);
+            if (!this.future.completed(result)) {
+                pool.release(entry, true);
+            }
+        }
+
+        public void failed(final Exception ex) {
+            if (log.isDebugEnabled()) {
+                log.debug("I/O session request failed", ex);
+            }
+            this.future.failed(ex);
+        }
+
+        public void cancelled() {
+            log.debug("I/O session request cancelled");
+            this.future.cancel(true);
+        }
+
+    }
+
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,140 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.conn;
+
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.nio.pool.PoolEntry;
+import org.apache.http.nio.conn.IOSessionManager;
+import org.apache.http.nio.conn.ManagedIOSession;
+import org.apache.http.nio.reactor.IOSession;
+
+public class BasicManagedIOSession implements ManagedIOSession {
+
+    private final IOSessionManager<HttpRoute> manager;
+    private volatile PoolEntry<HttpRoute> entry;
+    private volatile boolean released;
+    private volatile boolean reusable;
+
+    public BasicManagedIOSession(
+            final IOSessionManager<HttpRoute> manager,
+            final PoolEntry<HttpRoute> entry) {
+        super();
+        this.manager = manager;
+        this.entry = entry;
+        this.released = false;
+        this.reusable = true;
+    }
+
+    protected IOSessionManager<HttpRoute> getManager() {
+        return this.manager;
+    }
+
+    protected PoolEntry<HttpRoute> getEntry() {
+        return this.entry;
+    }
+    
+    public IOSession getSession() {
+        if (this.released) {
+            return null;
+        }
+        return this.entry.getIOSession();
+    }
+
+    public void releaseSession() {
+        if (this.released) {
+            return;
+        }
+        this.released = true;
+        this.manager.releaseSession(this);
+        this.entry = null;
+    }
+
+    public void abortSession() {
+        if (this.released) {
+            return;
+        }
+        this.released = true;
+        this.reusable = false;
+        IOSession iosession = this.entry.getIOSession();
+        iosession.shutdown();
+        this.manager.releaseSession(this);
+        this.entry = null;
+    }
+
+    public Object getState() {
+        if (this.released) {
+            return null;
+        }
+        return this.entry.getState();
+    }
+
+    public void setState(final Object state) {
+        if (this.released) {
+            return;
+        }
+        this.entry.setState(state);
+    }
+
+    public boolean isReusable() {
+        return this.reusable;
+    }
+
+    public void markNonReusable() {
+        if (this.released) {
+            return;
+        }
+        this.reusable = false;
+    }
+
+    public void markReusable() {
+        if (this.released) {
+            return;
+        }
+        this.reusable = true;
+    }
+
+    @Override
+    public String toString() {
+        HttpRoute route = this.entry.getRoute();
+    	StringBuilder buffer = new StringBuilder();
+        buffer.append("HTTP connection: ");
+        if (route.getLocalAddress() != null) {
+            buffer.append(route.getLocalAddress());
+            buffer.append("->");
+        }
+        for (int i = 0; i < route.getHopCount(); i++) {
+        	buffer.append(route.getHopTarget(i));
+        	buffer.append("->");
+        }
+        buffer.append(route.getTargetHost());
+        if (this.released) {
+            buffer.append(" (released)");
+        }
+        return buffer.toString();
+    }
+    
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicManagedIOSession.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,57 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.conn;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import org.apache.http.HttpHost;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.nio.pool.RouteResolver;
+import org.apache.http.impl.nio.pool.SessionPool;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
+
+class HttpSessionPool extends SessionPool<HttpRoute> {
+
+    public HttpSessionPool(final ConnectingIOReactor ioreactor) {
+        super(ioreactor, new InternalRouteResolver(), 20, 50);
+    }
+    
+    static class InternalRouteResolver implements RouteResolver<HttpRoute> {
+
+        public SocketAddress resolveLocalAddress(final HttpRoute route) {
+            return new InetSocketAddress(route.getLocalAddress(), 0);
+        }
+
+        public SocketAddress resolveRemoteAddress(final HttpRoute route) {
+            HttpHost target = route.getTargetHost();
+            return new InetSocketAddress(target.getHostName(), target.getPort());
+        }
+
+    }
+    
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/HttpSessionPool.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,233 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.conn;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.ByteChannel;
+import java.nio.channels.SelectionKey;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.commons.logging.Log;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.reactor.SessionBufferStatus;
+
+public class LoggingIOSession implements IOSession {
+
+    private static AtomicLong COUNT = new AtomicLong(0);
+    
+    private final Log log;
+    private final Wire wirelog;
+    private final IOSession session;
+    private final ByteChannel channel;
+    private final String id;
+    
+    public LoggingIOSession(final IOSession session, final Log log, final Log wirelog) {
+        super();
+        if (session == null) {
+            throw new IllegalArgumentException("I/O session may not be null");
+        }
+        this.log = log;
+        this.wirelog = new Wire(wirelog);
+        this.session = session;
+        this.channel = new LoggingByteChannel();
+        this.id = Long.toString(COUNT.incrementAndGet());
+    }
+
+    public ByteChannel channel() {
+        return this.channel;
+    }
+
+    public SocketAddress getLocalAddress() {
+        return this.session.getLocalAddress();
+    }
+
+    public SocketAddress getRemoteAddress() {
+        return this.session.getRemoteAddress();
+    }
+
+    public int getEventMask() {
+        return this.session.getEventMask();
+    }
+
+    private static String formatOps(int ops) {
+        StringBuffer buffer = new StringBuffer(6);
+        buffer.append('[');
+        if ((ops & SelectionKey.OP_READ) > 0) {
+            buffer.append('r');
+        }
+        if ((ops & SelectionKey.OP_WRITE) > 0) {
+            buffer.append('w');
+        }
+        if ((ops & SelectionKey.OP_ACCEPT) > 0) {
+            buffer.append('a');
+        }
+        if ((ops & SelectionKey.OP_CONNECT) > 0) {
+            buffer.append('c');
+        }
+        buffer.append(']');
+        return buffer.toString();
+    }
+    
+    public void setEventMask(int ops) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Set event mask " 
+                    + formatOps(ops));
+        }
+        this.session.setEventMask(ops);
+    }
+
+    public void setEvent(int op) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Set event " 
+                    + formatOps(op));
+        }
+        this.session.setEvent(op);
+    }
+
+    public void clearEvent(int op) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Clear event " 
+                    + formatOps(op));
+        }
+        this.session.clearEvent(op);
+    }
+
+    public void close() {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Close");
+        }
+        this.session.close();
+    }
+
+    public int getStatus() {
+        return this.session.getStatus();
+    }
+
+    public boolean isClosed() {
+        return this.session.isClosed();
+    }
+
+    public void shutdown() {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Shutdown");
+        }
+        this.session.shutdown();
+    }
+
+    public int getSocketTimeout() {
+        return this.session.getSocketTimeout();
+    }
+
+    public void setSocketTimeout(int timeout) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Set timeout " 
+                    + timeout);
+        }
+        this.session.setSocketTimeout(timeout);
+    }
+
+    public void setBufferStatus(final SessionBufferStatus status) {
+        this.session.setBufferStatus(status);
+    }
+
+    public boolean hasBufferedInput() {
+        return this.session.hasBufferedInput();
+    }
+
+    public boolean hasBufferedOutput() {
+        return this.session.hasBufferedOutput();
+    }
+
+    public Object getAttribute(final String name) {
+        return this.session.getAttribute(name);
+    }
+
+    public void setAttribute(final String name, final Object obj) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Set attribute " 
+                    + name);
+        }
+        this.session.setAttribute(name, obj);
+    }
+
+    public Object removeAttribute(final String name) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug("I/O session " + this.id + " " + this.session + ": Remove attribute " 
+                    + name);
+        }
+        return this.session.removeAttribute(name);
+    }
+
+    class LoggingByteChannel implements ByteChannel {
+
+        public int read(final ByteBuffer dst) throws IOException {
+            int bytesRead = session.channel().read(dst);
+            if (log.isDebugEnabled()) {
+                log.debug("I/O session " + id + " " + session + ": " + bytesRead + " bytes read");
+            }
+            if (bytesRead > 0 && wirelog.isEnabled()) {
+            	ByteBuffer b = dst.duplicate();
+            	int p = b.position();
+            	b.limit(p);
+            	b.position(p - bytesRead);
+            	wirelog.input(b);
+            }
+            return bytesRead;
+        }
+
+        public int write(final ByteBuffer src) throws IOException {
+            int byteWritten = session.channel().write(src);
+            if (log.isDebugEnabled()) {
+                log.debug("I/O session " + id + " " + session + ": " + byteWritten + " bytes written");
+            }
+            if (byteWritten > 0 && wirelog.isEnabled()) {
+            	ByteBuffer b = src.duplicate();
+            	int p = b.position();
+            	b.limit(p);
+            	b.position(p - byteWritten);
+            	wirelog.output(b);
+            }
+            return byteWritten;
+        }
+
+        public void close() throws IOException {
+            if (log.isDebugEnabled()) {
+                log.debug("I/O session " + id + " " + session + ": Channel close");
+            }
+            session.channel().close();
+        }
+
+        public boolean isOpen() {
+            return session.channel().isOpen();
+        }
+        
+    }    
+    
+}
\ No newline at end of file

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,140 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.conn;
+
+import java.io.IOException;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.commons.logging.Log;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpMessage;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpClientConnection;
+import org.apache.http.nio.NHttpMessageParser;
+import org.apache.http.nio.NHttpMessageWriter;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.reactor.SessionInputBuffer;
+import org.apache.http.nio.reactor.SessionOutputBuffer;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.params.HttpParams;
+
+public class LoggingNHttpClientConnection extends DefaultNHttpClientConnection {
+
+    private final Log headerlog;
+
+    public LoggingNHttpClientConnection(
+    		final Log headerlog,
+            final IOSession iosession,
+            final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
+        super(iosession, responseFactory, allocator, params);
+        this.headerlog = headerlog;
+	}
+
+    @Override
+	protected NHttpMessageWriter createRequestWriter(
+			final SessionOutputBuffer buffer, 
+			final HttpParams params) {
+		return new LoggingNHttpMessageWriter(
+		        super.createRequestWriter(buffer, params));
+	}
+
+	@Override
+	protected NHttpMessageParser createResponseParser(
+			final SessionInputBuffer buffer, 
+			final HttpResponseFactory responseFactory,
+			final HttpParams params) {
+		return new LoggingNHttpMessageParser(
+		        super.createResponseParser(buffer, responseFactory, params));
+	}
+
+	class LoggingNHttpMessageWriter implements NHttpMessageWriter {
+
+		private final NHttpMessageWriter writer;
+		
+		public LoggingNHttpMessageWriter(final NHttpMessageWriter writer) {
+			super();
+			this.writer = writer;
+		}
+		
+		public void reset() {
+			this.writer.reset();
+		}
+
+		public void write(final HttpMessage message) throws IOException, HttpException {
+	        if (message != null && headerlog.isDebugEnabled()) {
+	        	HttpRequest request = (HttpRequest) message; 
+	            headerlog.debug(">> " + request.getRequestLine().toString());
+	            Header[] headers = request.getAllHeaders();
+	            for (int i = 0; i < headers.length; i++) {
+	                headerlog.debug(">> " + headers[i].toString());
+	            }
+	        }
+	        this.writer.write(message);
+		}
+		
+	}
+	
+	class LoggingNHttpMessageParser implements NHttpMessageParser {
+
+		private final NHttpMessageParser parser;
+		
+		public LoggingNHttpMessageParser(final NHttpMessageParser parser) {
+			super();
+			this.parser = parser;
+		}
+		
+		public void reset() {
+			this.parser.reset();
+		}
+
+		public int fillBuffer(final ReadableByteChannel channel) throws IOException {
+			return this.parser.fillBuffer(channel);
+		}
+
+		public HttpMessage parse() throws IOException, HttpException {
+			HttpMessage message = this.parser.parse();
+			if (headerlog.isDebugEnabled()) {
+				HttpResponse response = (HttpResponse) message; 
+		        if (response != null && headerlog.isDebugEnabled()) {
+		            headerlog.debug("<< " + response.getStatusLine().toString());
+		            Header[] headers = response.getAllHeaders();
+		            for (int i = 0; i < headers.length; i++) {
+		                headerlog.debug("<< " + headers[i].toString());
+		            }
+		        }
+			}
+			return message;
+		}
+		
+	}
+
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/LoggingNHttpClientConnection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,93 @@
+package org.apache.http.impl.nio.conn;
+
+import java.nio.ByteBuffer;
+
+import org.apache.commons.logging.Log;
+
+class Wire {
+
+    private final Log log;
+    
+    public Wire(final Log log) {
+        super();
+        this.log = log;
+    }
+    
+    private void wire(final String header, final byte[] b, int pos, int off) {
+        StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < off; i++) {
+            int ch = b[pos + i];
+            if (ch == 13) {
+                buffer.append("[\\r]");
+            } else if (ch == 10) {
+                    buffer.append("[\\n]\"");
+                    buffer.insert(0, "\"");
+                    buffer.insert(0, header);
+                    this.log.debug(buffer.toString());
+                    buffer.setLength(0);
+            } else if ((ch < 32) || (ch > 127)) {
+                buffer.append("[0x");
+                buffer.append(Integer.toHexString(ch));
+                buffer.append("]");
+            } else {
+                buffer.append((char) ch);
+            }
+        } 
+        if (buffer.length() > 0) {
+            buffer.append('\"');
+            buffer.insert(0, '\"');
+            buffer.insert(0, header);
+            this.log.debug(buffer.toString());
+        }
+    }
+
+
+    public boolean isEnabled() {
+        return this.log.isDebugEnabled();
+    }    
+    
+    public void output(final byte[] b, int pos, int off) {
+        wire(">> ", b, pos, off);
+    }
+
+    public void input(final byte[] b, int pos, int off) {
+        wire("<< ", b, pos, off);
+    }
+
+    public void output(byte[] b) {
+        output(b, 0, b.length);
+    }
+
+    public void input(byte[] b) {
+        input(b, 0, b.length);
+    }
+
+    public void output(int b) {
+        output(new byte[] {(byte) b});
+    }
+
+    public void input(int b) {
+        input(new byte[] {(byte) b});
+    }
+
+    public void output(final ByteBuffer b) {
+        if (b.hasArray()) {
+            output(b.array(), b.arrayOffset() + b.position(), b.remaining());
+        } else {
+            byte[] tmp = new byte[b.remaining()];
+            b.get(tmp);
+            output(tmp);
+        }
+    }
+
+    public void input(final ByteBuffer b) {
+        if (b.hasArray()) {
+            input(b.array(), b.arrayOffset() + b.position(), b.remaining());
+        } else {
+            byte[] tmp = new byte[b.remaining()];
+            b.get(tmp);
+            input(tmp);
+        }
+    }
+
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/conn/Wire.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.pool;
+
+class LeaseRequest<T> {
+
+    private final T route;
+    private final Object state;
+    private final PoolEntryCallback<T> callback;
+
+    public LeaseRequest(
+            final T route,
+            final Object state,
+            final PoolEntryCallback<T> callback) {
+        super();
+        this.route = route;
+        this.state = state;
+        this.callback = callback;
+    }
+
+    public T getRoute() {
+        return this.route;
+    }
+
+    public Object getState() {
+        return this.state;
+    }
+
+    public PoolEntryCallback<T> getCallback() {
+        return this.callback;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append("[");
+        buffer.append(this.route);
+        buffer.append("][");
+        buffer.append(this.state);
+        buffer.append("]");
+        return super.toString();
+    }
+
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,77 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.pool;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.http.nio.reactor.IOSession;
+
+public class PoolEntry<T> {
+
+    private static AtomicLong COUNTER = new AtomicLong(); 
+    
+    private final long id;
+    private final T route;
+    private final IOSession session;
+    private Object state;
+
+    public PoolEntry(final T route, final IOSession session) {
+        super();
+        this.route = route;
+        this.session = session;
+        this.id = COUNTER.incrementAndGet();
+    }
+
+    public T getRoute() {
+        return this.route;
+    }
+
+    public IOSession getIOSession() {
+        return this.session;
+    }
+    public Object getState() {
+        return this.state;
+    }
+
+    public void setState(final Object state) {
+        this.state = state;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append("[id:");
+        buffer.append(this.id);
+        buffer.append("][route:");
+        buffer.append(this.route);
+        buffer.append("][state:");
+        buffer.append(this.state);
+        buffer.append("]");
+        return buffer.toString();
+    }
+    
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java?rev=814229&view=auto
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java (added)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java Sat Sep 12 20:30:20 2009
@@ -0,0 +1,37 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.impl.nio.pool;
+
+public interface PoolEntryCallback<T> {
+
+    void completed(PoolEntry<T> entry);
+    
+    void failed(Exception ex);
+    
+    void cancelled();
+    
+}

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/pool/PoolEntryCallback.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message