use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project cypher-for-gremlin by opencypher.
the class CypherOpProcessor method traversal.
private GraphTraversalSource traversal(Context context) throws OpProcessorException {
RequestMessage msg = context.getRequestMessage();
GraphManager graphManager = context.getGraphManager();
Optional<Map<String, String>> aliasesOptional = msg.optionalArgs(Tokens.ARGS_ALIASES);
String gAlias = aliasesOptional.map(aliases -> aliases.get(Tokens.VAL_TRAVERSAL_SOURCE_ALIAS)).orElse(null);
if (gAlias == null) {
return graphManager.getGraphNames().stream().findFirst().map(graphManager::getGraph).map(Graph::traversal).orElseThrow(() -> opProcessorException(msg, "No graphs found on the server"));
}
Graph graph = graphManager.getGraph(gAlias);
if (graph != null) {
return graph.traversal();
}
TraversalSource traversalSource = graphManager.getTraversalSource(gAlias);
if (traversalSource instanceof GraphTraversalSource) {
return (GraphTraversalSource) traversalSource;
}
throw opProcessorException(msg, "Traversable alias '" + gAlias + "' not found");
}
use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project cypher-for-gremlin by opencypher.
the class ClientServerCommunicationTest method createRequestTest.
@Test
public void createRequestTest() throws Exception {
RequestMessage request = buildRequest("cypher").create();
assertThat(request.getOp()).isEqualTo(Tokens.OPS_EVAL);
assertThat(request.getProcessor()).isEqualTo(CYPHER_OP_PROCESSOR_NAME);
assertThat(request.getArgs()).containsOnly(entry(Tokens.ARGS_GREMLIN, "cypher"));
}
use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project janusgraph by JanusGraph.
the class JanusGraphIoRegistryTest method serializationTest.
private void serializationTest(GraphTraversal[] traversals) throws SerializationException {
Builder mapper = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());
MessageSerializer binarySerializer = new GryoMessageSerializerV1d0(mapper);
for (GraphTraversal traversal : traversals) {
Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
RequestMessage requestMessage = RequestMessage.build(Tokens.OPS_BYTECODE).processor("traversal").addArg(Tokens.ARGS_GREMLIN, expectedBytecode).create();
ByteBuf bb = binarySerializer.serializeRequestAsBinary(requestMessage, allocator);
final int mimeLen = bb.readByte();
bb.readBytes(new byte[mimeLen]);
RequestMessage deser = binarySerializer.deserializeRequest(bb);
Bytecode result = (Bytecode) deser.getArgs().get(Tokens.ARGS_GREMLIN);
assertEquals(expectedBytecode, result);
}
}
use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project cypher-for-gremlin by opencypher.
the class OpProcessorCypherGremlinClient method submitAsync.
@Override
public CompletableFuture<CypherResultSet> submitAsync(String cypher, Map<String, ?> parameters) {
RequestMessage requestMessage = buildRequest(cypher, parameters).create();
CompletableFuture<ResultSet> resultSetFuture = client.submitAsync(requestMessage);
return resultSetFuture.thenApply(ResultSet::iterator).thenApply(CypherResultSet::new);
}
Aggregations