org.apache.nifi.processor.ProcessContext - java examples

Here are the examples of the java api org.apache.nifi.processor.ProcessContext taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : AbstractEmailProcessor.java
Copyright Apache License 2.0
Author : apache
@OnStopped
public void stop(ProcessContext processContext) {
    this.flushRemainingMessages(processContext);
    try {
        this.messageReceiver.destroy();
        this.messageReceiver = null;
    } catch (Exception e) {
        this.logger.warn("Failure while closing processor", e);
    }
}

19 View Complete Implementation : PutUDP.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a concrete instance of a ChannelSender object to use for sending UDP datagrams.
 *
 * @param context
 *            - the current process context.
 *
 * @return ChannelSender object.
 */
@Override
protected ChannelSender createSender(final ProcessContext context) throws IOException {
    final String protocol = UDP_VALUE.getValue();
    final String hostname = context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue();
    final int port = context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
    final int bufferSize = context.getProperty(MAX_SOCKET_SEND_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    return createSender(protocol, hostname, port, 0, bufferSize, null);
}

19 View Complete Implementation : ConsumeMQTT.java
Copyright Apache License 2.0
Author : apache
@OnStopped
public void onStopped(final ProcessContext context) throws IOException {
    if (mqttQueue != null && !mqttQueue.isEmpty() && processSessionFactory != null) {
        logger.info("Finishing processing leftover messages");
        ProcessSession session = processSessionFactory.createSession();
        transferQueue(session);
    } else {
        if (mqttQueue != null && !mqttQueue.isEmpty()) {
            throw new ProcessException("Stopping the processor but there is no ProcessSessionFactory stored and there are messages in the MQTT internal queue. Removing the processor now will " + "clear the queue but will result in DATA LOSS. This is normally due to starting the processor, receiving messages and stopping before the onTrigger happens. The messages " + "in the MQTT internal queue cannot finish processing until until the processor is triggered to run.");
        }
    }
}

19 View Complete Implementation : AbstractListProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a Map of attributes that should be applied to the FlowFile to represent this enreplacedy. This processor will emit a FlowFile for each "new" enreplacedy
 * (see the doreplacedentation for this clreplaced for a discussion of how this clreplaced determines whether or not an enreplacedy is "new"). The FlowFile will contain no
 * content. The attributes that will be included are exactly the attributes that are returned by this method.
 *
 * @param enreplacedy  the enreplacedy represented by the FlowFile
 * @param context the ProcessContext for obtaining configuration information
 * @return a Map of attributes for this enreplacedy
 */
protected abstract Map<String, String> createAttributes(T enreplacedy, ProcessContext context);

19 View Complete Implementation : ConsumeWindowsEventLog.java
Copyright Apache License 2.0
Author : apache
@Override
public void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException {
    this.sessionFactory = sessionFactory;
    if (!isSubscribed()) {
        String errorMessage = subscribe(context);
        if (errorMessage != null) {
            context.yield();
            getLogger().error(errorMessage);
            return;
        }
    }
    final int flowFileCount = processQueue(sessionFactory.createSession());
    final long now = System.currentTimeMillis();
    if (flowFileCount > 0) {
        lastActivityTimestamp = now;
    } else if (inactiveDurationToReconnect > 0) {
        if ((now - lastActivityTimestamp) > inactiveDurationToReconnect) {
            getLogger().info("Exceeds configured 'inactive duration to reconnect' {} ms. Unsubscribe to reconnect..", new Object[] { inactiveDurationToReconnect });
            unsubscribe();
        }
    }
}

19 View Complete Implementation : GetTCP.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(final ProcessContext context) throws ProcessException {
    this.receiveBufferSize = context.getProperty(RECEIVE_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    this.originalServerAddressList = context.getProperty(ENDPOINT_LIST).getValue();
    this.endOfMessageByte = ((byte) context.getProperty(END_OF_MESSAGE_BYTE).asInteger().intValue());
    this.connectionAttemptCount = context.getProperty(CONNECTION_ATTEMPT_COUNT).asInteger();
    this.reconnectInterval = context.getProperty(RECONNECT_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    this.clientScheduler = new ScheduledThreadPoolExecutor(originalServerAddressList.split(",").length + 1);
    this.clientScheduler.setKeepAliveTime(10, TimeUnit.SECONDS);
    this.clientScheduler.allowCoreThreadTimeOut(true);
    for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        if (descriptor.isDynamic()) {
            this.dynamicAttributes.put(descriptor.getName(), entry.getValue());
        }
    }
}

19 View Complete Implementation : GetTCP.java
Copyright Apache License 2.0
Author : apache
private void run(ProcessContext context) {
    String[] serverAddresses = this.originalServerAddressList.split(",");
    for (String hostPortPair : serverAddresses) {
        ReceivingClient client;
        if (!this.liveTcpClients.containsKey(hostPortPair)) {
            String[] hostAndPort = hostPortPair.split(":");
            InetSocketAddress address = new InetSocketAddress(hostAndPort[0], Integer.parseInt(hostAndPort[1]));
            client = new ReceivingClient(address, this.clientScheduler, this.receiveBufferSize, this.endOfMessageByte);
            client.setReconnectAttempts(this.connectionAttemptCount);
            client.setDelayMillisBeforeReconnect(this.reconnectInterval);
            client.setMessageHandler(this.delegatingMessageHandler);
            this.liveTcpClients.put(hostPortPair, client);
            this.startClient(client);
        } else {
            client = this.liveTcpClients.get(hostPortPair);
            if (!client.isRunning()) {
                // primarily for cleanup in the event of abnormal termination
                client.stop();
                this.startClient(client);
            }
        }
    }
}

19 View Complete Implementation : ConsumeMQTT.java
Copyright Apache License 2.0
Author : apache
private void initializeClient(ProcessContext context) {
    // NOTE: This method is called when isConnected returns false which can happen when the client is null, or when it is
    // non-null but not connected, so we need to handle each case and only create a new client when it is null
    try {
        if (mqttClient == null) {
            logger.debug("Creating client");
            mqttClient = createMqttClient(broker, clientID, persistence);
            mqttClient.setCallback(this);
        }
        if (!mqttClient.isConnected()) {
            logger.debug("Connecting client");
            mqttClient.connect(connOpts);
            mqttClient.subscribe(topicFilter, qos);
        }
    } catch (MqttException e) {
        logger.error("Connection to {} lost (or was never connected) and connection failed. Yielding processor", new Object[] { broker }, e);
        context.yield();
    }
}

19 View Complete Implementation : AbstractSNMPProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Delegate method to supplement
 * {@link #onTrigger(ProcessContext, ProcessSession)}. It is implemented by
 * sub-clreplacedes to perform {@link Processor} specific functionality.
 *
 * @param context
 *            instance of {@link ProcessContext}
 * @param session
 *            instance of {@link ProcessSession}
 * @throws ProcessException Process exception
 */
protected abstract void onTriggerSnmp(ProcessContext context, ProcessSession session) throws ProcessException;

19 View Complete Implementation : AbstractSNMPProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Builds target resource.
 * @param context Process context
 */
private void buildTargetResource(ProcessContext context) {
    if ((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) {
        try {
            this.transportMapping = new DefaultUdpTransportMapping();
            this.snmp = new Snmp(this.transportMapping);
            if ("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) {
                USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
                SecurityModels.getInstance().addSecurityModel(usm);
            }
            this.transportMapping.listen();
        } catch (Exception e) {
            throw new IllegalStateException("Failed to initialize UDP transport mapping", e);
        }
    }
    if (this.snmpTarget == null) {
        this.snmpTarget = this.createSnmpTarget(context);
    }
    if (this.targetResource == null) {
        this.targetResource = this.finishBuildingTargetResource(context);
    }
}

19 View Complete Implementation : AbstractListenEventProcessor.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    charset = Charset.forName(context.getProperty(CHARSET).getValue());
    port = context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
    events = new LinkedBlockingQueue<>(context.getProperty(MAX_MESSAGE_QUEUE_SIZE).asInteger());
    final String nicIPAddressStr = context.getProperty(NETWORK_INTF_NAME).evaluateAttributeExpressions().getValue();
    final int maxChannelBufferSize = context.getProperty(MAX_SOCKET_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    InetAddress nicIPAddress = null;
    if (!StringUtils.isEmpty(nicIPAddressStr)) {
        NetworkInterface netIF = NetworkInterface.getByName(nicIPAddressStr);
        nicIPAddress = netIF.getInetAddresses().nextElement();
    }
    // create the dispatcher and call open() to bind to the given port
    dispatcher = createDispatcher(context, events);
    dispatcher.open(nicIPAddress, port, maxChannelBufferSize);
    // start a thread to run the dispatcher
    final Thread readerThread = new Thread(dispatcher);
    readerThread.setName(getClreplaced().getName() + " [" + getIdentifier() + "]");
    readerThread.setDaemon(true);
    readerThread.start();
}

19 View Complete Implementation : AbstractListProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Performs a listing of the remote enreplacedies that can be pulled. If any enreplacedy that is returned has already been "discovered" or "emitted"
 * by this Processor, it will be ignored. A discussion of how the Processor determines those enreplacedies that have already been emitted is
 * provided above in the doreplacedentation for this clreplaced. Any enreplacedy that is returned by this method with a timestamp prior to the minTimestamp
 * will be filtered out by the Processor. Therefore, it is not necessary that implementations perform this filtering but can be more efficient
 * if the filtering can be performed on the server side prior to retrieving the information.
 *
 * @param context      the ProcessContex to use in order to pull the appropriate enreplacedies
 * @param minTimestamp the minimum timestamp of enreplacedies that should be returned.
 * @return a Listing of enreplacedies that have a timestamp >= minTimestamp
 */
protected abstract List<T> performListing(final ProcessContext context, final Long minTimestamp) throws IOException;

19 View Complete Implementation : AbstractDeleteHBase.java
Copyright Apache License 2.0
Author : apache
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    try {
        doDelete(context, session);
    } catch (Exception e) {
        getLogger().error("Error", e);
    } finally {
        session.commit();
    }
}

19 View Complete Implementation : ExecuteFlumeSource.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(final ProcessContext context) {
    try {
        source = SOURCE_FACTORY.create(context.getProperty(SOURCE_NAME).getValue(), context.getProperty(SOURCE_TYPE).getValue());
        String flumeConfig = context.getProperty(FLUME_CONFIG).getValue();
        String agentName = context.getProperty(AGENT_NAME).getValue();
        String sourceName = context.getProperty(SOURCE_NAME).getValue();
        Configurables.configure(source, getFlumeSourceContext(flumeConfig, agentName, sourceName));
        if (source instanceof PollableSource) {
            source.setChannelProcessor(new ChannelProcessor(new NifiChannelSelector(pollableSourceChannel)));
            source.start();
        }
    } catch (Throwable th) {
        getLogger().error("Error creating source", th);
        throw Throwables.propagate(th);
    }
}

19 View Complete Implementation : MonitorActivity.java
Copyright Apache License 2.0
Author : apache
private boolean isClusterScope(final ProcessContext context, boolean logInvalidConfig) {
    if (SCOPE_CLUSTER.equals(context.getProperty(MONITORING_SCOPE).getValue())) {
        if (getNodeTypeProvider().isClustered()) {
            return true;
        }
        if (logInvalidConfig) {
            getLogger().warn("NiFi is running as a Standalone mode, but 'cluster' scope is set." + " Fallback to 'node' scope. Fix configuration to stop this message.");
        }
    }
    return false;
}

19 View Complete Implementation : AbstractEmailProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Builds the url used to connect to the email server.
 */
String buildUrl(ProcessContext processContext) {
    String host = processContext.getProperty(HOST).evaluateAttributeExpressions().getValue();
    String port = processContext.getProperty(PORT).evaluateAttributeExpressions().getValue();
    String user = processContext.getProperty(USER).evaluateAttributeExpressions().getValue();
    String preplacedword = processContext.getProperty(PreplacedWORD).evaluateAttributeExpressions().getValue();
    String folder = processContext.getProperty(FOLDER).evaluateAttributeExpressions().getValue();
    StringBuilder urlBuilder = new StringBuilder();
    try {
        urlBuilder.append(URLEncoder.encode(user, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new ProcessException(e);
    }
    urlBuilder.append(":");
    try {
        urlBuilder.append(URLEncoder.encode(preplacedword, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new ProcessException(e);
    }
    urlBuilder.append("@");
    urlBuilder.append(host);
    urlBuilder.append(":");
    urlBuilder.append(port);
    urlBuilder.append("/");
    urlBuilder.append(folder);
    String protocol = this.getProtocol(processContext);
    String finalUrl = protocol + "://" + urlBuilder.toString();
    // build display-safe URL
    int preplacedwordStartIndex = urlBuilder.indexOf(":") + 1;
    int preplacedwordEndIndex = urlBuilder.indexOf("@");
    urlBuilder.replace(preplacedwordStartIndex, preplacedwordEndIndex, "[preplacedword]");
    this.displayUrl = protocol + "://" + urlBuilder.toString();
    if (this.logger.isInfoEnabled()) {
        this.logger.info("Connecting to Email server at the following URL: " + this.displayUrl);
    }
    return finalUrl;
}

19 View Complete Implementation : FetchHBaseRow.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(ProcessContext context) {
    this.decodeCharset = Charset.forName(context.getProperty(DECODE_CHARSET).getValue());
    this.encodeCharset = Charset.forName(context.getProperty(ENCODE_CHARSET).getValue());
    final String jsonFormat = context.getProperty(JSON_FORMAT).getValue();
    if (jsonFormat.equals(JSON_FORMAT_FULL_ROW.getValue())) {
        this.regularRowSerializer = new JsonFullRowSerializer(decodeCharset, encodeCharset);
        this.base64RowSerializer = new JsonFullRowSerializer(decodeCharset, encodeCharset, true);
    } else {
        this.regularRowSerializer = new JsonQualifierAndValueRowSerializer(decodeCharset, encodeCharset);
        this.base64RowSerializer = new JsonQualifierAndValueRowSerializer(decodeCharset, encodeCharset, true);
    }
}

19 View Complete Implementation : PartialFunctions.java
Copyright Apache License 2.0
Author : apache
public static void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory, ComponentLog logger, OnTrigger onTrigger, RollbackSession rollbackSession) throws ProcessException {
    final ProcessSession session = sessionFactory.createSession();
    try {
        onTrigger.execute(session);
        session.commit();
    } catch (final Throwable t) {
        logger.error("{} failed to process due to {}; rolling back session", new Object[] { onTrigger, t });
        rollbackSession.rollback(session, t);
        throw t;
    }
}

19 View Complete Implementation : ExecuteFlumeSink.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(final ProcessContext context) {
    try {
        channel = new NifiSinkSessionChannel(SUCCESS, FAILURE);
        channel.start();
        sink = SINK_FACTORY.create(context.getProperty(SOURCE_NAME).getValue(), context.getProperty(SINK_TYPE).getValue());
        sink.setChannel(channel);
        String flumeConfig = context.getProperty(FLUME_CONFIG).getValue();
        String agentName = context.getProperty(AGENT_NAME).getValue();
        String sinkName = context.getProperty(SOURCE_NAME).getValue();
        Configurables.configure(sink, getFlumeSinkContext(flumeConfig, agentName, sinkName));
        sink.start();
    } catch (Throwable th) {
        getLogger().error("Error creating sink", th);
        throw Throwables.propagate(th);
    }
}

19 View Complete Implementation : AbstractListProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Returns the path to perform a listing on.
 * Many resources can be comprised of a "path" (or a "container" or "bucket", etc.) as well as name or identifier that is unique only
 * within that path. This method is responsible for returning the path that is currently being polled for enreplacedies. If this does concept
 * does not apply for the concrete implementation, it is recommended that the concrete implementation return "." or "/" for all invocations of this method.
 *
 * @param context the ProcessContex to use in order to obtain configuration
 * @return the path that is to be used to perform the listing, or <code>null</code> if not applicable.
 */
protected abstract String getPath(final ProcessContext context);

19 View Complete Implementation : BinFiles.java
Copyright Apache License 2.0
Author : apache
private int migrateBins(final ProcessContext context) {
    int added = 0;
    for (final Bin bin : binManager.removeReadyBins(true)) {
        this.readyBins.add(bin);
        added++;
    }
    // if we have created all of the bins that are allowed, go ahead and remove the oldest one. If we don't do
    // this, then we will simply wait for it to expire because we can't get any more FlowFiles into the
    // bins. So we may as well expire it now.
    if (added == 0 && binManager.getBinCount() >= context.getProperty(MAX_BIN_COUNT).asInteger()) {
        final Bin bin = binManager.removeOldestBin();
        if (bin != null) {
            added++;
            this.readyBins.add(bin);
        }
    }
    return added;
}

19 View Complete Implementation : SolrProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Create a SolrClient based on the type of Solr specified.
 *
 * @param context
 *          The context
 * @return an HttpSolrClient or CloudSolrClient
 */
protected SolrClient createSolrClient(final ProcessContext context, final String solrLocation) {
    return SolrUtils.createSolrClient(context, solrLocation);
}

19 View Complete Implementation : ConsumeJMS.java
Copyright Apache License 2.0
Author : apache
/**
 * <p>
 * Use provided clientId for non shared durable consumers, if not set
 * always a different value as defined in {@link AbstractJMSProcessor#setClientId(ProcessContext, SingleConnectionFactory)}.
 * </p>
 * See {@link Session#createDurableConsumer(javax.jms.Topic, String, String, boolean)},
 * in special following part: <i>An unshared durable subscription is
 * identified by a name specified by the client and by the client identifier,
 * which must be set. An application which subsequently wishes to create
 * a consumer on that unshared durable subscription must use the same
 * client identifier.</i>
 */
@Override
protected void setClientId(ProcessContext context, SingleConnectionFactory cachingFactory) {
    if (isDurableSubscriber(context) && !isShared(context)) {
        cachingFactory.setClientId(getClientId(context));
    } else {
        super.setClientId(context, cachingFactory);
    }
}

19 View Complete Implementation : PutTCP.java
Copyright Apache License 2.0
Author : apache
/**
 * Gets the current value of the "Connection Per FlowFile" property.
 *
 * @param context
 *            - the current process context.
 *
 * @return boolean value - true if a connection per FlowFile is specified.
 */
protected boolean isConnectionPerFlowFile(final ProcessContext context) {
    return context.getProperty(CONNECTION_PER_FLOWFILE).getValue().equalsIgnoreCase("true");
}

19 View Complete Implementation : ListenGRPC.java
Copyright Apache License 2.0
Author : apache
@OnStopped
public void stopServer(final ProcessContext context) {
    if (this.server != null) {
        try {
            this.server.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            getLogger().warn("Unable to cleanly shutdown embedded gRPC server due to {}", new Object[] { e });
            this.server = null;
        }
    }
}

19 View Complete Implementation : AbstractSNMPProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Will builds target resource upon first invocation and will delegate to the
 * implementation of {@link #onTriggerSnmp(ProcessContext, ProcessSession)} method for
 * further processing.
 */
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    synchronized (this) {
        this.buildTargetResource(context);
    }
    this.onTriggerSnmp(context, session);
}

19 View Complete Implementation : AbstractEnrichIP.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    final String dbFileString = context.getProperty(GEO_DATABASE_FILE).evaluateAttributeExpressions().getValue();
    final File dbFile = new File(dbFileString);
    final StopWatch stopWatch = new StopWatch(true);
    final DatabaseReader reader = new DatabaseReader.Builder(dbFile).build();
    stopWatch.stop();
    getLogger().info("Completed loading of Maxmind Database.  Elapsed time was {} milliseconds.", new Object[] { stopWatch.getDuration(TimeUnit.MILLISECONDS) });
    databaseReaderRef.set(reader);
}

19 View Complete Implementation : ConsumeAzureEventHub.java
Copyright Apache License 2.0
Author : apache
@OnStopped
public void unregisterEventProcessor(final ProcessContext context) {
    if (eventProcessorHost != null) {
        try {
            eventProcessorHost.unregisterEventProcessor();
            eventProcessorHost = null;
            processSessionFactory = null;
            readerFactory = null;
            writerFactory = null;
        } catch (Exception e) {
            throw new RuntimeException("Failed to unregister the event processor due to " + e, e);
        }
    }
}

19 View Complete Implementation : PutUDP.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a Universal Resource Identifier (URI) for this processor. Constructs a URI of the form UDP://host:port where the host and port values are taken from the configured property values.
 *
 * @param context
 *            - the current process context.
 *
 * @return The URI value as a String.
 */
@Override
protected String createTransitUri(final ProcessContext context) {
    final String protocol = UDP_VALUE.getValue();
    final String host = context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue();
    final String port = context.getProperty(PORT).evaluateAttributeExpressions().getValue();
    return new StringBuilder().append(protocol).append("://").append(host).append(":").append(port).toString();
}

19 View Complete Implementation : RollbackOnFailure.java
Copyright Apache License 2.0
Author : apache
public static <FCT extends RollbackOnFailure> void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory, FCT functionContext, ComponentLog logger, PartialFunctions.OnTrigger onTrigger) throws ProcessException {
    PartialFunctions.onTrigger(context, sessionFactory, logger, onTrigger, (session, t) -> {
        // If RollbackOnFailure is enabled, do not penalize processing FlowFiles when rollback,
        // in order to keep those in the incoming relationship to be processed again.
        final boolean shouldPenalize = !functionContext.isRollbackOnFailure();
        session.rollback(shouldPenalize);
        // However, keeping failed FlowFile in the incoming relationship would retry it too often.
        // So, administratively yield the process.
        if (functionContext.isRollbackOnFailure()) {
            logger.warn("Administratively yielding {} after rolling back due to {}", new Object[] { context.getName(), t }, t);
            context.yield();
        }
    });
}

19 View Complete Implementation : AbstractEmailProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Builds and initializes the target message receiver if necessary (if it's
 * null). Upon execution of this operation the receiver is fully functional
 * and is ready to receive messages.
 */
private synchronized void initializeIfNecessary(ProcessContext context, ProcessSession processSession) {
    if (this.messageReceiver == null) {
        this.processSession = processSession;
        this.messageReceiver = this.buildMessageReceiver(context);
        this.shouldSetDeleteFlag = context.getProperty(SHOULD_DELETE_MESSAGES).asBoolean();
        int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger();
        this.messageReceiver.setMaxFetchSize(fetchSize);
        this.messageReceiver.setJavaMailProperties(this.buildJavaMailProperties(context));
        // need to avoid spring warning messages
        this.messageReceiver.setBeanFactory(new StaticListableBeanFactory());
        this.messageReceiver.afterPropertiesSet();
        this.messageQueue = new ArrayBlockingQueue<>(fetchSize);
    }
}

19 View Complete Implementation : AbstractMongoProcessor.java
Copyright Apache License 2.0
Author : apache
protected WriteConcern getWriteConcern(final ProcessContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;
    switch(writeConcernProperty) {
        case WRITE_CONCERN_ACKNOWLEDGED:
            writeConcern = WriteConcern.ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_UNACKNOWLEDGED:
            writeConcern = WriteConcern.UNACKNOWLEDGED;
            break;
        case WRITE_CONCERN_FSYNCED:
            writeConcern = WriteConcern.FSYNCED;
            break;
        case WRITE_CONCERN_JOURNALED:
            writeConcern = WriteConcern.JOURNALED;
            break;
        case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
            writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_MAJORITY:
            writeConcern = WriteConcern.MAJORITY;
            break;
        default:
            writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}

19 View Complete Implementation : AbstractSNMPProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Delegate method to supplement building of target {@link SNMPWorker} (see
 * {@link SNMPSetter} or {@link SNMPGetter}) and is implemented by
 * sub-clreplacedes.
 *
 * @param context
 *            instance of {@link ProcessContext}
 * @return new instance of {@link SNMPWorker}
 */
protected abstract T finishBuildingTargetResource(ProcessContext context);

19 View Complete Implementation : PublishMQTT.java
Copyright Apache License 2.0
Author : apache
private void initializeClient(ProcessContext context) {
    // NOTE: This method is called when isConnected returns false which can happen when the client is null, or when it is
    // non-null but not connected, so we need to handle each case and only create a new client when it is null
    try {
        if (mqttClient == null) {
            logger.debug("Creating client");
            mqttClient = createMqttClient(broker, clientID, persistence);
            mqttClient.setCallback(this);
        }
        if (!mqttClient.isConnected()) {
            logger.debug("Connecting client");
            mqttClient.connect(connOpts);
        }
    } catch (MqttException e) {
        logger.error("Connection to {} lost (or was never connected) and connection failed. Yielding processor", new Object[] { broker }, e);
        context.yield();
    }
}

19 View Complete Implementation : AbstractListenEventBatchingProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Called at the end of onTrigger to allow sub-clreplacedes to take post processing action on the events
 *
 * @param context the current context
 * @param session the current session
 * @param events the list of all events processed by the current execution of onTrigger
 */
protected void postProcess(ProcessContext context, ProcessSession session, final List<E> events) {
// empty implementation so sub-clreplacedes only have to override if necessary
}

19 View Complete Implementation : AbstractIgniteCacheProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Initialize the ignite cache instance
 * @param context process context
 * @throws ProcessException if there is a problem while scheduling the processor
 */
public void initializeIgniteCache(ProcessContext context) throws ProcessException {
    getLogger().info("Initializing Ignite cache");
    try {
        if (getIgnite() == null) {
            getLogger().info("Initializing ignite as client");
            super.initializeIgnite(context);
        }
        cacheName = context.getProperty(CACHE_NAME).getValue();
    } catch (Exception e) {
        getLogger().error("Failed to initialize ignite cache due to {}", new Object[] { e }, e);
        throw new ProcessException(e);
    }
}

19 View Complete Implementation : KafkaProcessorUtils.java
Copyright Apache License 2.0
Author : apache
/**
 * Method used to configure the 'sasl.jaas.config' property based on KAFKA-4259<br />
 * https://cwiki.apache.org/confluence/display/KAFKA/KIP-85%3A+Dynamic+JAAS+configuration+for+Kafka+clients<br />
 * <br />
 * It expects something with the following format: <br />
 * <br />
 * <LoginModuleClreplaced> <ControlFlag> *(<OptionName>=<OptionValue>); <br />
 * ControlFlag = required / requisite / sufficient / optional
 *
 * @param mapToPopulate Map of configuration properties
 * @param context Context
 */
private static void setJaasConfig(Map<String, Object> mapToPopulate, ProcessContext context) {
    final String saslMechanism = context.getProperty(SASL_MECHANISM).getValue();
    switch(saslMechanism) {
        case GSSAPI_VALUE:
            setGssApiJaasConfig(mapToPopulate, context);
            break;
        case PLAIN_VALUE:
            setPlainJaasConfig(mapToPopulate, context);
            break;
        case SCRAM_SHA256_VALUE:
            setScramJaasConfig(mapToPopulate, context);
            break;
        default:
            throw new IllegalStateException("Unknown " + SASL_MECHANISM.getDisplayName() + ": " + saslMechanism);
    }
}

19 View Complete Implementation : TestSFTPTransfer.java
Copyright Apache License 2.0
Author : apache
private SFTPTransfer createSftpTransfer(ProcessContext processContext, SFTPClient sftpClient) {
    final ComponentLog componentLog = mock(ComponentLog.clreplaced);
    return new SFTPTransfer(processContext, componentLog) {

        @Override
        protected SFTPClient getSFTPClient(FlowFile flowFile) throws IOException {
            return sftpClient;
        }
    };
}

19 View Complete Implementation : ConsumeWindowsEventLog.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(ProcessContext context) throws AlreadySubscribedException {
    if (isSubscribed()) {
        throw new AlreadySubscribedException(PROCESSOR_ALREADY_SUBSCRIBED);
    }
    String errorMessage = subscribe(context);
    if (errorMessage != null) {
        getLogger().error(errorMessage);
    }
}

19 View Complete Implementation : BinFiles.java
Copyright Apache License 2.0
Author : apache
/**
 * Processes a single bin. Implementing clreplaced is responsible for committing each session
 *
 * @param unmodifiableBin A reference to a single bin of flow files
 * @param context The context
 * @return <code>true</code> if the input bin was already committed. E.g., in case of a failure, the implementation
 *         may choose to transfer all binned files to Failure and commit their sessions. If
 *         false, the processBins() method will transfer the files to Original and commit the sessions
 *
 * @throws ProcessException if any problem arises while processing a bin of FlowFiles. All flow files in the bin
 *             will be transferred to failure and the ProcessSession provided by the 'session'
 *             argument rolled back
 */
protected abstract BinProcessingResult processBin(Bin unmodifiableBin, ProcessContext context) throws ProcessException;

19 View Complete Implementation : PutMongo.java
Copyright Apache License 2.0
Author : apache
protected WriteConcern getWriteConcern(final ProcessContext context) {
    final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue();
    WriteConcern writeConcern = null;
    switch(writeConcernProperty) {
        case WRITE_CONCERN_ACKNOWLEDGED:
            writeConcern = WriteConcern.ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_UNACKNOWLEDGED:
            writeConcern = WriteConcern.UNACKNOWLEDGED;
            break;
        case WRITE_CONCERN_FSYNCED:
            writeConcern = WriteConcern.FSYNCED;
            break;
        case WRITE_CONCERN_JOURNALED:
            writeConcern = WriteConcern.JOURNALED;
            break;
        case WRITE_CONCERN_REPLICA_ACKNOWLEDGED:
            writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED;
            break;
        case WRITE_CONCERN_MAJORITY:
            writeConcern = WriteConcern.MAJORITY;
            break;
        default:
            writeConcern = WriteConcern.ACKNOWLEDGED;
    }
    return writeConcern;
}

19 View Complete Implementation : ConsumeWindowsEventLog.java
Copyright Apache License 2.0
Author : apache
/**
 * Register subscriber via native call
 *
 * @param context the process context
 */
private String subscribe(ProcessContext context) {
    final String channel = context.getProperty(CHANNEL).evaluateAttributeExpressions().getValue();
    final String query = context.getProperty(QUERY).evaluateAttributeExpressions().getValue();
    renderedXMLs = new LinkedBlockingQueue<>(context.getProperty(MAX_EVENT_QUEUE_SIZE).asInteger());
    try {
        provenanceUri = new URI("winlog", name, "/" + channel, query, null).toASCIIString();
    } catch (URISyntaxException e) {
        getLogger().debug("Failed to construct detailed provenanceUri from channel={}, query={}, use simpler one.", new Object[] { channel, query });
        provenanceUri = String.format("winlog://%s/%s", name, channel);
    }
    inactiveDurationToReconnect = context.getProperty(INACTIVE_DURATION_TO_RECONNECT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS);
    evtSubscribeCallback = new EventSubscribeXmlRenderingCallback(getLogger(), s -> {
        try {
            renderedXMLs.put(s);
        } catch (InterruptedException e) {
            throw new IllegalStateException("Got interrupted while waiting to add to queue.", e);
        }
    }, context.getProperty(MAX_BUFFER_SIZE).asInteger(), wEvtApi, kernel32, errorLookup);
    subscriptionHandle = wEvtApi.EvtSubscribe(null, null, channel, query, null, null, evtSubscribeCallback, WEvtApi.EvtSubscribeFlags.SUBSCRIBE_TO_FUTURE | WEvtApi.EvtSubscribeFlags.EVT_SUBSCRIBE_STRICT);
    if (!isSubscribed()) {
        return UNABLE_TO_SUBSCRIBE + errorLookup.getLastError();
    }
    lastActivityTimestamp = System.currentTimeMillis();
    return null;
}

18 View Complete Implementation : AttributesToJSON.java
Copyright Apache License 2.0
Author : apache
@OnScheduled
public void onScheduled(ProcessContext context) {
    attributesToRemove = context.getProperty(INCLUDE_CORE_ATTRIBUTES).asBoolean() ? Collections.EMPTY_SET : Arrays.stream(CoreAttributes.values()).map(CoreAttributes::key).collect(Collectors.toSet());
    attributes = buildAtrs(context.getProperty(ATTRIBUTES_LIST).getValue(), attributesToRemove);
    nullValueForEmptyString = context.getProperty(NULL_VALUE_FOR_EMPTY_STRING).asBoolean();
    destinationContent = DESTINATION_CONTENT.equals(context.getProperty(DESTINATION).getValue());
    if (context.getProperty(ATTRIBUTES_REGEX).isSet()) {
        pattern = Pattern.compile(context.getProperty(ATTRIBUTES_REGEX).evaluateAttributeExpressions().getValue());
    }
}

18 View Complete Implementation : AbstractSQSProcessor.java
Copyright Apache License 2.0
Author : apache
/**
 * Create client using AWSCredentials
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AmazonSQSClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().info("Creating client using aws credentials ");
    return new AmazonSQSClient(credentials, config);
}

18 View Complete Implementation : JsonQueryElasticsearch.java
Copyright Apache License 2.0
Author : apache
private List<FlowFile> handleHits(List<Map<String, Object>> hits, ProcessContext context, ProcessSession session, FlowFile parent, Map<String, String> attributes) throws IOException {
    String splitUpValue = context.getProperty(SPLIT_UP_HITS).getValue();
    List<FlowFile> retVal = new ArrayList<>();
    if (splitUpValue.equals(SPLIT_UP_YES.getValue())) {
        for (Map<String, Object> hit : hits) {
            FlowFile hitFlowFile = parent != null ? session.create(parent) : session.create();
            String json = mapper.writeValuereplacedtring(hit);
            retVal.add(writeHitFlowFile(json, session, hitFlowFile, attributes));
        }
    } else {
        FlowFile hitFlowFile = parent != null ? session.create(parent) : session.create();
        String json = mapper.writeValuereplacedtring(hits);
        retVal.add(writeHitFlowFile(json, session, hitFlowFile, attributes));
    }
    return retVal;
}

18 View Complete Implementation : BinFiles.java
Copyright Apache License 2.0
Author : apache
@Override
public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) throws ProcessException {
    final int totalBinCount = binManager.getBinCount() + readyBins.size();
    final int maxBinCount = context.getProperty(MAX_BIN_COUNT).asInteger();
    final int flowFilesBinned;
    if (totalBinCount < maxBinCount) {
        flowFilesBinned = binFlowFiles(context, sessionFactory);
        getLogger().debug("Binned {} FlowFiles", new Object[] { flowFilesBinned });
    } else {
        flowFilesBinned = 0;
        getLogger().debug("Will not bin any FlowFiles because {} bins already exist;" + "will wait until bins have been emptied before any more are created", new Object[] { totalBinCount });
    }
    if (!isScheduled()) {
        return;
    }
    final int binsMigrated = migrateBins(context);
    final int binsProcessed = processBins(context);
    // If we accomplished nothing then let's yield
    if (flowFilesBinned == 0 && binsMigrated == 0 && binsProcessed == 0) {
        context.yield();
    }
}

18 View Complete Implementation : MonitorActivity.java
Copyright Apache License 2.0
Author : apache
@OnStopped
public void onStopped(final ProcessContext context) {
    if (getNodeTypeProvider().isPrimary()) {
        final StateManager stateManager = context.getStateManager();
        try {
            stateManager.clear(Scope.CLUSTER);
        } catch (IOException e) {
            getLogger().error("Failed to clear cluster state due to " + e, e);
        }
    }
}

18 View Complete Implementation : AbstractPutHBase.java
Copyright Apache License 2.0
Author : apache
/**
 * Sub-clreplacedes provide the implementation to create a put from a FlowFile.
 *
 * @param session
 *              the current session
 * @param context
 *              the current context
 * @param flowFile
 *              the FlowFile to create a Put from
 *
 * @return a PutFlowFile instance for the given FlowFile
 */
protected abstract PutFlowFile createPut(final ProcessSession session, final ProcessContext context, final FlowFile flowFile);

18 View Complete Implementation : ConsumeEWS.java
Copyright Apache License 2.0
Author : apache
/**
 * Will flush the remaining messages when this processor is stopped.
 */
protected void flushRemainingMessages(ProcessContext processContext) {
    Message emailMessage;
    try {
        while ((emailMessage = this.messageQueue.poll(1, TimeUnit.MILLISECONDS)) != null) {
            this.transfer(emailMessage, processContext, this.processSession);
            this.processSession.commit();
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        this.logger.debug("Current thread is interrupted");
    }
}

18 View Complete Implementation : LogAttribute.java
Copyright Apache License 2.0
Author : apache
private Set<String> getAttributesToLog(final Set<String> flowFileAttrKeys, final ProcessContext context) {
    // collect properties
    final String attrsToLogValue = context.getProperty(ATTRIBUTES_TO_LOG_CSV).getValue();
    final String attrsToRemoveValue = context.getProperty(ATTRIBUTES_TO_IGNORE_CSV).getValue();
    final Set<String> attrsToLog = StringUtils.isBlank(attrsToLogValue) ? Sets.newHashSet(flowFileAttrKeys) : Sets.newHashSet(attrsToLogValue.split("\\s*,\\s*"));
    final Set<String> attrsToRemove = StringUtils.isBlank(attrsToRemoveValue) ? Sets.newHashSet() : Sets.newHashSet(attrsToRemoveValue.split("\\s*,\\s*"));
    final Pattern attrsToLogRegex = Pattern.compile(context.getProperty(ATTRIBUTES_TO_LOG_REGEX).getValue());
    final String attrsToRemoveRegexValue = context.getProperty(ATTRIBUTES_TO_IGNORE_REGEX).getValue();
    final Pattern attrsToRemoveRegex = attrsToRemoveRegexValue == null ? null : Pattern.compile(context.getProperty(ATTRIBUTES_TO_IGNORE_REGEX).getValue());
    return flowFileAttrKeys.stream().filter(candidate -> {
        // we'll consider logging an attribute if either no explicit attributes to log were configured,
        // if this property was configured to be logged, or if the regular expression of properties to log matches
        if ((attrsToLog.isEmpty() || attrsToLog.contains(candidate)) && attrsToLogRegex.matcher(candidate).matches()) {
            // log properties we've _not_ configured either explicitly or by regular expression to be ignored.
            if ((attrsToRemove.isEmpty() || !attrsToRemove.contains(candidate)) && (attrsToRemoveRegex == null || !attrsToRemoveRegex.matcher(candidate).matches())) {
                return true;
            }
        }
        return false;
    }).collect(Collectors.toCollection(TreeSet::new));
}