Search in sources :

Example 1 with SwapManagerInitializationContext

use of org.apache.nifi.controller.repository.SwapManagerInitializationContext 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)

Example 2 with SwapManagerInitializationContext

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

the class TestFileSystemSwapManager method createSwapManager.

private FileSystemSwapManager createSwapManager() {
    final FileSystemSwapManager swapManager = new FileSystemSwapManager();
    final ResourceClaimManager resourceClaimManager = new NopResourceClaimManager();
    final FlowFileRepository flowfileRepo = Mockito.mock(FlowFileRepository.class);
    swapManager.initialize(new SwapManagerInitializationContext() {

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

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

        @Override
        public EventReporter getEventReporter() {
            return EventReporter.NO_OP;
        }
    });
    return swapManager;
}
Also used : FlowFileRepository(org.apache.nifi.controller.repository.FlowFileRepository) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) SwapManagerInitializationContext(org.apache.nifi.controller.repository.SwapManagerInitializationContext) EventReporter(org.apache.nifi.events.EventReporter)

Aggregations

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