Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 96714 invoked from network); 25 Sep 2007 21:11:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Sep 2007 21:11:53 -0000 Received: (qmail 22697 invoked by uid 500); 25 Sep 2007 21:11:43 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 22683 invoked by uid 500); 25 Sep 2007 21:11:43 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 22672 invoked by uid 99); 25 Sep 2007 21:11:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Sep 2007 14:11:43 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Sep 2007 21:14:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AAD501A9832; Tue, 25 Sep 2007 14:11:27 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r579382 - in /geronimo/sandbox/AsyncHttpClient/src/main: java/org/apache/ahc/ java/org/apache/ahc/codec/ javadoc/ Date: Tue, 25 Sep 2007 21:11:21 -0000 To: scm@geronimo.apache.org From: jgenender@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070925211127.AAD501A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jgenender Date: Tue Sep 25 14:11:20 2007 New Revision: 579382 URL: http://svn.apache.org/viewvc?rev=579382&view=rev Log: Some javadoc Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/package.html geronimo/sandbox/AsyncHttpClient/src/main/javadoc/overview.html Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java?rev=579382&r1=579381&r2=579382&view=diff ============================================================================== --- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java (original) +++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java Tue Sep 25 14:11:20 2007 @@ -35,35 +35,70 @@ import java.util.concurrent.ExecutorService; /** - * Main class to use for sending asyncronous HTTP requests to servers. + * Main class to use for sending asynchronous HTTP requests to servers. * Only one or a few of these objects should be used in an application since - * it manages the threads and requests to multiple seperate servers/sockets. + * it manages the threads and requests to multiple separate servers/sockets. */ public class AsyncHttpClient { + /** The Constant DEFAULT_CONNECTION_TIMEOUT. */ public static final int DEFAULT_CONNECTION_TIMEOUT = 30000; + + /** The Constant DEFAULT_SSL_PROTOCOL. */ public static final String DEFAULT_SSL_PROTOCOL = "TLS"; + /** The ssl protocol. */ private String sslProtocol = DEFAULT_SSL_PROTOCOL; + /** The connection timeout. */ private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + + /** The connector. */ private SocketConnector connector; + + /** The thread pool. */ private static ExecutorService threadPool; + + /** The HttpIoHandler handler. */ private HttpIoHandler handler = new HttpIoHandler(); + + /** The ssl filter. */ private SSLFilter sslFilter; + /** + * Instantiates a new AsyncHttpClient. It will use a single threaded model and is good for + * use in one-off connections. + */ public AsyncHttpClient() { this(DEFAULT_CONNECTION_TIMEOUT, null); } + /** + * Instantiates a new AsyncHttpClient. This will take a thread pool (ExecutorService) to use + * for processing connections. + * + * @param executor the executor + */ public AsyncHttpClient(ExecutorService executor) { this(DEFAULT_CONNECTION_TIMEOUT, executor); } + /** + * Instantiates a new AsyncHttpClient. Uses a single thread model by default and allows you to specify + * a connection timeout. + * + * @param connectionTimeout the connection timeout in milliseconds. + */ public AsyncHttpClient(int connectionTimeout) { this(connectionTimeout, null); } + /** + * Instantiates a new AsyncHttpClient. Allows you to specify a connection timeout and an ExecutorService. + * + * @param connectionTimeout the connection timeout in milliseconds. + * @param executor the ExceutorService to use to process connections. + */ public AsyncHttpClient(int connectionTimeout, ExecutorService executor) { this.connectionTimeout = connectionTimeout; @@ -80,6 +115,12 @@ } + /** + * Sends a request. + * + * @param message the HttpRequestMessage to send to the remote server. + * @see HttpRequestMessage + */ public void sendRequest(HttpRequestMessage message) { if (threadPool != null && threadPool.isShutdown()) { throw new IllegalStateException("AsyncHttpClient has been destroyed and cannot be reused."); @@ -90,14 +131,28 @@ future.addListener(new FutureListener(this, message)); } + /** + * Gets the connection timeout. + * + * @return the connection timeout in milliseconds + */ public int getConnectionTimeout() { return connectionTimeout; } + /** + * Sets the connection timeout. + * + * @param connectionTimeout the new connection timeout in milliseconds + */ public void setConnectionTimeout(int connectionTimeout) { this.connectionTimeout = connectionTimeout; } + /** + * Shuts down the AsyncHttpClient object and shuts any associated thread pools. SHould always be called when the application is + * done using the object or a hang can occur. + */ public void destroyAll() { handler.destroy(); @@ -110,17 +165,34 @@ } } - //If connected, this listener will add the SSL Filter + /** + * The listener interface for receiving connection events. Its main purpose is to notify the + * callback of any exceptions that may have occurred, or to handle the session and inject + * the proper SSL filter if the connection is to be used for https. If a good + * connection occurs, it is also responsible for sending the request. + */ class FutureListener implements IoFutureListener { + /** The request. */ HttpRequestMessage request; + + /** The client. */ AsyncHttpClient client; + /** + * Instantiates a new future listener for a connection. + * + * @param client the AsyncHttpClient client object + * @param request the HttpRequestMessage request that is to be sent. + */ public FutureListener(AsyncHttpClient client, HttpRequestMessage request) { this.client = client; this.request = request; } + /* (non-Javadoc) + * @see org.apache.mina.common.IoFutureListener#operationComplete(org.apache.mina.common.IoFuture) + */ public void operationComplete(IoFuture future) { ConnectFuture connFuture = (ConnectFuture) future; if (connFuture.isConnected()) { @@ -164,6 +236,13 @@ } } + /** + * Creates the client ssl context. + * + * @return the SSL context + * + * @throws GeneralSecurityException the general security exception + */ private SSLContext createClientSSLContext() throws GeneralSecurityException { SSLContext context = SSLContext.getInstance(sslProtocol); context.init(null, TrustManagerFactoryImpl.X509_MANAGERS, null); Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java?rev=579382&r1=579381&r2=579382&view=diff ============================================================================== --- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java (original) +++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java Tue Sep 25 14:11:20 2007 @@ -21,9 +21,40 @@ import org.apache.ahc.codec.HttpResponseMessage; +/** + * The Interface AsyncHttpClientCallback. This callback that should be implemented to receive notifications + * from the AsyncHttpClient. The callback implementation is passed as a parameter to a + * {@link org.apache.ahc.codec.HttpRequestMessage HttpRequestMessage}. Each message should have its own + * callback implementation. + * @see org.apache.ahc.codec.HttpRequestMessage + */ public interface AsyncHttpClientCallback { + + /** + * Message response event. Occurs when the {@link AsyncHttpClient} receives a response from the server. + * + * @param message the {@link org.apache.ahc.codec.HttpResponseMessage HttpRequestMessage} message response + */ void onResponse(HttpResponseMessage message); + + /** + * Exception event. Occurs when the {@link AsyncHttpClient} receives any type of Exception from the connection + * through the response. + * + * @param cause the cause of the Exception + */ void onException(Throwable cause); + + /** + * Closed event. Occurs when the {@link AsyncHttpClient} closes the connection. This can occur if + * the remote server closes the connection,after an Exception occurred, after a response is sent, or + * during the handling of a redirect response. This simply signals that the socket has closed. + */ void onClosed(); + + /** + * Timeout event. Occurs when the {@link AsyncHttpClient} times out while waiting for a response from a + * remote server. + */ void onTimeout(); } Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java?rev=579382&r1=579381&r2=579382&view=diff ============================================================================== --- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java (original) +++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java Tue Sep 25 14:11:20 2007 @@ -27,6 +27,9 @@ import org.apache.ahc.util.DateUtil; import org.apache.mina.common.ByteBuffer; +/** + * Utility class for helping to decode the HTTP Protocol + */ public class HttpDecoder { public static final String CHUNKED = "chunked"; @@ -56,9 +59,15 @@ private static final byte LF = 10; - private CharsetDecoder decoder = Charset.defaultCharset().newDecoder(); + /** + * Finds a line from a ByteBuffer that ends with a CR/LF and returns the line as a String + * + * @param in ByteBuffer containing data + * @return a String representing the decoded line + * @throws Exception for any Exception that is encountered + */ public String decodeLine(ByteBuffer in) throws Exception { int beginPos = in.position(); int limit = in.limit(); @@ -95,6 +104,14 @@ return result; } + /** + * Decodes the status code and message from a HTTP response and places the values in a + * HttpResponseMessage object. + * @param line String containing HTTP/1.X Message + * @param msg the HttpResponseMessage for which to place the result + * @throws Exception on any Exception that may occur + * @see HttpResponseMessage + */ public void decodeStatus(String line, HttpResponseMessage msg) throws Exception { String magic = line.substring(0, 8); if (!magic.equals("HTTP/1.1") && !magic.equals("HTTP/1.0")) { Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/package.html URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/package.html?rev=579382&r1=579381&r2=579382&view=diff ============================================================================== --- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/package.html (original) +++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/package.html Tue Sep 25 14:11:20 2007 @@ -21,6 +21,6 @@ --> -

