@EventDriven @SideEffectFree @SupportsBatching @InputRequirement(value=INPUT_REQUIRED) @TriggerWhenAnyDestinationAvailable @Tags(value={"distribute","load balance","route","round robin","weighted"}) @CapabilityDescription(value="Distributes FlowFiles to downstream processors based on a Distribution Strategy. If using the Round Robin strategy, the default is to assign each destination a weighting of 1 (evenly distributed). However, optional propertiescan be added to the change this; adding a property with the name \'5\' and value \'10\' means that the relationship with name \'5\' will be receive 10 FlowFiles in each iteration instead of 1.") @DynamicProperty(name="The relationship name(positive number)", value="The relationship Weight(positive number)", description="adding a property with the name \'5\' and value \'10\' means that the relationship with name \'5\' will be receive 10 FlowFiles in each iteration instead of 1.") @DynamicRelationship(name="A number 1..<Number Of Relationships>", description="FlowFiles are sent to this relationship per the <Distribution Strategy>") @WritesAttributes(value=@WritesAttribute(attribute="distribute.load.relationship",description="The name of the specific relationship the flow file has been routed through")) public class DistributeLoad extends AbstractProcessor
Modifier and Type | Class and Description |
---|---|
private static interface |
DistributeLoad.DistributionStrategy
Implementations must be thread-safe.
|
private static class |
DistributeLoad.InvalidPropertyNameValidator |
private class |
DistributeLoad.LoadDistributionStrategy |
private class |
DistributeLoad.NextAvailableStrategy |
private class |
DistributeLoad.RoundRobinStrategy |
Modifier and Type | Field and Description |
---|---|
static PropertyDescriptor |
DISTRIBUTION_STRATEGY |
private AtomicBoolean |
doCustomValidate |
private AtomicBoolean |
doSetProps |
static PropertyDescriptor |
HOSTNAMES |
static PropertyDescriptor |
LOAD_DISTRIBUTION_SERVICE_TEMPLATE |
private LoadDistributionListener |
myListener |
static PropertyDescriptor |
NUM_RELATIONSHIPS |
private List<PropertyDescriptor> |
properties |
static String |
RELATIONSHIP_ATTRIBUTE |
private AtomicReference<Set<Relationship>> |
relationshipsRef |
static String |
STRATEGY_LOAD_DISTRIBUTION_SERVICE |
static String |
STRATEGY_NEXT_AVAILABLE |
static String |
STRATEGY_ROUND_ROBIN |
private AtomicReference<DistributeLoad.DistributionStrategy> |
strategyRef |
private AtomicReference<List<Relationship>> |
weightedRelationshipListRef |
Constructor and Description |
---|
DistributeLoad() |
Modifier and Type | Method and Description |
---|---|
private static Relationship |
createRelationship(int num) |
void |
createWeightedList(ProcessContext context) |
protected Collection<ValidationResult> |
customValidate(ValidationContext validationContext) |
Set<Relationship> |
getRelationships() |
protected PropertyDescriptor |
getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) |
protected List<PropertyDescriptor> |
getSupportedPropertyDescriptors() |
protected void |
init(ProcessorInitializationContext context) |
void |
onPropertyModified(PropertyDescriptor descriptor,
String oldValue,
String newValue) |
void |
onTrigger(ProcessContext context,
ProcessSession session) |
private void |
updateWeightedRelationships(Map<Integer,Integer> weightings) |
onTrigger
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrue
equals, getPropertyDescriptor, getPropertyDescriptors, hashCode, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getPropertyDescriptor, getPropertyDescriptors, validate
public static final String STRATEGY_ROUND_ROBIN
public static final String STRATEGY_NEXT_AVAILABLE
public static final String STRATEGY_LOAD_DISTRIBUTION_SERVICE
public static final PropertyDescriptor NUM_RELATIONSHIPS
public static final PropertyDescriptor DISTRIBUTION_STRATEGY
public static final PropertyDescriptor HOSTNAMES
public static final PropertyDescriptor LOAD_DISTRIBUTION_SERVICE_TEMPLATE
public static final String RELATIONSHIP_ATTRIBUTE
private List<PropertyDescriptor> properties
private final AtomicReference<Set<Relationship>> relationshipsRef
private final AtomicReference<DistributeLoad.DistributionStrategy> strategyRef
private final AtomicReference<List<Relationship>> weightedRelationshipListRef
private final AtomicBoolean doCustomValidate
private volatile LoadDistributionListener myListener
private final AtomicBoolean doSetProps
protected void init(ProcessorInitializationContext context)
init
in class AbstractSessionFactoryProcessor
private static Relationship createRelationship(int num)
public Set<Relationship> getRelationships()
getRelationships
in interface Processor
getRelationships
in class AbstractSessionFactoryProcessor
public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue)
onPropertyModified
in interface ConfigurableComponent
onPropertyModified
in class AbstractConfigurableComponent
protected List<PropertyDescriptor> getSupportedPropertyDescriptors()
getSupportedPropertyDescriptors
in class AbstractConfigurableComponent
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName)
getSupportedDynamicPropertyDescriptor
in class AbstractConfigurableComponent
protected Collection<ValidationResult> customValidate(ValidationContext validationContext)
customValidate
in class AbstractConfigurableComponent
@OnScheduled public void createWeightedList(ProcessContext context)
private void updateWeightedRelationships(Map<Integer,Integer> weightings)
public void onTrigger(ProcessContext context, ProcessSession session)
onTrigger
in class AbstractProcessor
Copyright © 2020 Apache NiFi Project. All rights reserved.