Make IOReactor IO session decorator and exception callback configurable.
This commit is contained in:
parent
dfc2086d24
commit
1fb79b96f6
|
@ -74,6 +74,8 @@ import org.apache.hc.client5.http.routing.HttpRoutePlanner;
|
|||
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
|
||||
import org.apache.hc.core5.annotation.Internal;
|
||||
import org.apache.hc.core5.concurrent.DefaultThreadFactory;
|
||||
import org.apache.hc.core5.function.Callback;
|
||||
import org.apache.hc.core5.function.Decorator;
|
||||
import org.apache.hc.core5.function.Resolver;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
@ -99,6 +101,7 @@ import org.apache.hc.core5.reactor.Command;
|
|||
import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
|
||||
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
|
||||
import org.apache.hc.core5.reactor.IOReactorConfig;
|
||||
import org.apache.hc.core5.reactor.IOSession;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.VersionInfo;
|
||||
|
@ -207,6 +210,11 @@ public class H2AsyncClientBuilder {
|
|||
|
||||
private List<Closeable> closeables;
|
||||
|
||||
|
||||
private Callback<Exception> ioReactorExceptionCallback;
|
||||
|
||||
private Decorator<IOSession> ioSessionDecorator;
|
||||
|
||||
public static H2AsyncClientBuilder create() {
|
||||
return new H2AsyncClientBuilder();
|
||||
}
|
||||
|
@ -259,6 +267,27 @@ public class H2AsyncClientBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback that will be invoked when the client's IOReactor encounters an uncaught exception.
|
||||
*
|
||||
* @since 5.2
|
||||
*/
|
||||
public final H2AsyncClientBuilder setIoReactorExceptionCallback(final Callback<Exception> ioReactorExceptionCallback) {
|
||||
this.ioReactorExceptionCallback = ioReactorExceptionCallback;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the {@link IOSession} {@link Decorator} that will be use with the client's IOReactor.
|
||||
*
|
||||
* @since 5.2
|
||||
*/
|
||||
public final H2AsyncClientBuilder setIoSessionDecorator(final Decorator<IOSession> ioSessionDecorator) {
|
||||
this.ioSessionDecorator = ioSessionDecorator;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this protocol interceptor to the head of the protocol processing list.
|
||||
*/
|
||||
|
@ -733,8 +762,8 @@ public class H2AsyncClientBuilder {
|
|||
ioEventHandlerFactory,
|
||||
ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
|
||||
threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-dispatch", true),
|
||||
LoggingIOSessionDecorator.INSTANCE,
|
||||
LoggingExceptionCallback.INSTANCE,
|
||||
ioSessionDecorator != null ? ioSessionDecorator : LoggingIOSessionDecorator.INSTANCE,
|
||||
ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE,
|
||||
null,
|
||||
ioSession -> ioSession.enqueue(new ShutdownCommand(CloseMode.GRACEFUL), Command.Priority.IMMEDIATE));
|
||||
|
||||
|
|
Loading…
Reference in New Issue