The primary user components for the AsyncHttpClient API

+

The primary user components for the AsyncHttpClient API.

Modified: geronimo/sandbox/AsyncHttpClient/src/main/javadoc/overview.html URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/javadoc/overview.html?rev=579382&r1=579381&r2=579382&view=diff ============================================================================== --- geronimo/sandbox/AsyncHttpClient/src/main/javadoc/overview.html (original) +++ geronimo/sandbox/AsyncHttpClient/src/main/javadoc/overview.html Tue Sep 25 14:11:20 2007 @@ -1,31 +1,39 @@ - + The AsyncHttpClient is a high performance HTTP client API that is based on the Java NIO networking -API. + API. -

The AsyncHttpClient is a high performance HTTP client API that is based on the Java NIO networking -API.

+

The AsyncHttpClient is a high performance HTTP client API that is based on the Java NIO networking API.

This API is based on the Apache MINA framework to provide a high -performance networking library based on the HTTP protocol. +performance networking library based on the HTTP protocol. The AsyncHttpClient utilizes the Java NIO and +mutlithreaded capabilities to be able to handle many concurrent outbound connections without having threads +sitting in a wait state. There are numerous applications this API can be good for, such as gaming applications +or web servers that need to access 3rd party web components and operate under heavy load. The major +implication for this API is the ability to effectively and efficiently make use of threads while waiting for +responses from the server. +

Usage

+Using the AsyncHttpClient is generally simple. In your application, you typically want to create a single +instance of the AsyncHttpClient and use it throughout the life cycle of your application. The AsyncHttpClient +only needs to be created once and reused to send multiple connections to multiple servers.