You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2018/09/18 22:21:51 UTC
[2/2] httpcomponents-core git commit: Replace object creation with
reference to static final object.
Replace object creation with reference to static final object.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/45c06ea3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/45c06ea3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/45c06ea3
Branch: refs/heads/master
Commit: 45c06ea3b8715f9043560cff751252e5cfe264db
Parents: e6242e0
Author: Gary Gregory <gg...@rocketsoftware.com>
Authored: Tue Sep 18 16:21:47 2018 -0600
Committer: Gary Gregory <gg...@rocketsoftware.com>
Committed: Tue Sep 18 16:21:47 2018 -0600
----------------------------------------------------------------------
.../bootstrap/Http2MultiplexingRequester.java | 11 ++--------
.../hc/core5/testing/nio/IOReactorExecutor.java | 10 +--------
.../http/impl/bootstrap/HttpAsyncRequester.java | 11 ++--------
.../http/impl/bootstrap/HttpAsyncServer.java | 12 ++---------
.../core5/http/nio/command/ShutdownCommand.java | 22 +++++++++++++++++---
5 files changed, 26 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/45c06ea3/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2MultiplexingRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2MultiplexingRequester.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2MultiplexingRequester.java
index ae48264..11c2785 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2MultiplexingRequester.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2MultiplexingRequester.java
@@ -39,7 +39,6 @@ import org.apache.hc.core5.concurrent.Cancellable;
import org.apache.hc.core5.concurrent.CancellableDependency;
import org.apache.hc.core5.concurrent.ComplexFuture;
import org.apache.hc.core5.concurrent.FutureCallback;
-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.EntityDetails;
@@ -96,14 +95,8 @@ public class Http2MultiplexingRequester extends AsyncRequester{
final IOSessionListener sessionListener,
final Resolver<HttpHost, InetSocketAddress> addressResolver,
final TlsStrategy tlsStrategy) {
- super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, sessionListener, new Callback<IOSession>() {
-
- @Override
- public void execute(final IOSession session) {
- session.enqueue(ShutdownCommand.GRACEFUL, Command.Priority.IMMEDIATE);
- }
-
- }, DefaultAddressResolver.INSTANCE);
+ super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, sessionListener,
+ ShutdownCommand.GRACEFUL_IMMEDIATE_CALLBACK, DefaultAddressResolver.INSTANCE);
this.connPool = new H2ConnPool(this, addressResolver, tlsStrategy);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/45c06ea3/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
index 4ecd05f..1b739c6 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
@@ -36,7 +36,6 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.http.nio.command.ShutdownCommand;
import org.apache.hc.core5.io.CloseMode;
-import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.ExceptionEvent;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
import org.apache.hc.core5.reactor.IOReactorConfig;
@@ -76,14 +75,7 @@ abstract class IOReactorExecutor<T extends IOReactorService> implements AutoClos
ioEventHandlerFactory,
ioReactorConfig,
workerThreadFactory,
- new Callback<IOSession>() {
-
- @Override
- public void execute(final IOSession session) {
- session.enqueue(ShutdownCommand.GRACEFUL, Command.Priority.NORMAL);
- }
-
- }))) {
+ ShutdownCommand.GRACEFUL_NORMAL_CALLBACK))) {
if (status.compareAndSet(Status.READY, Status.RUNNING)) {
ioReactorRef.get().start();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/45c06ea3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index f24ae59..1fee83f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -38,7 +38,6 @@ import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.concurrent.BasicFuture;
import org.apache.hc.core5.concurrent.ComplexFuture;
import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.function.Decorator;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
@@ -101,14 +100,8 @@ public class HttpAsyncRequester extends AsyncRequester implements ConnPoolContro
final IOSessionListener sessionListener,
final ManagedConnPool<HttpHost, IOSession> connPool,
final TlsStrategy tlsStrategy) {
- super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, sessionListener, new Callback<IOSession>() {
-
- @Override
- public void execute(final IOSession session) {
- session.enqueue(ShutdownCommand.GRACEFUL, Command.Priority.IMMEDIATE);
- }
-
- }, DefaultAddressResolver.INSTANCE);
+ super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, sessionListener,
+ ShutdownCommand.GRACEFUL_IMMEDIATE_CALLBACK, DefaultAddressResolver.INSTANCE);
this.connPool = Args.notNull(connPool, "Connection pool");
this.tlsStrategy = tlsStrategy;
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/45c06ea3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
index 1077031..46c1cbd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
@@ -27,10 +27,8 @@
package org.apache.hc.core5.http.impl.bootstrap;
import org.apache.hc.core5.annotation.Internal;
-import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.function.Decorator;
import org.apache.hc.core5.http.nio.command.ShutdownCommand;
-import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.IOSession;
@@ -52,14 +50,8 @@ public class HttpAsyncServer extends AsyncServer {
final IOReactorConfig ioReactorConfig,
final Decorator<IOSession> ioSessionDecorator,
final IOSessionListener sessionListener) {
- super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, sessionListener, new Callback<IOSession>() {
-
- @Override
- public void execute(final IOSession session) {
- session.enqueue(ShutdownCommand.GRACEFUL, Command.Priority.NORMAL);
- }
-
- });
+ super(eventHandlerFactory, ioReactorConfig, ioSessionDecorator, sessionListener,
+ ShutdownCommand.GRACEFUL_NORMAL_CALLBACK);
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/45c06ea3/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
index bb215f6..7a3a150 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
@@ -27,13 +27,15 @@
package org.apache.hc.core5.http.nio.command;
+import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.reactor.Command;
+import org.apache.hc.core5.reactor.IOSession;
/**
- * Shutdown command. Two shutdown modes are supported: {@link CloseMode#GRACEFUL}
- * and {@link CloseMode#IMMEDIATE}. The exact implementation of both modes is protocol
- * or handler specific.
+ * Shutdown command. Two shutdown modes are supported: {@link CloseMode#GRACEFUL} and
+ * {@link CloseMode#IMMEDIATE}. The exact implementation of both modes is protocol or handler
+ * specific.
*
* @since 5.0
*/
@@ -42,6 +44,20 @@ public final class ShutdownCommand implements Command {
public static final ShutdownCommand GRACEFUL = new ShutdownCommand(CloseMode.GRACEFUL);
public static final ShutdownCommand IMMEDIATE = new ShutdownCommand(CloseMode.IMMEDIATE);
+ public static final Callback<IOSession> GRACEFUL_IMMEDIATE_CALLBACK = createIOSessionCallback(Priority.IMMEDIATE);
+ public static final Callback<IOSession> GRACEFUL_NORMAL_CALLBACK = createIOSessionCallback(Priority.NORMAL);
+
+ private static Callback<IOSession> createIOSessionCallback(final Priority priority) {
+ return new Callback<IOSession>() {
+
+ @Override
+ public void execute(final IOSession session) {
+ session.enqueue(ShutdownCommand.GRACEFUL, priority);
+ }
+
+ };
+ }
+
private final CloseMode type;
public ShutdownCommand(final CloseMode type) {