Package com.tinkerpop.gremlin.server.op.session

Examples of com.tinkerpop.gremlin.server.op.session.Session


    @Override
    protected void encode(final ChannelHandlerContext channelHandlerContext, final ResponseMessage o, final List<Object> objects) throws Exception {
        final MessageSerializer serializer = channelHandlerContext.channel().attr(StateKey.SERIALIZER).get();
        final boolean useBinary = channelHandlerContext.channel().attr(StateKey.USE_BINARY).get();
        final Session session = channelHandlerContext.channel().attr(StateKey.SESSION).get();

        try {
            if (useBinary) {
                final ByteBuf serialized;

                // if the request came in on a session then the serialization must occur in that same thread.
                if (null == session)
                    serialized = serializer.serializeResponseAsBinary(o, channelHandlerContext.alloc());
                else
                    serialized = session.getExecutor().submit(() -> serializer.serializeResponseAsBinary(o, channelHandlerContext.alloc())).get();

                if (o.getStatus().getCode().isSuccess())
                    objects.add(new BinaryWebSocketFrame(serialized));
                else {
                    objects.add(new BinaryWebSocketFrame(serialized));
                    final ResponseMessage terminator = ResponseMessage.build(o.getRequestId()).code(ResponseStatusCode.SUCCESS_TERMINATOR).create();
                    objects.add(new BinaryWebSocketFrame(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;

                final String serialized;

                // if the request came in on a session then the serialization must occur in that same thread.
                if (null == session)
                    serialized = textSerializer.serializeResponseAsString(o);
                else
                    serialized = session.getExecutor().submit(() -> textSerializer.serializeResponseAsString(o)).get();

                if (o.getStatus().getCode().isSuccess())
                    objects.add(new TextWebSocketFrame(true, 0, serialized));
                else {
                    objects.add(new TextWebSocketFrame(true, 0, serialized));
View Full Code Here

TOP

Related Classes of com.tinkerpop.gremlin.server.op.session.Session

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.