Java Code Examples for org.apache.nifi.nar.NarCloseable#withNarLoader()

The following examples show how to use org.apache.nifi.nar.NarCloseable#withNarLoader() . 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: LoginIdentityProviderFactoryBean.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private LoginIdentityProvider withNarLoader(final LoginIdentityProvider baseProvider) {
    return new LoginIdentityProvider() {

        @Override
        public AuthenticationResponse authenticate(LoginCredentials credentials) {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                return baseProvider.authenticate(credentials);
            }
        }

        @Override
        public void initialize(LoginIdentityProviderInitializationContext initializationContext) throws ProviderCreationException {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                baseProvider.initialize(initializationContext);
            }
        }

        @Override
        public void onConfigured(LoginIdentityProviderConfigurationContext configurationContext) throws ProviderCreationException {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                baseProvider.onConfigured(configurationContext);
            }
        }

        @Override
        public void preDestruction() throws ProviderDestructionException {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                baseProvider.preDestruction();
            }
        }
    };
}
 
Example 2
Source File: LoginIdentityProviderFactoryBean.java    From nifi with Apache License 2.0 5 votes vote down vote up
private LoginIdentityProvider withNarLoader(final LoginIdentityProvider baseProvider) {
    return new LoginIdentityProvider() {

        @Override
        public AuthenticationResponse authenticate(LoginCredentials credentials) {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                return baseProvider.authenticate(credentials);
            }
        }

        @Override
        public void initialize(LoginIdentityProviderInitializationContext initializationContext) throws ProviderCreationException {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                baseProvider.initialize(initializationContext);
            }
        }

        @Override
        public void onConfigured(LoginIdentityProviderConfigurationContext configurationContext) throws ProviderCreationException {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                baseProvider.onConfigured(configurationContext);
            }
        }

        @Override
        public void preDestruction() throws ProviderDestructionException {
            try (final NarCloseable narCloseable = NarCloseable.withNarLoader()) {
                baseProvider.preDestruction();
            }
        }
    };
}
 
Example 3
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public FlowFileSwapManager createSwapManager() {
    final String implementationClassName = nifiProperties.getProperty(NiFiProperties.FLOWFILE_SWAP_MANAGER_IMPLEMENTATION, DEFAULT_SWAP_MANAGER_IMPLEMENTATION);
    if (implementationClassName == null) {
        return null;
    }

    try {
        final FlowFileSwapManager swapManager = NarThreadContextClassLoader.createInstance(extensionManager, implementationClassName, FlowFileSwapManager.class, nifiProperties);

        final EventReporter eventReporter = createEventReporter();
        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 swapManager;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: FlowController.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
}
 
Example 5
Source File: FlowController.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * 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 the connection
 * @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();
    final EventReporter eventReporter = createEventReporter();

    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);
    }

    final FlowFileQueueFactory flowFileQueueFactory = new FlowFileQueueFactory() {
        @Override
        public FlowFileQueue createFlowFileQueue(final LoadBalanceStrategy loadBalanceStrategy, final String partitioningAttribute, final ConnectionEventListener eventListener) {
            final FlowFileQueue flowFileQueue;

            if (clusterCoordinator == null) {
                flowFileQueue = new StandardFlowFileQueue(id, eventListener, flowFileRepository, provenanceRepository, resourceClaimManager, processScheduler, swapManager,
                        eventReporter, nifiProperties.getQueueSwapThreshold(), nifiProperties.getDefaultBackPressureObjectThreshold(), nifiProperties.getDefaultBackPressureDataSizeThreshold());
            } else {
                flowFileQueue = new SocketLoadBalancedFlowFileQueue(id, eventListener, processScheduler, flowFileRepository, provenanceRepository, contentRepository, resourceClaimManager,
                        clusterCoordinator, loadBalanceClientRegistry, swapManager, nifiProperties.getQueueSwapThreshold(), eventReporter);

                flowFileQueue.setBackPressureObjectThreshold(nifiProperties.getDefaultBackPressureObjectThreshold());
                flowFileQueue.setBackPressureDataSizeThreshold(nifiProperties.getDefaultBackPressureDataSizeThreshold());
            }

            return flowFileQueue;
        }
    };

    final Connection connection = builder.id(requireNonNull(id).intern())
            .name(name == null ? null : name.intern())
            .relationships(relationships)
            .source(requireNonNull(source))
            .destination(destination)
            .flowFileQueueFactory(flowFileQueueFactory)
            .build();

    return connection;
}