forked from krlawrence/graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteSubgraphStrategy.java
More file actions
54 lines (45 loc) · 2.03 KB
/
Copy pathRemoteSubgraphStrategy.java
File metadata and controls
54 lines (45 loc) · 2.03 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
// RemoteSubgraphStrategy.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 that explore using a SubGraphStrategy
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 org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
public class RemoteSubgraphStrategy
{
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));
// Create a new traversal source object
GraphTraversalSource g2;
// Create a strategy that filters out anything without
// a region code of 'US-TX'
g2 = g.withStrategies(
SubgraphStrategy.build().
vertices(has("region","US-TX")).create());
// How many airports are there in Texas?
System.out.println(g2.V().count().next());
cluster.close();
}
}