Search in sources :

Example 1 with FlowFileSwapManager

use of org.apache.nifi.controller.repository.FlowFileSwapManager in project nifi by apache.

the class FlowController method createConnection.

/**
 * Creates a connection between two Connectable objects.
 *
 * @param id required ID of the connection
 * @param name the name of the connection, or <code>null</code> to leave the
 * connection unnamed
 * @param source required source
 * @param destination required destination
 * @param relationshipNames required collection of relationship names
 * @return
 *
 * @throws NullPointerException if the ID, source, destination, or set of
 * relationships is null.
 * @throws IllegalArgumentException if <code>relationships</code> is an
 * empty collection
 */
public Connection createConnection(final String id, final String name, final Connectable source, final Connectable destination, final Collection<String> relationshipNames) {
    final StandardConnection.Builder builder = new StandardConnection.Builder(processScheduler);
    final List<Relationship> relationships = new ArrayList<>();
    for (final String relationshipName : requireNonNull(relationshipNames)) {
        relationships.add(new Relationship.Builder().name(relationshipName).build());
    }
    // Create and initialize a FlowFileSwapManager for this connection
    final FlowFileSwapManager swapManager = createSwapManager(nifiProperties);
    final EventReporter eventReporter = createEventReporter(getBulletinRepository());
    try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
        final SwapManagerInitializationContext initializationContext = new SwapManagerInitializationContext() {

            @Override
            public ResourceClaimManager getResourceClaimManager() {
                return resourceClaimManager;
            }

            @Override
            public FlowFileRepository getFlowFileRepository() {
                return flowFileRepository;
            }

            @Override
            public EventReporter getEventReporter() {
                return eventReporter;
            }
        };
        swapManager.initialize(initializationContext);
    }
    return builder.id(requireNonNull(id).intern()).name(name == null ? null : name.intern()).relationships(relationships).source(requireNonNull(source)).destination(destination).swapManager(swapManager).queueSwapThreshold(nifiProperties.getQueueSwapThreshold()).eventReporter(eventReporter).resourceClaimManager(resourceClaimManager).flowFileRepository(flowFileRepository).provenanceRepository(provenanceRepository).build();
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) Relationship(org.apache.nifi.processor.Relationship) ArrayList(java.util.ArrayList) FlowFileSwapManager(org.apache.nifi.controller.repository.FlowFileSwapManager) StandardConnection(org.apache.nifi.connectable.StandardConnection) SwapManagerInitializationContext(org.apache.nifi.controller.repository.SwapManagerInitializationContext) EventReporter(org.apache.nifi.events.EventReporter)

Aggregations

ArrayList (java.util.ArrayList)1 StandardConnection (org.apache.nifi.connectable.StandardConnection)1 FlowFileSwapManager (org.apache.nifi.controller.repository.FlowFileSwapManager)1 SwapManagerInitializationContext (org.apache.nifi.controller.repository.SwapManagerInitializationContext)1 EventReporter (org.apache.nifi.events.EventReporter)1 NarCloseable (org.apache.nifi.nar.NarCloseable)1 Relationship (org.apache.nifi.processor.Relationship)1