org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlgAddVertexStartStep.java From sqlg with MIT License | 6 votes |
@Override protected Traverser.Admin<Vertex> processNextStart() { if (this.first) { this.first = false; final SqlgTraverserGenerator generator = SqlgTraverserGenerator.instance(); final Vertex vertex = this.getTraversal().getGraph().get().addVertex( this.parameters.getKeyValues( generator.generate(false, (Step)this, 1L, false, false) )); if (this.callbackRegistry != null && !this.callbackRegistry.getCallbacks().isEmpty()) { final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex)); this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae)); } return generator.generate(vertex, (Step)this, 1L, false, false); } else throw FastNoSuchElementException.instance(); }
Example #2
Source File: AddEdgeStep.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override protected Edge map(final Traverser.Admin<S> traverser) { Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0); Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0); if (toVertex instanceof Attachable) toVertex = ((Attachable<Vertex>) toVertex) .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance()))); if (fromVertex instanceof Attachable) fromVertex = ((Attachable<Vertex>) fromVertex) .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance()))); final String edgeLabel = this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0); final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label)); if (callbackRegistry != null) { final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.EdgeAddedEvent vae = new Event.EdgeAddedEvent(eventStrategy.detach(edge)); callbackRegistry.getCallbacks().forEach(c -> c.accept(vae)); } return edge; }
Example #3
Source File: TestTraversalAddV.java From sqlg with MIT License | 6 votes |
@Test public void shouldDetachVertexWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexAdded(final Vertex element) { Assert.assertThat(element, IsInstanceOf.instanceOf(DetachedVertex.class)); Assert.assertEquals("thing", element.label()); Assert.assertEquals("there", element.value("here")); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.addV("thing").property("here", "there").iterate(); sqlgGraph.tx().commit(); Assert.assertThat(triggered.get(), Is.is(true)); }
Example #4
Source File: TinkerGraphPlayTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @Ignore public void testPlayDK() throws Exception { final Graph graph = TinkerGraph.open(); final EventStrategy strategy = EventStrategy.build().addListener(new ConsoleMutationListener(graph)).create(); final GraphTraversalSource g = graph.traversal().withStrategies(strategy); g.addV().property(T.id, 1).iterate(); g.V(1).property("name", "name1").iterate(); g.V(1).property("name", "name2").iterate(); g.V(1).property("name", "name2").iterate(); g.addV().property(T.id, 2).iterate(); g.V(2).property(VertexProperty.Cardinality.list, "name", "name1").iterate(); g.V(2).property(VertexProperty.Cardinality.list, "name", "name2").iterate(); g.V(2).property(VertexProperty.Cardinality.list, "name", "name2").iterate(); g.addV().property(T.id, 3).iterate(); g.V(3).property(VertexProperty.Cardinality.set, "name", "name1", "ping", "pong").iterate(); g.V(3).property(VertexProperty.Cardinality.set, "name", "name2", "ping", "pong").iterate(); g.V(3).property(VertexProperty.Cardinality.set, "name", "name2", "pong", "ping").iterate(); }
Example #5
Source File: TestDropStepBarrier.java From sqlg with MIT License | 6 votes |
@Test public void dropProperty() { final AtomicBoolean triggered = new AtomicBoolean(false); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyRemoved(final VertexProperty element) { triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); final EventStrategy eventStrategy = builder.create(); Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); this.sqlgGraph.tx().commit(); this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties().drop().iterate(); this.sqlgGraph.tx().commit(); Assert.assertTrue(triggered.get()); Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext()); }
Example #6
Source File: AddVertexStartStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected Traverser.Admin<Vertex> processNextStart() { if (this.first) { this.first = false; final TraverserGenerator generator = this.getTraversal().getTraverserGenerator(); final Vertex vertex = this.getTraversal().getGraph().get().addVertex(this.parameters.getKeyValues(generator.generate(false, (Step) this, 1L))); if (this.callbackRegistry != null) { final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex)); this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae)); } return generator.generate(vertex, this, 1L); } else throw FastNoSuchElementException.instance(); }
Example #7
Source File: TestTinkerPopEvent.java From sqlg with MIT License | 5 votes |
@Test public void shouldDetachVertexPropertyWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = this.sqlgGraph.addVertex(); final VertexProperty vp = v.property("to-remove","blah"); final String label = vp.label(); final Object value = vp.value(); final VertexProperty vpToKeep = v.property("to-keep","dah"); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyRemoved(final VertexProperty element) { Assert.assertEquals(label, element.label()); Assert.assertEquals(value, element.value()); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); if (this.sqlgGraph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).properties("to-remove").drop().iterate(); this.sqlgGraph.tx().commit(); Assert.assertEquals(1, IteratorUtils.count(v.properties())); Assert.assertEquals(vpToKeep.value(), v.value("to-keep")); Assert.assertThat(triggered.get(), CoreMatchers.is(true)); }
Example #8
Source File: TestDropStepTruncate.java From sqlg with MIT License | 5 votes |
@Before public void before() throws Exception { super.before(); configuration.setProperty("implement.foreign.keys", this.fkOn); this.removedVertices.clear(); if (this.mutatingCallback) { final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex vertex) { removedVertices.add(vertex); } @Override public void edgeRemoved(final Edge edge) { removedEdges.add(edge); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); EventStrategy eventStrategy = builder.create(); this.dropTraversal = this.sqlgGraph.traversal(); if (this.mutatingCallback) { this.dropTraversal = this.dropTraversal.withStrategies(eventStrategy); } } else { this.dropTraversal = this.sqlgGraph.traversal(); } }
Example #9
Source File: TestDropStepPartition.java From sqlg with MIT License | 5 votes |
@Before public void before() throws Exception { super.before(); Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsPartitioning()); configuration.setProperty("implement.foreign.keys", this.fkOn); this.removedVertices.clear(); if (this.mutatingCallback) { // Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows()); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex vertex) { removedVertices.add(vertex); } @Override public void edgeRemoved(final Edge edge) { removedEdges.add(edge); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); EventStrategy eventStrategy = builder.create(); this.dropTraversal = this.sqlgGraph.traversal(); if (this.mutatingCallback) { this.dropTraversal = this.dropTraversal.withStrategies(eventStrategy); } } else { this.dropTraversal = this.sqlgGraph.traversal(); } }
Example #10
Source File: TestDropStepBarrier.java From sqlg with MIT License | 5 votes |
@Test public void dropPropertyuserSuppliedIds() { final AtomicBoolean triggered = new AtomicBoolean(false); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyRemoved(final VertexProperty element) { triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); final EventStrategy eventStrategy = builder.create(); VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist( "A", new LinkedHashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("uid3", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); VertexLabel bVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist( "B", new LinkedHashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("uid3", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); this.sqlgGraph.tx().commit(); Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); this.sqlgGraph.tx().commit(); this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties("name").drop().iterate(); this.sqlgGraph.tx().commit(); Assert.assertTrue(triggered.get()); Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext()); }
Example #11
Source File: TestDropStep.java From sqlg with MIT License | 5 votes |
@Test public void shouldReferenceVertexWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = this.sqlgGraph.addVertex(); final String label = v.label(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex element) { Assert.assertThat(element, IsInstanceOf.instanceOf(ReferenceVertex.class)); Assert.assertEquals(id, element.id()); Assert.assertEquals(label, element.label()); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener) .detach(EventStrategy.Detachment.REFERENCE); if (this.sqlgGraph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = this.sqlgGraph.traversal().withStrategies(eventStrategy); gts.V(v).drop().iterate(); this.sqlgGraph.tx().commit(); AbstractGremlinTest.assertVertexEdgeCounts(this.sqlgGraph, 0, 0); Assert.assertThat(triggered.get(), CoreMatchers.is(true)); }
Example #12
Source File: TestDropStep.java From sqlg with MIT License | 5 votes |
@Before public void before() throws Exception { super.before(); configuration.setProperty("implement.foreign.keys", this.fkOn); this.removedVertices.clear(); if (this.mutatingCallback) { // Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows()); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexRemoved(final Vertex vertex) { removedVertices.add(vertex); } @Override public void edgeRemoved(final Edge edge) { removedEdges.add(edge); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); EventStrategy eventStrategy = builder.create(); this.dropTraversal = this.sqlgGraph.traversal(); if (this.mutatingCallback) { this.dropTraversal = this.dropTraversal.withStrategies(eventStrategy); } } else { this.dropTraversal = this.sqlgGraph.traversal(); } }
Example #13
Source File: AddVertexStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected Vertex map(final Traverser.Admin<S> traverser) { final Vertex vertex = this.getTraversal().getGraph().get().addVertex(this.parameters.getKeyValues(traverser)); if (this.callbackRegistry != null) { final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex)); this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae)); } return vertex; }
Example #14
Source File: AddEdgeStartStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected Traverser.Admin<Edge> processNextStart() { if (this.first) { this.first = false; final TraverserGenerator generator = this.getTraversal().getTraverserGenerator(); final Traverser.Admin traverser = generator.generate(1, (Step) this, 1); // a dead traverser to trigger the traversal Vertex toVertex = (Vertex) this.parameters.get(traverser, TO, Collections::emptyList).get(0); Vertex fromVertex = (Vertex) this.parameters.get(traverser, FROM, Collections::emptyList).get(0); if (toVertex instanceof Attachable) toVertex = ((Attachable<Vertex>) toVertex) .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance()))); if (fromVertex instanceof Attachable) fromVertex = ((Attachable<Vertex>) fromVertex) .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance()))); final String edgeLabel = (String) this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0); final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label)); if (callbackRegistry != null) { final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.EdgeAddedEvent vae = new Event.EdgeAddedEvent(eventStrategy.detach(edge)); callbackRegistry.getCallbacks().forEach(c -> c.accept(vae)); } return generator.generate(edge, this, 1L); } else throw FastNoSuchElementException.instance(); }
Example #15
Source File: TestTinkerPopEvent.java From sqlg with MIT License | 4 votes |
private GraphTraversalSource create(final EventStrategy strategy) { return this.sqlgGraph.traversal().withStrategies(strategy); }
Example #16
Source File: TestTraversalAddV.java From sqlg with MIT License | 4 votes |
private GraphTraversalSource create(final EventStrategy strategy) { return this.sqlgGraph.traversal().withStrategies(strategy); }
Example #17
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 4 votes |
private JanusGraph initializeJanusGraph(boolean createMode, boolean enableListeners) { LOG.fine("Initializing graph."); Path lucene = graphDir.resolve("graphsearch"); Path berkeley = graphDir.resolve("titangraph"); // TODO: Externalize this. conf = new BaseConfiguration(); // Sets a unique id in order to fix WINDUP-697. This causes Titan to not attempt to generate and ID, // as the Titan id generation code fails on machines with broken network configurations. conf.setProperty("graph.unique-instance-id", "windup_" + System.nanoTime() + "_" + RandomStringUtils.randomAlphabetic(6)); conf.setProperty("storage.directory", berkeley.toAbsolutePath().toString()); conf.setProperty("storage.backend", "berkeleyje"); // Sets the berkeley cache to a relatively small value to reduce the memory footprint. // This is actually more important than performance on some of the smaller machines out there, and // the performance decrease seems to be minimal. conf.setProperty("storage.berkeleydb.cache-percentage", 1); // Set READ UNCOMMITTED to improve performance conf.setProperty("storage.berkeleydb.lock-mode", LockMode.READ_UNCOMMITTED); conf.setProperty("storage.berkeleydb.isolation-level", BerkeleyJEStoreManager.IsolationLevel.READ_UNCOMMITTED); // Increase storage write buffer since we basically do a large bulk load during the first phases. // See http://s3.thinkaurelius.com/docs/titan/current/bulk-loading.html conf.setProperty("storage.buffer-size", "4096"); // Turn off transactions to improve performance conf.setProperty("storage.transactions", false); conf.setProperty("ids.block-size", 25000); // conf.setProperty("ids.flush", true); // conf.setProperty("", false); // // turn on a db-cache that persists across txn boundaries, but make it relatively small conf.setProperty("cache.db-cache", true); conf.setProperty("cache.db-cache-clean-wait", 0); conf.setProperty("cache.db-cache-size", .09); conf.setProperty("cache.db-cache-time", 0); conf.setProperty("index.search.backend", "lucene"); conf.setProperty("index.search.directory", lucene.toAbsolutePath().toString()); writeToPropertiesFile(conf, graphDir.resolve("TitanConfiguration.properties").toFile()); JanusGraph janusGraph = JanusGraphFactory.open(conf); /* * We only need to setup the eventing system when initializing a graph, not when loading it later for * reporting. */ if (enableListeners) { TraversalStrategies graphStrategies = TraversalStrategies.GlobalCache .getStrategies(StandardJanusGraph.class) .clone(); // Remove any old listeners if (graphStrategies.getStrategy(EventStrategy.class) != null) graphStrategies.removeStrategies(EventStrategy.class); graphStrategies.addStrategies(EventStrategy.build().addListener(mutationListener).create()); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, graphStrategies); mutationListener.setGraph(this); } return janusGraph; }