You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/05/28 17:51:28 UTC
svn commit: r1598052 - in
/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol:
HttpAsyncRequestExecutor.java HttpAsyncRequester.java HttpAsyncService.java
Author: olegk
Date: Wed May 28 15:51:28 2014
New Revision: 1598052
URL: http://svn.apache.org/r1598052
Log:
Use ExceptionLogger in HttpAsyncService, HttpAsyncRequester and HttpAsyncRequestExecutor
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1598052&r1=1598051&r2=1598052&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Wed May 28 15:51:28 2014
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.net.SocketTimeoutException;
import org.apache.http.ConnectionClosedException;
+import org.apache.http.ExceptionLogger;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
@@ -83,6 +84,25 @@ public class HttpAsyncRequestExecutor im
public static final String HTTP_HANDLER = "http.nio.exchange-handler";
private final int waitForContinue;
+ private final ExceptionLogger exceptionLogger;
+
+ /**
+ * Creates new instance of <tt>HttpAsyncRequestExecutor</tt>.
+ * @param waitForContinue wait for continue time period.
+ * @param exceptionLogger Exception logger. If <code>null</code>
+ * {@link ExceptionLogger#NO_OP} will be used. Please note that the exception
+ * logger will be only used to log I/O exception thrown while closing
+ * {@link java.io.Closeable} objects (such as {@link org.apache.http.HttpConnection}).
+ *
+ * @since 4.4
+ */
+ public HttpAsyncRequestExecutor(
+ final int waitForContinue,
+ final ExceptionLogger exceptionLogger) {
+ super();
+ this.waitForContinue = Args.positive(waitForContinue, "Wait for continue time");
+ this.exceptionLogger = exceptionLogger != null ? exceptionLogger : ExceptionLogger.NO_OP;
+ }
/**
* Creates new instance of HttpAsyncRequestExecutor.
@@ -90,12 +110,11 @@ public class HttpAsyncRequestExecutor im
* @since 4.3
*/
public HttpAsyncRequestExecutor(final int waitForContinue) {
- super();
- this.waitForContinue = Args.positive(waitForContinue, "Wait for continue time");
+ this(waitForContinue, null);
}
public HttpAsyncRequestExecutor() {
- this(DEFAULT_WAIT_FOR_CONTINUE);
+ this(DEFAULT_WAIT_FOR_CONTINUE, null);
}
@Override
@@ -354,6 +373,7 @@ public class HttpAsyncRequestExecutor im
* @param ex I/O exception thrown by {@link java.io.Closeable#close()}
*/
protected void log(final Exception ex) {
+ this.exceptionLogger.log(ex);
}
private State getState(final NHttpConnection conn) {
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java?rev=1598052&r1=1598051&r2=1598052&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java Wed May 28 15:51:28 2014
@@ -33,6 +33,7 @@ import java.util.concurrent.Future;
import org.apache.http.ConnectionClosedException;
import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.ExceptionLogger;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
import org.apache.http.concurrent.BasicFuture;
@@ -62,6 +63,7 @@ public class HttpAsyncRequester {
private final HttpProcessor httpprocessor;
private final ConnectionReuseStrategy connReuseStrategy;
+ private final ExceptionLogger exceptionLogger;
/**
* @deprecated (4.3) use {@link HttpAsyncRequester#HttpAsyncRequester(HttpProcessor,
@@ -76,17 +78,37 @@ public class HttpAsyncRequester {
}
/**
- * Creates new instance of HttpAsyncRequester.
+ * Creates new instance of <tt>HttpAsyncRequester<tt/>.
+ * @param httpProcessor HTTP protocol processor.
+ * @param connStrategy Connection re-use strategy. If <code>null</code>
+ * {@link DefaultConnectionReuseStrategy#INSTANCE} will be used.
+ * @param exceptionLogger Exception logger. If <code>null</code>
+ * {@link ExceptionLogger#NO_OP} will be used. Please note that the exception
+ * logger will be only used to log I/O exception thrown while closing
+ * {@link java.io.Closeable} objects (such as {@link org.apache.http.HttpConnection}).
*
- * @since 4.3
+ * @since 4.4
*/
public HttpAsyncRequester(
final HttpProcessor httpprocessor,
- final ConnectionReuseStrategy connReuseStrategy) {
+ final ConnectionReuseStrategy connReuseStrategy,
+ final ExceptionLogger exceptionLogger) {
super();
this.httpprocessor = Args.notNull(httpprocessor, "HTTP processor");
this.connReuseStrategy = connReuseStrategy != null ? connReuseStrategy :
- DefaultConnectionReuseStrategy.INSTANCE;
+ DefaultConnectionReuseStrategy.INSTANCE;
+ this.exceptionLogger = exceptionLogger != null ? exceptionLogger : ExceptionLogger.NO_OP;
+ }
+
+ /**
+ * Creates new instance of HttpAsyncRequester.
+ *
+ * @since 4.3
+ */
+ public HttpAsyncRequester(
+ final HttpProcessor httpprocessor,
+ final ConnectionReuseStrategy connReuseStrategy) {
+ this(httpprocessor, connReuseStrategy, (ExceptionLogger) null);
}
/**
@@ -553,6 +575,7 @@ public class HttpAsyncRequester {
* @param ex I/O exception thrown by {@link java.io.Closeable#close()}
*/
protected void log(final Exception ex) {
+ this.exceptionLogger.log(ex);
}
private void close(final Closeable closeable) {
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java?rev=1598052&r1=1598051&r2=1598052&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java Wed May 28 15:51:28 2014
@@ -33,6 +33,7 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.ExceptionLogger;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
@@ -106,6 +107,7 @@ public class HttpAsyncService implements
private final HttpResponseFactory responseFactory;
private final HttpAsyncRequestHandlerMapper handlerMapper;
private final HttpAsyncExpectationVerifier expectationVerifier;
+ private final ExceptionLogger exceptionLogger;
/**
* Creates new instance of <tt>HttpAsyncServerProtocolHandler</tt>.
@@ -180,14 +182,42 @@ public class HttpAsyncService implements
final HttpResponseFactory responseFactory,
final HttpAsyncRequestHandlerMapper handlerMapper,
final HttpAsyncExpectationVerifier expectationVerifier) {
+ this(httpProcessor, connStrategy, responseFactory, handlerMapper, expectationVerifier, null);
+ }
+
+ /**
+ * Creates new instance of <tt>HttpAsyncServerProtocolHandler</tt>.
+ *
+ * @param httpProcessor HTTP protocol processor.
+ * @param connStrategy Connection re-use strategy. If <code>null</code>
+ * {@link DefaultConnectionReuseStrategy#INSTANCE} will be used.
+ * @param responseFactory HTTP response factory. If <code>null</code>
+ * {@link DefaultHttpResponseFactory#INSTANCE} will be used.
+ * @param handlerMapper Request handler mapper.
+ * @param expectationVerifier Request expectation verifier. May be <code>null</code>.
+ * @param exceptionLogger Exception logger. If <code>null</code>
+ * {@link ExceptionLogger#NO_OP} will be used. Please note that the exception
+ * logger will be only used to log I/O exception thrown while closing
+ * {@link java.io.Closeable} objects (such as {@link org.apache.http.HttpConnection}).
+ *
+ * @since 4.4
+ */
+ public HttpAsyncService(
+ final HttpProcessor httpProcessor,
+ final ConnectionReuseStrategy connStrategy,
+ final HttpResponseFactory responseFactory,
+ final HttpAsyncRequestHandlerMapper handlerMapper,
+ final HttpAsyncExpectationVerifier expectationVerifier,
+ final ExceptionLogger exceptionLogger) {
super();
this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
this.connStrategy = connStrategy != null ? connStrategy :
- DefaultConnectionReuseStrategy.INSTANCE;
+ DefaultConnectionReuseStrategy.INSTANCE;
this.responseFactory = responseFactory != null ? responseFactory :
- DefaultHttpResponseFactory.INSTANCE;
+ DefaultHttpResponseFactory.INSTANCE;
this.handlerMapper = handlerMapper;
this.expectationVerifier = expectationVerifier;
+ this.exceptionLogger = exceptionLogger != null ? exceptionLogger : ExceptionLogger.NO_OP;
}
/**
@@ -204,6 +234,25 @@ public class HttpAsyncService implements
this(httpProcessor, null, null, handlerMapper, null);
}
+ /**
+ * Creates new instance of <tt>HttpAsyncServerProtocolHandler</tt>.
+ *
+ * @param httpProcessor HTTP protocol processor.
+ * @param handlerMapper Request handler mapper.
+ * @param exceptionLogger Exception logger. If <code>null</code>
+ * {@link ExceptionLogger#NO_OP} will be used. Please note that the exception
+ * logger will be only used to log I/O exception thrown while closing
+ * {@link java.io.Closeable} objects (such as {@link org.apache.http.HttpConnection}).
+ *
+ * @since 4.4
+ */
+ public HttpAsyncService(
+ final HttpProcessor httpProcessor,
+ final HttpAsyncRequestHandlerMapper handlerMapper,
+ final ExceptionLogger exceptionLogger) {
+ this(httpProcessor, null, null, handlerMapper, null, exceptionLogger);
+ }
+
@Override
public void connected(final NHttpServerConnection conn) {
final State state = new State();
@@ -486,6 +535,7 @@ public class HttpAsyncService implements
* @param ex I/O exception thrown by {@link java.io.Closeable#close()}
*/
protected void log(final Exception ex) {
+ this.exceptionLogger.log(ex);
}
private void closeConnection(final NHttpConnection conn) {