You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/05/07 23:30:24 UTC

[15/24] incubator-tinkerpop git commit: Small optimization in gremlin-driver to prevent recreation of ResponseMessage instances.

Small optimization in gremlin-driver to prevent recreation of ResponseMessage instances.


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

Branch: refs/heads/TINKERPOP3-666
Commit: c86826e0cbd5343511160b46889764b3db94a477
Parents: 6888509
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 7 14:48:49 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 7 14:48:49 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/driver/Handler.java       | 23 +++++++++++++++-----
 .../tinkerpop/gremlin/driver/ResponseQueue.java |  2 +-
 2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c86826e0/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
index 88a1601..ebfdf11 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
@@ -30,12 +30,16 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 
 /**
- * Traverser for internal handler classes for constructing the Channel Pipeline.
+ * Holder for internal handler classes used in constructing the channel pipeline.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 class Handler {
 
+    /**
+     * Takes a map of requests pending responses and writes responses to the {@link ResponseQueue} of a request
+     * as the {@link ResponseMessage} objects are deserialized.
+     */
     static class GremlinResponseHandler extends SimpleChannelInboundHandler<ResponseMessage> {
         private final ConcurrentMap<UUID, ResponseQueue> pending;
 
@@ -50,18 +54,25 @@ class Handler {
                         response.getStatus().getCode() == ResponseStatusCode.PARTIAL_CONTENT) {
                     final Object data = response.getResult().getData();
                     if (data instanceof List) {
-                        // unrolls the collection into individual response messages to be handled by the queue
+                        // unrolls the collection into individual response messages to be handled by the queue. of
+                        // course, this assumes that the list is of size greater than 1 - else it can be treated as
+                        // a normal object as there is no need to create new ResponseMessage instances for it
                         final List<Object> listToUnroll = (List<Object>) data;
                         final ResponseQueue queue = pending.get(response.getRequestId());
-                        listToUnroll.forEach(item -> queue.add(
-                                ResponseMessage.build(response.getRequestId())
-                                        .result(item).create()));
+                        if (listToUnroll.size() == 1) {
+                            queue.add(response);
+                        } else {
+                            listToUnroll.forEach(item -> queue.add(
+                                    ResponseMessage.build(response.getRequestId())
+                                            .result(item).create()));
+                        }
                     } else {
                         // since this is not a list it can just be added to the queue
                         pending.get(response.getRequestId()).add(response);
                     }
-                } else
+                } else {
                     pending.get(response.getRequestId()).markError(new ResponseException(response.getStatus().getCode(), response.getStatus().getMessage()));
+                }
 
                 // todo: should this go in finally? where is the catch?
                 // as this is a non-PARTIAL_CONTENT code - the stream is done

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c86826e0/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResponseQueue.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResponseQueue.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResponseQueue.java
index b3cfbfe..40055b5 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResponseQueue.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResponseQueue.java
@@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * A queue of incoming {@link ResponseMessage} objects.  The queue is updated by the
- * {@link org.apache.tinkerpop.gremlin.driver.Handler.GremlinResponseHandler} until a response terminator is identified.  At that point the fetch
+ * {@link Handler.GremlinResponseHandler} until a response terminator is identified.  At that point the fetch
  * status is changed to {@link Status#COMPLETE} and all results have made it client side.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)