You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/03/08 18:15:30 UTC

[2/5] incubator-tinkerpop git commit: Minor refactoring to extract Connection shutdown function.

Minor refactoring to extract Connection shutdown function.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/4abb58bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/4abb58bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/4abb58bf

Branch: refs/heads/tp31
Commit: 4abb58bf5df63b71d2ccab893f7f9f354e2391a1
Parents: fba51aa
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Mar 1 16:52:27 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Mar 1 16:52:27 2016 -0500

----------------------------------------------------------------------
 .../tinkerpop/gremlin/driver/Connection.java      | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4abb58bf/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
index 9767fbd..10d3b89 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
@@ -191,11 +191,7 @@ final class Connection {
                         // was called
                         readCompleted.thenAcceptAsync(v -> {
                             thisConnection.returnToPool();
-
-                            // close was signaled in closeAsync() but there were pending messages at that time. attempt
-                            // the shutdown if the returned result cleared up the last pending message
-                            if (isClosed() && pending.isEmpty())
-                                shutdown(closeFuture.get());
+                            tryShutdown();
                         }, cluster.executor());
 
                         // the callback for when the read failed. a failed read means the request went to the server
@@ -218,8 +214,7 @@ final class Connection {
 
                             // close was signaled in closeAsync() but there were pending messages at that time. attempt
                             // the shutdown if the returned result cleared up the last pending message
-                            if (isClosed() && pending.isEmpty())
-                                shutdown(closeFuture.get());
+                            tryShutdown();
 
                             return null;
                         });
@@ -243,6 +238,15 @@ final class Connection {
         }
     }
 
+    /**
+     * Close was signaled in closeAsync() but there were pending messages at that time. This method attempts the
+     * shutdown if the returned result cleared up the last pending message.
+     */
+    private void tryShutdown() {
+        if (isClosed() && pending.isEmpty())
+            shutdown(closeFuture.get());
+    }
+
     private void shutdown(final CompletableFuture<Void> future) {
         // shutdown can be called directly from closeAsync() or after write() and therefore this method should only
         // be called once. once shutdown is initiated, it shoudln't be executed a second time or else it sends more