forked from krlawrence/graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteClient.java
More file actions
64 lines (54 loc) · 1.91 KB
/
Copy pathRemoteClient.java
File metadata and controls
64 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// RemoteClient.java
//
// Simple example of using GremlinServer from a Java client
//
// This example does the following:
// 1. Configure a new Cluster object
// 2. Use that cluster to connect to a Gremlin Server
// 3. Run a few queries against graph
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
public class RemoteClient
{
public static void main( String[] args )
{
Cluster.Builder builder = Cluster.build();
builder.addContactPoint("localhost");
builder.port(8182);
builder.serializer(new GryoMessageSerializerV1d0());
Cluster cluster = builder.create();
GraphTraversalSource g =
EmptyGraph.instance().traversal().
withRemote(DriverRemoteConnection.using(cluster));
List <Map<String,Object>> vmaps =
g.V().has("airport","region","GB-ENG").limit(10).valueMap().toList();
System.out.println("\n\nThe following airports were found\n");
for (Map <String,Object> m : vmaps)
{
ArrayList code = (ArrayList) m.get("code");
ArrayList desc = (ArrayList) m.get("desc");
System.out.println(code.get(0) + " , " + desc.get(0));
}
cluster.close();
}
}
// The output should look something like this
/*
The following airports were found
LEQ , Land's End Airport
LGW , London Gatwick
MAN , Manchester Airport
LHR , London Heathrow
LCY , London City Airport
STN , London Stansted Airport
EMA , East Midlands Airport
LPL , Liverpool John Lennon Airport
LBA , Leeds Bradford Airport
NCL , Newcastle Airport
*/