You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2015/08/12 16:01:43 UTC
[4/6] nifi git commit: [NIFI-784] Moving dynamic propertyMap to
onScheduled method and updating logger statements to use lazy evaluation with
String formatter
[NIFI-784] Moving dynamic propertyMap to onScheduled method and updating logger statements to use lazy evaluation with String formatter
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/4a43e813
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/4a43e813
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/4a43e813
Branch: refs/heads/develop
Commit: 4a43e81343b4eaf967a7e5a5417fd7bb35226503
Parents: a1af29e
Author: Brian Ghigiarelli <br...@gmail.com>
Authored: Thu Jul 23 22:52:35 2015 -0400
Committer: Brian Ghigiarelli <br...@gmail.com>
Committed: Thu Jul 23 22:52:35 2015 -0400
----------------------------------------------------------------------
.../processors/standard/RouteOnAttribute.java | 39 ++++++++++++++------
1 file changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/4a43e813/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/RouteOnAttribute.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/RouteOnAttribute.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/RouteOnAttribute.java
index 69107dd..52dc80b 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/RouteOnAttribute.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/RouteOnAttribute.java
@@ -27,12 +27,14 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.DynamicRelationship;
import org.apache.nifi.annotation.behavior.EventDriven;
import org.apache.nifi.annotation.behavior.SideEffectFree;
import org.apache.nifi.annotation.behavior.SupportsBatching;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
-import org.apache.nifi.annotation.behavior.DynamicRelationship;
import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
import org.apache.nifi.components.AllowableValue;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.PropertyValue;
@@ -103,6 +105,8 @@ public class RouteOnAttribute extends AbstractProcessor {
private volatile String configuredRouteStrategy = ROUTE_STRATEGY.getDefaultValue();
private volatile Set<String> dynamicPropertyNames = new HashSet<>();
+ private final Map<Relationship, PropertyValue> propertyMap = new HashMap<>();
+
@Override
protected void init(final ProcessorInitializationContext context) {
final Set<Relationship> set = new HashSet<>();
@@ -166,6 +170,27 @@ public class RouteOnAttribute extends AbstractProcessor {
this.relationships.set(newRelationships);
}
+ /**
+ * When this processor is
+ * @param context
+ */
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
+ if (!descriptor.isDynamic()) {
+ continue;
+ }
+ getLogger().debug("Adding new dynamic property: {}", new Object[]{descriptor});
+ propertyMap.put(new Relationship.Builder().name(descriptor.getName()).build(), context.getProperty(descriptor));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled(final ProcessContext context) {
+ getLogger().debug("Clearing propertyMap");
+ propertyMap.clear();
+ }
+
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
FlowFile flowFile = session.get();
@@ -174,14 +199,6 @@ public class RouteOnAttribute extends AbstractProcessor {
}
final ProcessorLog logger = getLogger();
- final Map<Relationship, PropertyValue> propertyMap = new HashMap<>();
- for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
- if (!descriptor.isDynamic()) {
- continue;
- }
-
- propertyMap.put(new Relationship.Builder().name(descriptor.getName()).build(), context.getProperty(descriptor));
- }
final Set<Relationship> matchingRelationships = new HashSet<>();
for (final Map.Entry<Relationship, PropertyValue> entry : propertyMap.entrySet()) {
@@ -216,7 +233,7 @@ public class RouteOnAttribute extends AbstractProcessor {
}
if (destinationRelationships.isEmpty()) {
- logger.info(this + " routing " + flowFile + " to unmatched");
+ logger.info("{} routing {} to unmatched", new Object[]{ this, flowFile });
flowFile = session.putAttribute(flowFile, ROUTE_ATTRIBUTE_KEY, REL_NO_MATCH.getName());
session.getProvenanceReporter().route(flowFile, REL_NO_MATCH);
session.transfer(flowFile, REL_NO_MATCH);
@@ -236,7 +253,7 @@ public class RouteOnAttribute extends AbstractProcessor {
// now transfer any clones generated
for (final Map.Entry<Relationship, FlowFile> entry : transferMap.entrySet()) {
- logger.info(this + " cloned " + flowFile + " into " + entry.getValue() + " and routing clone to relationship " + entry.getKey());
+ logger.info("{} cloned {} into {} and routing clone to relationship {}", new Object[]{ this, flowFile, entry.getValue(), entry.getKey() });
FlowFile updatedFlowFile = session.putAttribute(entry.getValue(), ROUTE_ATTRIBUTE_KEY, entry.getKey().getName());
session.getProvenanceReporter().route(updatedFlowFile, entry.getKey());
session.transfer(updatedFlowFile, entry.getKey());