From 73e168e954ad8304bbd7f4a078031c106cf2e8e3 Mon Sep 17 00:00:00 2001 From: Pasqualino Ferrentino Date: Thu, 11 Feb 2016 01:10:24 -0600 Subject: [PATCH] NIFI-1003 A relationship can be auto-terminable. In this case the processor will auto-terminate the relationship and allow the user to run it even if he does not connect those relationships and does not terminate them. This closes #217 Signed-off-by: Aldrin Piri --- .../apache/nifi/processor/Relationship.java | 18 ++++++++++++++++++ .../nifi/controller/StandardProcessorNode.java | 3 +++ 2 files changed, 21 insertions(+) diff --git a/nifi-api/src/main/java/org/apache/nifi/processor/Relationship.java b/nifi-api/src/main/java/org/apache/nifi/processor/Relationship.java index 0fec1f6ef9..148940ce1d 100644 --- a/nifi-api/src/main/java/org/apache/nifi/processor/Relationship.java +++ b/nifi-api/src/main/java/org/apache/nifi/processor/Relationship.java @@ -41,9 +41,17 @@ public final class Relationship implements Comparable { */ private final int hashCode; + /** + * The flag which tells the controller to auto terminate this + * relationship, so that the processor can be run even if it does + * not have connections from this relationship + */ + private final boolean isAutoTerminate; + protected Relationship(final Builder builder) { this.name = builder.name == null ? null : builder.name.intern(); this.description = builder.description; + this.isAutoTerminate = builder.autoTerminate; this.hashCode = 301 + ( (name == null) ? 0 :this.name.hashCode() ); // compute only once, since it gets called a bunch and will never change } @@ -71,6 +79,7 @@ public final class Relationship implements Comparable { private String name = ""; private String description = ""; + private boolean autoTerminate = false; public Builder name(final String name) { if (null != name) { @@ -86,6 +95,11 @@ public final class Relationship implements Comparable { return this; } + public Builder autoTerminateDefault(boolean autoTerminate) { + this.autoTerminate = autoTerminate; + return this; + } + public Relationship build() { return new Relationship(this); } @@ -99,6 +113,10 @@ public final class Relationship implements Comparable { return this.description; } + public boolean isAutoTerminated() { + return this.isAutoTerminate; + } + @Override public boolean equals(final Object other) { if (other == null) { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java index 2db506cb84..f57343e62f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java @@ -304,6 +304,9 @@ public class StandardProcessorNode extends ProcessorNode implements Connectable @Override public boolean isAutoTerminated(final Relationship relationship) { + if (relationship.isAutoTerminated() && getConnections(relationship).isEmpty()) { + return true; + } final Set terminatable = undefinedRelationshipsToTerminate.get(); if (terminatable == null) { return false;