Java Code Examples for org.apache.nifi.processor.ProcessContext#getAvailableRelationships()

The following examples show how to use org.apache.nifi.processor.ProcessContext#getAvailableRelationships() . 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: StandardFunnel.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void onTrigger(final ProcessContext context, final ProcessSession session) {
    readLock.lock();
    try {
        Set<Relationship> available = context.getAvailableRelationships();
        while (!available.isEmpty()) {
            final List<FlowFile> flowFiles = session.get(100);
            if (flowFiles.isEmpty()) {
                break;
            }

            session.transfer(flowFiles, Relationship.ANONYMOUS);
            session.commit();
            available = context.getAvailableRelationships();
        }
    } finally {
        readLock.unlock();
    }
}
 
Example 2
Source File: LocalPort.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected void transferUnboundedConcurrency(final ProcessContext context, final ProcessSession session) {
    Set<Relationship> available = context.getAvailableRelationships();
    int iterations = 0;
    while (!available.isEmpty()) {
        final List<FlowFile> flowFiles = session.get(1000);
        if (flowFiles.isEmpty()) {
            break;
        }

        session.transfer(flowFiles, Relationship.ANONYMOUS);
        session.commit();

        // If there are fewer than 1,000 FlowFiles available to transfer, or if we
        // have hit the configured FlowFile cap, we want to stop. This prevents us from
        // holding the Timer-Driven Thread for an excessive amount of time.
        if (flowFiles.size() < 1000 || ++iterations >= maxIterations) {
            break;
        }

        available = context.getAvailableRelationships();
    }
}
 
Example 3
Source File: DistributeLoad.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    final FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    final DistributionStrategy strategy = strategyRef.get();
    final Set<Relationship> available = context.getAvailableRelationships();
    final int numRelationships = context.getProperty(NUM_RELATIONSHIPS).asInteger();
    final boolean allDestinationsAvailable = (available.size() == numRelationships);
    if (!allDestinationsAvailable && strategy.requiresAllDestinationsAvailable()) {
        // can't transfer the FlowFiles. Roll back and yield
        session.rollback();
        context.yield();
        return;
    }

    final Relationship relationship = strategy.mapToRelationship(context, flowFile);
    if (relationship == null) {
        // can't transfer the FlowFiles. Roll back and yield
        session.rollback();
        context.yield();
        return;
    }

    session.transfer(flowFile, relationship);
    session.getProvenanceReporter().route(flowFile, relationship);
}
 
Example 4
Source File: TestExtractMediaMetadata.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelationships() {
    final TestRunner runner = TestRunners.newTestRunner(new ExtractMediaMetadata());
    ProcessContext context = runner.getProcessContext();
    Set<Relationship> relationships = context.getAvailableRelationships();
    assertEquals(2, relationships.size());
    assertTrue(relationships.contains(ExtractMediaMetadata.SUCCESS));
    assertTrue(relationships.contains(ExtractMediaMetadata.FAILURE));
}
 
Example 5
Source File: DistributeLoad.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    final FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    final DistributionStrategy strategy = strategyRef.get();
    final Set<Relationship> available = context.getAvailableRelationships();
    final int numRelationships = context.getProperty(NUM_RELATIONSHIPS).asInteger();
    final boolean allDestinationsAvailable = (available.size() == numRelationships);
    if (!allDestinationsAvailable && strategy.requiresAllDestinationsAvailable()) {
        // can't transfer the FlowFiles. Roll back and yield
        session.rollback();
        context.yield();
        return;
    }

    final Relationship relationship = strategy.mapToRelationship(context, flowFile);
    if (relationship == null) {
        // can't transfer the FlowFiles. Roll back and yield
        session.rollback();
        context.yield();
        return;
    }

    // add an attribute capturing which relationship a flowfile was routed through
    session.putAttribute(flowFile, RELATIONSHIP_ATTRIBUTE, relationship.getName());

    session.transfer(flowFile, relationship);
    session.getProvenanceReporter().route(flowFile, relationship);
}
 
Example 6
Source File: TestExtractMediaMetadata.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelationships() {
    final TestRunner runner = TestRunners.newTestRunner(new ExtractMediaMetadata());
    ProcessContext context = runner.getProcessContext();
    Set<Relationship> relationships = context.getAvailableRelationships();
    assertEquals(2, relationships.size());
    assertTrue(relationships.contains(ExtractMediaMetadata.SUCCESS));
    assertTrue(relationships.contains(ExtractMediaMetadata.FAILURE));
}
 
Example 7
Source File: StandardFunnel.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void onTrigger(final ProcessContext context, final ProcessSession session) {
    readLock.lock();
    try {
        Set<Relationship> available = context.getAvailableRelationships();
        int iterations = 0;
        while (!available.isEmpty()) {
            final List<FlowFile> flowFiles = session.get(1000);
            if (flowFiles.isEmpty()) {
                break;
            }

            session.transfer(flowFiles, Relationship.ANONYMOUS);
            session.commit();

            // If there are fewer than 1,000 FlowFiles available to transfer, or if we
            // have hit the configured FlowFile cap, we want to stop. This prevents us from
            // holding the Timer-Driven Thread for an excessive amount of time.
            if (flowFiles.size() < 1000 || ++iterations >= maxIterations) {
                break;
            }

            available = context.getAvailableRelationships();
        }
    } finally {
        readLock.unlock();
    }
}