Package com.tinkerpop.gremlin.driver.message

Examples of com.tinkerpop.gremlin.driver.message.ResponseMessage$Builder


        if (error.get() != null) throw new RuntimeException(error.get());
        return this.size() == 0;
    }

    public ResponseMessage poll() {
        ResponseMessage msg = null;
        do {
            if (error.get() != null) throw new RuntimeException(error.get());
            try {
                msg = responseQueue.poll(10, TimeUnit.MILLISECONDS);
            } catch (InterruptedException ie) {
View Full Code Here


    /**
     * Get the next {@link Result} from the stream, blocking until one is available.
     */
    public Result one() {
        ResponseMessage msg = responseQueue.poll();
        if (msg != null)
            return new Result(msg);

        awaitItems(1).join();

View Full Code Here

     */
    public CompletableFuture<List<Result>> all() {
        return CompletableFuture.supplyAsync(() -> {
            final List<Result> list = new ArrayList<>();
            while (!isExhausted()) {
                final ResponseMessage msg = responseQueue.poll();
                if (msg != null)
                    list.add(new Result(msg));
            }
            return list;
        }, executor);
View Full Code Here

    private final UUID id = UUID.fromString("AB23423F-ED64-486B-8976-DBFD0DB85318");
    private final Graph g = TinkerFactory.createClassic();

    @Test
    public void shouldGetString() {
        final ResponseMessage msg = ResponseMessage.build(id).result("string").create();
        final Result result = new Result(msg);

        assertEquals("string", result.getString());
        assertEquals("string", result.get(String.class));
    }
View Full Code Here

        assertEquals("string", result.get(String.class));
    }

    @Test
    public void shouldGetInt() {
        final ResponseMessage msg = ResponseMessage.build(id).result(100).create();
        final Result result = new Result(msg);

        assertEquals(100, result.getInt());
        assertEquals(100, result.get(Integer.class).intValue());
    }
View Full Code Here

        assertEquals(100, result.get(Integer.class).intValue());
    }

    @Test
    public void shouldGetByte() {
        final ResponseMessage msg = ResponseMessage.build(id).result((byte) 100).create();
        final Result result = new Result(msg);

        assertEquals((byte) 100, result.getByte());
        assertEquals((byte) 100, result.get(Byte.class).byteValue());
    }
View Full Code Here

    public void serializeIterable() throws Exception {
        final ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(100);

        final ResponseMessage response = convert(list);
        assertCommon(response);

        final List<Integer> deserializedFunList = (List<Integer>) response.getResult().getData();
        assertEquals(2, deserializedFunList.size());
        assertEquals(new Integer(1), deserializedFunList.get(0));
        assertEquals(new Integer(100), deserializedFunList.get(1));
    }
View Full Code Here

        assertEquals((byte) 100, result.get(Byte.class).byteValue());
    }

    @Test
    public void shouldGetShort() {
        final ResponseMessage msg = ResponseMessage.build(id).result((short) 100).create();
        final Result result = new Result(msg);

        assertEquals((short) 100, result.getShort());
        assertEquals((short) 100, result.get(Short.class).shortValue());
    }
View Full Code Here

        final ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(null);
        list.add(100);

        final ResponseMessage response = convert(list);
        assertCommon(response);

        final List<Integer> deserializedFunList = (List<Integer>) response.getResult().getData();
        assertEquals(3, deserializedFunList.size());
        assertEquals(new Integer(1), deserializedFunList.get(0));
        assertNull(deserializedFunList.get(1));
        assertEquals(new Integer(100), deserializedFunList.get(2));
    }
View Full Code Here

            if (useBinary) {
                if (responseMessage.getStatus().getCode().isSuccess())
                    byteBuf.writeBytes(serializer.serializeResponseAsBinary(responseMessage, channelHandlerContext.alloc()));
                else {
                    byteBuf.writeBytes(serializer.serializeResponseAsBinary(responseMessage, channelHandlerContext.alloc()));
                    final ResponseMessage terminator = ResponseMessage.build(responseMessage.getRequestId()).code(ResponseStatusCode.SUCCESS_TERMINATOR).create();
                    byteBuf.writeBytes(serializer.serializeResponseAsBinary(terminator, channelHandlerContext.alloc()));
                    errorMeter.mark();
                }
            } else {
                // the expectation is that the GremlinTextRequestDecoder will have placed a MessageTextSerializer
                // instance on the channel.
                final MessageTextSerializer textSerializer = (MessageTextSerializer) serializer;
                if (responseMessage.getStatus().getCode().isSuccess())
                    byteBuf.writeBytes(textSerializer.serializeResponseAsString(responseMessage).getBytes(UTF8));
                else {
                    byteBuf.writeBytes(textSerializer.serializeResponseAsString(responseMessage).getBytes(UTF8));
                    final ResponseMessage terminator = ResponseMessage.build(responseMessage.getRequestId()).code(ResponseStatusCode.SUCCESS_TERMINATOR).create();
                    byteBuf.writeBytes(textSerializer.serializeResponseAsString(terminator).getBytes(UTF8));
                    errorMeter.mark();
                }
            }
        } catch (Exception ex) {
            errorMeter.mark();
            logger.warn("The result [{}] in the request {} could not be serialized and returned.", responseMessage.getResult(), responseMessage.getRequestId(), ex);
            final String errorMessage = String.format("Error during serialization: %s",
                    ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
            final ResponseMessage error = ResponseMessage.build(responseMessage.getRequestId())
                    .statusMessage(errorMessage)
                    .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create();
            if (useBinary) {
                channelHandlerContext.write(serializer.serializeResponseAsBinary(error, channelHandlerContext.alloc()));
                final ResponseMessage terminator = ResponseMessage.build(responseMessage.getRequestId()).code(ResponseStatusCode.SUCCESS_TERMINATOR).create();
                channelHandlerContext.writeAndFlush(serializer.serializeResponseAsBinary(terminator, channelHandlerContext.alloc()));
            } else {
                final MessageTextSerializer textSerializer = (MessageTextSerializer) serializer;
                channelHandlerContext.write(textSerializer.serializeResponseAsString(error));
                final ResponseMessage terminator = ResponseMessage.build(responseMessage.getRequestId()).code(ResponseStatusCode.SUCCESS_TERMINATOR).create();
                channelHandlerContext.writeAndFlush(textSerializer.serializeResponseAsString(terminator));
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.gremlin.driver.message.ResponseMessage$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.