From commits-return-30225-archive-asf-public=cust-asf.ponee.io@tinkerpop.apache.org Thu Jun 21 20:02:06 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E362318077D for ; Thu, 21 Jun 2018 20:01:58 +0200 (CEST) Received: (qmail 16109 invoked by uid 500); 21 Jun 2018 18:01:57 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 15989 invoked by uid 99); 21 Jun 2018 18:01:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2018 18:01:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7F19AE0F99; Thu, 21 Jun 2018 18:01:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkuppitz@apache.org To: commits@tinkerpop.apache.org Date: Thu, 21 Jun 2018 18:02:02 -0000 Message-Id: In-Reply-To: <3734875f5dec4c54ac45b8df026449e3@git.apache.org> References: <3734875f5dec4c54ac45b8df026449e3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/50] [abbrv] tinkerpop git commit: TINKERPOP-1831 Refactored EventStrategy TINKERPOP-1831 Refactored EventStrategy Removed deprecated method. Used VertexProperty.empty() and Property.empty() to represent the "old" value for new property events. Created a enum for configuring detachment on the EventStrategy builder. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7963fdfb Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7963fdfb Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7963fdfb Branch: refs/heads/shortest-path-wip Commit: 7963fdfb4407347a37ff35d40f5efdd1ba5f039f Parents: ae2f304 Author: Stephen Mallette Authored: Thu Jun 7 09:10:47 2018 -0400 Committer: Stephen Mallette Committed: Thu Jun 7 09:10:47 2018 -0400 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 3 + docs/src/upgrade/release-3.4.x.asciidoc | 22 +++ .../bulkloading/BulkLoaderVertexProgram.java | 6 - .../step/sideEffect/AddPropertyStep.java | 6 +- .../util/event/ConsoleMutationListener.java | 5 - .../step/util/event/MutationListener.java | 11 +- .../strategy/decoration/EventStrategy.java | 108 +++++----- .../strategy/decoration/EventStrategyTest.java | 1 - .../decoration/EventStrategyProcessTest.java | 197 ++++--------------- 9 files changed, 130 insertions(+), 229 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index e886107..7317aeb 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -37,6 +37,9 @@ This release also includes changes from <>. * Changed the order of `select()` scopes. The order is now: maps, side-effects, paths. * Removed previously deprecated Credentials DSL infrastructure. * Moved `TraversalEngine` to `gremlin-test` as it has long been only used in testing infrastructure. +* Events from `EventStrategy`raised from "new" mutations will now return a true "empty" property from `VertexProperty.empty()` or `Property.empty()` as is appropriate. +* `MutationListener#vertexPropertyChanged(Vertex, VertexProperty, Object, Object...)` no longer has a default implementation. +* Removed previously deprecated `MutationListener#vertexPropertyChanged(Vertex, Property, Object, Object...)`. * Removed previously deprecated `OpSelectorHandler` constructor. * Removed previously deprecated `close()` from `GremlinGroovyScriptEngine` which no longer implements `AutoCloseable`. * Removed previously deprecated `getGraphInputFormat()` and `getGraphOutputFormat()` from `HadoopConfiguration`. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/docs/src/upgrade/release-3.4.x.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc index 851d458..68e0c51 100644 --- a/docs/src/upgrade/release-3.4.x.asciidoc +++ b/docs/src/upgrade/release-3.4.x.asciidoc @@ -113,6 +113,27 @@ gremlin> g.V().values('name').max() ==>vadas ---- +==== EventStrategy API + +There were some minor modifications to how `EventStrategy` is constructed and what can be expected from events raised +from the addition of new properties. + +With respect to the change in terms of `EventStrategy` construction, the `detach()` builder method formerly took a +`Class` as an argument and that `Class` was meant to be one of the various "detachment factories" or `null`. That +approach was a bit confusing, so that signature has changed to `detach(EventStrategy.Detachment)` where the argument +is a more handy enum of detachment options. + +As for the changes related to events themselves, it is first worth noting that the previously deprecated +`vertexPropertyChanged(Vertex, Property, Object, Object...)` on `MutationListener` has been removed for what should +have originally been the correct signature of `vertexPropertyChanged(Vertex, VertexProperty, Object, Object...)`. In +prior versions when this method and its related `edgePropertyChanged()` and `vertexPropertyPropertyChanged()` were +triggered by way of the addition of a new property a "fake" property was included with a `null` value for the +"oldValue" argument to these methods (as it did not exist prior to this event). That was a bit awkward to reason about +when dealing with that event. To make this easier, the event now raises with a `VertexProperty.empty()` or +`Property.empty()` instance, which can be evaluated with `equals()` easily to determine if the property is new or not. + +link:https://issues.apache.org/jira/browse/TINKERPOP-1831[TINKERPOP-1831] + ==== Deprecation Removal The following deprecated classes, methods or fields have been removed in this version: @@ -122,6 +143,7 @@ The following deprecated classes, methods or fields have been removed in this ve ** `org.apache.tinkerpop.gremlin.process.traversal.engine.*` ** `org.apache.tinkerpop.gremlin.process.traversal.step.map.LambdaCollectingBarrierStep.Consumers` ** `org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer#makeHasContainers(String, P)` +** `org.apache.tinkerpop.gremlin.process.traversal.step.util.event.MutationListener#vertexPropertyChanged(Vertex, Property, Object, Object...)` ** `org.apache.tinkerpop.gremlin.structure.Element.Exceptions#elementAlreadyRemoved(Class, Object)` ** `org.apache.tinkerpop.gremlin.structure.Graph.Exceptions#elementNotFound(Class, Object)` ** `org.apache.tinkerpop.gremlin.structure.Graph.Exceptions#elementNotFound(Class, Object, Exception)` http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java index 508af3e..c637880 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java @@ -460,12 +460,6 @@ public class BulkLoaderVertexProgram implements VertexProgram { } @Override - public void vertexPropertyChanged(final Vertex element, final Property oldValue, final Object setValue, - final Object... vertexPropertyKeyValues) { - // do nothing - deprecated - } - - @Override public void vertexPropertyRemoved(final VertexProperty vertexProperty) { this.counter++; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java index 04a8414..3589c0c 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java @@ -97,17 +97,17 @@ public final class AddPropertyStep extends SideEffectStep if (element instanceof Vertex) evt = new Event.VertexPropertyChangedEvent(eventStrategy.detach((Vertex) element), newProperty ? - eventStrategy.empty(element, key) : + VertexProperty.empty() : eventStrategy.detach((VertexProperty) currentProperty), value, vertexPropertyKeyValues); else if (element instanceof Edge) evt = new Event.EdgePropertyChangedEvent(eventStrategy.detach((Edge) element), newProperty ? - eventStrategy.empty(element, key) : + Property.empty() : eventStrategy.detach(currentProperty), value); else if (element instanceof VertexProperty) evt = new Event.VertexPropertyPropertyChangedEvent(eventStrategy.detach((VertexProperty) element), newProperty ? - eventStrategy.empty(element, key) : + Property.empty() : eventStrategy.detach(currentProperty), value); else throw new IllegalStateException(String.format("The incoming object cannot be processed by change eventing in %s: %s", AddPropertyStep.class.getName(), element)); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/ConsoleMutationListener.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/ConsoleMutationListener.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/ConsoleMutationListener.java index 937f414..1bfdf24 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/ConsoleMutationListener.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/ConsoleMutationListener.java @@ -83,11 +83,6 @@ public class ConsoleMutationListener implements MutationListener { } @Override - public void vertexPropertyChanged(final Vertex element, final Property oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { - // do nothing - deprecated - } - - @Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { System.out.println("Vertex [" + element.toString() + "] property [" + oldValue + "] change to [" + setValue + "] in graph [" + graph.toString() + "]"); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/MutationListener.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/MutationListener.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/MutationListener.java index 00e49ed..8525d5d 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/MutationListener.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/event/MutationListener.java @@ -52,19 +52,10 @@ public interface MutationListener { /** * Raised after the property of a {@link Vertex} changed. * - * @deprecated As of release 3.2.7, replaced by {@link #vertexPropertyChanged(Vertex, VertexProperty, Object, Object...)}. - */ - public void vertexPropertyChanged(final Vertex element, final Property oldValue, final Object setValue, final Object... vertexPropertyKeyValues); - - /** - * Raised after the property of a {@link Vertex} changed. - * * @param element the {@link Vertex} that changed * @param setValue the new value of the property */ - public default void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { - vertexPropertyChanged(element, (Property) oldValue, setValue, vertexPropertyKeyValues); - } + public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues); /** * Raised after a {@link VertexProperty} was removed from the graph. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7963fdfb/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategy.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategy.java index b4824c8..094b43d 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/EventStrategy.java @@ -57,53 +57,23 @@ import java.util.List; */ public final class EventStrategy extends AbstractTraversalStrategy implements TraversalStrategy.DecorationStrategy { private final EventQueue eventQueue; - private final Class detachmentFactory; + private final Detachment detachment; private EventStrategy(final Builder builder) { this.eventQueue = builder.eventQueue; this.eventQueue.setListeners(builder.listeners); - this.detachmentFactory = builder.detachmentFactory; + this.detachment = builder.detachment; } - public Class getDetachmentFactory() { - return this.detachmentFactory; + public Detachment getDetachment() { + return this.detachment; } /** * Applies the appropriate detach operation to elements that will be raised in mutation events. */ public R detach(final R attached) { - if (null == detachmentFactory) - return attached; - else if (detachmentFactory.equals(DetachedFactory.class)) - return DetachedFactory.detach(attached, true); - else if (detachmentFactory.equals(ReferenceFactory.class)) - return ReferenceFactory.detach(attached); - else - throw new IllegalStateException("Unknown detachment option using " + detachmentFactory.getSimpleName()); - } - - /** - * For newly created properties that do not yet exist, an empty {@link Property} is required that just contains - * a key as a reference. - */ - public R empty(final Element element, final String key) { - // currently the "no detachment" model simply returns a Detached value to maintain consistency with the - // original API that already existed (where returning "Detached" was the only option). This could probably - // change in the future to use an "empty" property or perhaps the "change" event API could change all together - // and have a different return. - if (null == detachmentFactory || detachmentFactory.equals(DetachedFactory.class)) { - if (element instanceof Vertex) - return (R) new DetachedVertexProperty(null, key, null, null); - else - return (R) new DetachedProperty(key, null); - } else if (detachmentFactory.equals(ReferenceFactory.class)) { - if (element instanceof Vertex) - return (R) new ReferenceVertexProperty(new DetachedVertexProperty(null, key, null, null)); - else - return (R) new ReferenceProperty(new DetachedProperty(key, null)); - } else - throw new IllegalStateException("Unknown empty detachment option using " + detachmentFactory.getSimpleName()); + return (R) detachment.detach(attached); } @Override @@ -132,7 +102,7 @@ public final class EventStrategy extends AbstractTraversalStrategy listeners = new ArrayList<>(); private EventQueue eventQueue = new DefaultEventQueue(); - private Class detachmentFactory = DetachedFactory.class; + private Detachment detachment = Detachment.DETACHED_WITH_PROPERTIES; Builder() {} @@ -147,15 +117,11 @@ public final class EventStrategy extends AbstractTraversalStrategy factoryClass) { - detachmentFactory = factoryClass; + public Builder detach(final Detachment detachment) { + this.detachment = detachment; return this; } @@ -165,6 +131,60 @@ public final class EventStrategy extends AbstractTraversalStrategy