You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "vkagamlyk (via GitHub)" <gi...@apache.org> on 2024/04/10 16:26:19 UTC

[PR] draft java driver [tinkerpop]

vkagamlyk opened a new pull request, #2557:
URL: https://github.com/apache/tinkerpop/pull/2557

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] draft java driver [tinkerpop]

Posted by "vkagamlyk (via GitHub)" <gi...@apache.org>.
vkagamlyk merged PR #2557:
URL: https://github.com/apache/tinkerpop/pull/2557


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] draft java driver [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on code in PR #2557:
URL: https://github.com/apache/tinkerpop/pull/2557#discussion_r1560173177


##########
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/handler/HttpGremlinResponseStreamDecoder.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.driver.handler;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageDecoder;
+import io.netty.handler.codec.http.DefaultHttpContent;
+import io.netty.handler.codec.http.DefaultHttpObject;
+import io.netty.handler.codec.http.DefaultHttpResponse;
+import io.netty.handler.codec.http.DefaultLastHttpContent;
+import io.netty.handler.codec.http.HttpHeaders;
+import io.netty.util.Attribute;
+import io.netty.util.AttributeKey;
+import io.netty.util.AttributeMap;
+import org.apache.tinkerpop.gremlin.util.message.ResponseMessage;
+import org.apache.tinkerpop.gremlin.util.ser.MessageTextSerializerV4;
+import org.apache.tinkerpop.gremlin.util.ser.SerializationException;
+
+import java.util.List;
+import java.util.Objects;
+
+public class HttpGremlinResponseStreamDecoder extends MessageToMessageDecoder<DefaultHttpObject> {
+
+    // todo: move out
+    public static final AttributeKey<Boolean> IS_FIRST_CHUNK = AttributeKey.valueOf("isFirstChunk");
+
+    private final MessageTextSerializerV4<?> serializer;
+
+    public HttpGremlinResponseStreamDecoder(MessageTextSerializerV4<?> serializer) {
+        this.serializer = serializer;
+    }
+
+    @Override
+    protected void decode(ChannelHandlerContext ctx, DefaultHttpObject msg, List<Object> out) throws Exception {
+        final Attribute<Boolean> isFirstChunk = ((AttributeMap) ctx).attr(IS_FIRST_CHUNK);
+
+        System.out.println("HttpGremlinResponseStreamDecoder start");
+
+        if (msg instanceof DefaultHttpResponse) {
+            isFirstChunk.set(true);
+        }
+
+        if (msg instanceof DefaultHttpContent) {
+            try {
+                if (isFirstChunk.get()) {
+                    System.out.println("first chunk");
+                } else {
+                    System.out.println("not first chunk");
+                }
+
+                final ResponseMessage chunk = serializer.readChunk(((DefaultHttpContent) msg).content(), isFirstChunk.get());
+
+                if (chunk.getResult().getData() != null) {
+                    System.out.println("payload size: " + ((List) chunk.getResult().getData()).size());
+                }
+
+                if (msg instanceof DefaultLastHttpContent) {
+                    final HttpHeaders trailingHeaders = ((DefaultLastHttpContent) msg).trailingHeaders();
+
+                    System.out.println("final chunk, trailing headers:");
+                    System.out.println(trailingHeaders);
+
+                    if (!Objects.equals(trailingHeaders.get("code"), "200")) {
+                        throw new Exception(trailingHeaders.get("message"));
+                    }
+                }
+
+                isFirstChunk.set(false);
+
+                out.add(chunk);

Review Comment:
   We might want to make something like a PartialResponseMessage class. It could get a little confusing for others that don't realize that one large ResponseMessage is formed by serializing multiple partial ResponseMessage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] draft java driver [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on code in PR #2557:
URL: https://github.com/apache/tinkerpop/pull/2557#discussion_r1560170570


##########
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/handler/HttpGremlinResponseStreamDecoder.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.driver.handler;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageDecoder;
+import io.netty.handler.codec.http.DefaultHttpContent;
+import io.netty.handler.codec.http.DefaultHttpObject;
+import io.netty.handler.codec.http.DefaultHttpResponse;
+import io.netty.handler.codec.http.DefaultLastHttpContent;
+import io.netty.handler.codec.http.HttpHeaders;
+import io.netty.util.Attribute;
+import io.netty.util.AttributeKey;
+import io.netty.util.AttributeMap;
+import org.apache.tinkerpop.gremlin.util.message.ResponseMessage;
+import org.apache.tinkerpop.gremlin.util.ser.MessageTextSerializerV4;
+import org.apache.tinkerpop.gremlin.util.ser.SerializationException;
+
+import java.util.List;
+import java.util.Objects;
+
+public class HttpGremlinResponseStreamDecoder extends MessageToMessageDecoder<DefaultHttpObject> {
+
+    // todo: move out
+    public static final AttributeKey<Boolean> IS_FIRST_CHUNK = AttributeKey.valueOf("isFirstChunk");
+
+    private final MessageTextSerializerV4<?> serializer;
+
+    public HttpGremlinResponseStreamDecoder(MessageTextSerializerV4<?> serializer) {
+        this.serializer = serializer;
+    }
+
+    @Override
+    protected void decode(ChannelHandlerContext ctx, DefaultHttpObject msg, List<Object> out) throws Exception {
+        final Attribute<Boolean> isFirstChunk = ((AttributeMap) ctx).attr(IS_FIRST_CHUNK);
+
+        System.out.println("HttpGremlinResponseStreamDecoder start");
+
+        if (msg instanceof DefaultHttpResponse) {
+            isFirstChunk.set(true);
+        }
+
+        if (msg instanceof DefaultHttpContent) {
+            try {
+                if (isFirstChunk.get()) {
+                    System.out.println("first chunk");
+                } else {
+                    System.out.println("not first chunk");
+                }
+
+                final ResponseMessage chunk = serializer.readChunk(((DefaultHttpContent) msg).content(), isFirstChunk.get());
+
+                if (chunk.getResult().getData() != null) {
+                    System.out.println("payload size: " + ((List) chunk.getResult().getData()).size());
+                }
+
+                if (msg instanceof DefaultLastHttpContent) {

Review Comment:
   ```suggestion
                   if (msg instanceof LastHttpContent) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org