Java Code Examples for org.apache.nifi.annotation.lifecycle.OnScheduled

The following examples show how to use org.apache.nifi.annotation.lifecycle.OnScheduled. These examples are extracted from open source projects. 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 Project: localization_nifi   Author: wangrenlei   File: BinFiles.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public final void onScheduled(final ProcessContext context) throws IOException {
    binManager.setMinimumSize(context.getProperty(MIN_SIZE).asDataSize(DataUnit.B).longValue());

    if (context.getProperty(MAX_BIN_AGE).isSet()) {
        binManager.setMaxBinAge(context.getProperty(MAX_BIN_AGE).asTimePeriod(TimeUnit.SECONDS).intValue());
    } else {
        binManager.setMaxBinAge(Integer.MAX_VALUE);
    }

    if (context.getProperty(MAX_SIZE).isSet()) {
        binManager.setMaximumSize(context.getProperty(MAX_SIZE).asDataSize(DataUnit.B).longValue());
    } else {
        binManager.setMaximumSize(Long.MAX_VALUE);
    }

    binManager.setMinimumEntries(context.getProperty(MIN_ENTRIES).asInteger());

    if (context.getProperty(MAX_ENTRIES).isSet()) {
        binManager.setMaximumEntries(context.getProperty(MAX_ENTRIES).asInteger().intValue());
    } else {
        binManager.setMaximumEntries(Integer.MAX_VALUE);
    }

    this.setUpBinManager(binManager, context);
}
 
Example #2
Source Project: localization_nifi   Author: wangrenlei   File: GetTCP.java    License: Apache License 2.0 6 votes vote down vote up
@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());
        }
    }
}
 
Example #3
Source Project: localization_nifi   Author: wangrenlei   File: AbstractListenEventProcessor.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    charset = Charset.forName(context.getProperty(CHARSET).getValue());
    port = context.getProperty(PORT).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(getClass().getName() + " [" + getIdentifier() + "]");
    readerThread.setDaemon(true);
    readerThread.start();
}
 
Example #4
Source Project: localization_nifi   Author: wangrenlei   File: ExecuteFlumeSource.java    License: Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #5
Source Project: localization_nifi   Author: wangrenlei   File: PutAzureEventHub.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public final void setupClient(final ProcessContext context) throws ProcessException{
    final String policyName = context.getProperty(ACCESS_POLICY).getValue();
    final String policyKey = context.getProperty(POLICY_PRIMARY_KEY).getValue();
    final String namespace = context.getProperty(NAMESPACE).getValue();
    final String eventHubName = context.getProperty(EVENT_HUB_NAME).getValue();


    final int numThreads = context.getMaxConcurrentTasks();
    senderQueue = new LinkedBlockingQueue<>(numThreads);
    for (int i = 0; i < numThreads; i++) {
        final EventHubClient client = createEventHubClient(namespace, eventHubName, policyName, policyKey);
        if(null != client) {
            senderQueue.offer(client);
        }
    }
}
 
Example #6
Source Project: localization_nifi   Author: wangrenlei   File: ExecuteScript.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Performs setup operations when the processor is scheduled to run. This includes evaluating the processor's
 * properties, as well as reloading the script (from file or the "Script Body" property)
 *
 * @param context the context in which to perform the setup operations
 */
@OnScheduled
public void setup(final ProcessContext context) {
    scriptingComponentHelper.setupVariables(context);

    // Create a script engine for each possible task
    int maxTasks = context.getMaxConcurrentTasks();
    scriptingComponentHelper.setup(maxTasks, getLogger());
    scriptToRun = scriptingComponentHelper.getScriptBody();

    try {
        if (scriptToRun == null && scriptingComponentHelper.getScriptPath() != null) {
            try (final FileInputStream scriptStream = new FileInputStream(scriptingComponentHelper.getScriptPath())) {
                scriptToRun = IOUtils.toString(scriptStream, Charset.defaultCharset());
            }
        }
    } catch (IOException ioe) {
        throw new ProcessException(ioe);
    }
}
 
Example #7
Source Project: localization_nifi   Author: wangrenlei   File: RouteText.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * When this processor is scheduled, update the dynamic properties into the map
 * for quick access during each onTrigger call
 *
 * @param context ProcessContext used to retrieve dynamic properties
 */
@OnScheduled
public void onScheduled(final ProcessContext context) {
    final String regex = context.getProperty(GROUPING_REGEX).getValue();
    if (regex != null) {
        groupingRegex = Pattern.compile(regex);
    }

    final Map<Relationship, PropertyValue> newPropertyMap = new HashMap<>();
    for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
        if (!descriptor.isDynamic()) {
            continue;
        }
        getLogger().debug("Adding new dynamic property: {}", new Object[] {descriptor});
        newPropertyMap.put(new Relationship.Builder().name(descriptor.getName()).build(), context.getProperty(descriptor));
    }

    this.propertyMap = newPropertyMap;
}
 
Example #8
Source Project: localization_nifi   Author: wangrenlei   File: ExecuteFlumeSink.java    License: Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #9
Source Project: localization_nifi   Author: wangrenlei   File: TransformXml.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) {
    final ComponentLog logger = getLogger();
    final Integer cacheSize = context.getProperty(CACHE_SIZE).asInteger();
    final Long cacheTTL = context.getProperty(CACHE_TTL_AFTER_LAST_ACCESS).asTimePeriod(TimeUnit.SECONDS);

    if (cacheSize > 0) {
        CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(cacheSize);
        if (cacheTTL > 0) {
            cacheBuilder = cacheBuilder.expireAfterAccess(cacheTTL, TimeUnit.SECONDS);
        }

        cache = cacheBuilder.build(
           new CacheLoader<String, Templates>() {
               public Templates load(String path) throws TransformerConfigurationException {
                   return newTemplates(path);
               }
           });
    } else {
        cache = null;
        logger.warn("Stylesheet cache disabled because cache size is set to 0");
    }
}
 
Example #10
Source Project: localization_nifi   Author: wangrenlei   File: ControllerStatusReportingTask.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public void onConfigured(final ConfigurationContext context) {
    connectionLineFormat = context.getProperty(SHOW_DELTAS).asBoolean() ? CONNECTION_LINE_FORMAT_WITH_DELTA : CONNECTION_LINE_FORMAT_NO_DELTA;
    connectionHeader = String.format(connectionLineFormat, "Connection ID", "Source", "Connection Name", "Destination", "Flow Files In", "Flow Files Out", "FlowFiles Queued");

    final StringBuilder connectionBorderBuilder = new StringBuilder(connectionHeader.length());
    for (int i = 0; i < connectionHeader.length(); i++) {
        connectionBorderBuilder.append('-');
    }
    connectionBorderLine = connectionBorderBuilder.toString();

    processorLineFormat = context.getProperty(SHOW_DELTAS).asBoolean() ? PROCESSOR_LINE_FORMAT_WITH_DELTA : PROCESSOR_LINE_FORMAT_NO_DELTA;
    processorHeader = String.format(processorLineFormat, "Processor Name", "Processor ID", "Processor Type", "Run Status", "Flow Files In",
            "Flow Files Out", "Bytes Read", "Bytes Written", "Tasks", "Proc Time");

    final StringBuilder processorBorderBuilder = new StringBuilder(processorHeader.length());
    for (int i = 0; i < processorHeader.length(); i++) {
        processorBorderBuilder.append('-');
    }
    processorBorderLine = processorBorderBuilder.toString();
}
 
Example #11
Source Project: localization_nifi   Author: wangrenlei   File: AttributeRollingWindow.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    timeWindow = context.getProperty(TIME_WINDOW).asTimePeriod(TimeUnit.MILLISECONDS);
    microBatchTime = context.getProperty(SUB_WINDOW_LENGTH).asTimePeriod(TimeUnit.MILLISECONDS);

    if(microBatchTime == null || microBatchTime == 0) {
        StateManager stateManager = context.getStateManager();
        StateMap state = stateManager.getState(SCOPE);
        HashMap<String, String> tempMap = new HashMap<>();
        tempMap.putAll(state.toMap());
        if (!tempMap.containsKey(COUNT_KEY)) {
            tempMap.put(COUNT_KEY, "0");
            context.getStateManager().setState(tempMap, SCOPE);
        }
    }
}
 
Example #12
Source Project: localization_nifi   Author: wangrenlei   File: GetHDFS.java    License: Apache License 2.0 6 votes vote down vote up
@OnScheduled
public void onScheduled(ProcessContext context) throws IOException {
    abstractOnScheduled(context);
    // copy configuration values to pass them around cleanly
    processorConfig = new ProcessorConfiguration(context);
    final FileSystem fs = getFileSystem();
    final Path dir = new Path(context.getProperty(DIRECTORY).evaluateAttributeExpressions().getValue());
    if (!fs.exists(dir)) {
        throw new IOException("PropertyDescriptor " + DIRECTORY + " has invalid value " + dir + ". The directory does not exist.");
    }

    // forget the state of the queue in case HDFS contents changed while this processor was turned off
    queueLock.lock();
    try {
        filePathQueue.clear();
        processing.clear();
    } finally {
        queueLock.unlock();
    }
}
 
Example #13
Source Project: localization_nifi   Author: wangrenlei   File: AbstractListenEventBatchingProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@OnScheduled
public void onScheduled(ProcessContext context) throws IOException {
    super.onScheduled(context);
    final String msgDemarcator = context.getProperty(MESSAGE_DELIMITER).getValue().replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t");
    messageDemarcatorBytes = msgDemarcator.getBytes(charset);
}
 
Example #14
Source Project: localization_nifi   Author: wangrenlei   File: GetAzureEventHub.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws ProcessException {
    final BlockingQueue<String> partitionNames = new LinkedBlockingQueue<>();
    for (int i = 0; i < context.getProperty(NUM_PARTITIONS).asInteger(); i++) {
        partitionNames.add(String.valueOf(i));
    }
    this.partitionNames = partitionNames;

    final String policyName = context.getProperty(ACCESS_POLICY).getValue();
    final String policyKey = context.getProperty(POLICY_PRIMARY_KEY).getValue();
    final String namespace = context.getProperty(NAMESPACE).getValue();
    final String eventHubName = context.getProperty(EVENT_HUB_NAME).getValue();

    if(context.getProperty(ENQUEUE_TIME).isSet()) {
        configuredEnqueueTime = Instant.parse(context.getProperty(ENQUEUE_TIME).toString());
    } else {
        configuredEnqueueTime = null;
    }
    if(context.getProperty(RECEIVER_FETCH_SIZE).isSet()) {
        receiverFetchSize = context.getProperty(RECEIVER_FETCH_SIZE).asInteger();
    } else {
        receiverFetchSize = 100;
    }
    if(context.getProperty(RECEIVER_FETCH_TIMEOUT).isSet()) {
        receiverFetchTimeout = Duration.ofMillis(context.getProperty(RECEIVER_FETCH_TIMEOUT).asLong());
    } else {
        receiverFetchTimeout = null;
    }

    final String connectionString = new ConnectionStringBuilder(namespace, eventHubName, policyName, policyKey).toString();
    setupReceiver(connectionString);
}
 
Example #15
Source Project: localization_nifi   Author: wangrenlei   File: ScriptedReportingTask.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Performs setup operations when the processor is scheduled to run. This includes evaluating the processor's
 * properties, as well as reloading the script (from file or the "Script Body" property)
 *
 * @param context the context in which to perform the setup operations
 */
@OnScheduled
public void setup(final ConfigurationContext context) {
    scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue());
    scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue());
    scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue());
    String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue();
    if (!StringUtils.isEmpty(modulePath)) {
        scriptingComponentHelper.setModules(modulePath.split(","));
    } else {
        scriptingComponentHelper.setModules(new String[0]);
    }
    // Create a script engine for each possible task
    scriptingComponentHelper.setup(1, getLogger());
    scriptToRun = scriptingComponentHelper.getScriptBody();

    try {
        String scriptPath = scriptingComponentHelper.getScriptPath();
        if (scriptToRun == null && scriptPath != null) {
            try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
                scriptToRun = IOUtils.toString(scriptStream, Charset.defaultCharset());
            }
        }
    } catch (IOException ioe) {
        throw new ProcessException(ioe);
    }

    vmMetrics = VirtualMachineMetrics.getInstance();
}
 
Example #16
Source Project: localization_nifi   Author: wangrenlei   File: SolrProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public final void onScheduled(final ProcessContext context) throws IOException {
    this.solrLocation =  context.getProperty(SOLR_LOCATION).evaluateAttributeExpressions().getValue();
    this.basicUsername = context.getProperty(BASIC_USERNAME).evaluateAttributeExpressions().getValue();
    this.basicPassword = context.getProperty(BASIC_PASSWORD).evaluateAttributeExpressions().getValue();
    if (!StringUtils.isBlank(basicUsername) && !StringUtils.isBlank(basicPassword)) {
        basicAuthEnabled = true;
    }
    this.solrClient = createSolrClient(context, solrLocation);
}
 
Example #17
Source Project: localization_nifi   Author: wangrenlei   File: SpringContextProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@OnScheduled
public void initializeSpringContext(ProcessContext processContext) {
    this.applicationContextConfigFileName = processContext.getProperty(CTX_CONFIG_PATH).getValue();
    this.applicationContextLibPath = processContext.getProperty(CTX_LIB_PATH).getValue();

    String stStr = processContext.getProperty(SEND_TIMEOUT).getValue();
    this.sendTimeout = stStr == null ? 0 : FormatUtils.getTimeDuration(stStr, TimeUnit.MILLISECONDS);

    String rtStr = processContext.getProperty(RECEIVE_TIMEOUT).getValue();
    this.receiveTimeout = rtStr == null ? 0 : FormatUtils.getTimeDuration(rtStr, TimeUnit.MILLISECONDS);

    try {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Initializing Spring Application Context defined in " + this.applicationContextConfigFileName);
        }
        this.exchanger = SpringContextFactory.createSpringContextDelegate(this.applicationContextLibPath,
                this.applicationContextConfigFileName);
    } catch (Exception e) {
        throw new IllegalStateException("Failed while initializing Spring Application Context", e);
    }
    if (logger.isInfoEnabled()) {
        logger.info("Successfully initialized Spring Application Context defined in "
                + this.applicationContextConfigFileName);
    }
}
 
Example #18
Source Project: localization_nifi   Author: wangrenlei   File: PutSQS.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(final ProcessContext context) {
    userDefinedProperties = new ArrayList<>();
    for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
        if (descriptor.isDynamic()) {
            userDefinedProperties.add(descriptor);
        }
    }
}
 
Example #19
Source Project: localization_nifi   Author: wangrenlei   File: TestStandardProcessScheduler.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled() {
    onScheduleAttempts.incrementAndGet();

    if (failOnScheduled.get()) {
        throw new RuntimeException("Intentional Exception for testing purposes");
    }
}
 
Example #20
Source Project: localization_nifi   Author: wangrenlei   File: TestProcessorLifecycle.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void schedule(ProcessContext ctx) {
    this.operationNames.add("@OnScheduled");
    if (this.generateExceptionOnScheduled
            && this.onScheduledExceptionCount++ < this.keepFailingOnScheduledTimes) {
        throw new RuntimeException("Intentional");
    }
    this.onScheduleCallback.run();
}
 
Example #21
Source Project: localization_nifi   Author: wangrenlei   File: ListenBeats.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@OnScheduled
public void onScheduled(ProcessContext context) throws IOException {
    super.onScheduled(context);
    // wanted to ensure charset was already populated here
    beatsEncoder = new BeatsEncoder();
}
 
Example #22
Source Project: localization_nifi   Author: wangrenlei   File: ScanAttribute.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    final String filterRegex = context.getProperty(DICTIONARY_FILTER).getValue();
    this.dictionaryFilterPattern = (filterRegex == null) ? null : Pattern.compile(filterRegex);

    final String attributeRegex = context.getProperty(ATTRIBUTE_PATTERN).getValue();
    this.attributePattern = (attributeRegex.equals(".*")) ? null : Pattern.compile(attributeRegex);

    this.dictionaryTerms = createDictionary(context);
    this.fileWatcher = new SynchronousFileWatcher(Paths.get(context.getProperty(DICTIONARY_FILE).getValue()), new LastModifiedMonitor(), 1000L);
}
 
Example #23
Source Project: localization_nifi   Author: wangrenlei   File: GetHTTP.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    if (clearState.getAndSet(false)) {
        context.getStateManager().clear(Scope.LOCAL);
    }
    if (customHeaders.size() == 0) {
        for (Map.Entry<PropertyDescriptor, String> property : context.getProperties().entrySet()) {
            // only add the custom defined Headers (i.e. dynamic properties)
            if (!getSupportedPropertyDescriptors().contains(property.getKey())) {
                customHeaders.add(property.getKey());
            }
        }
    }
}
 
Example #24
Source Project: localization_nifi   Author: wangrenlei   File: AbstractAWSCredentialsProviderProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method checks if {#link {@link #AWS_CREDENTIALS_PROVIDER_SERVICE} is available and if it
 * is, uses the credentials provider, otherwise it invokes the {@link AbstractAWSProcessor#onScheduled(ProcessContext)}
 * which uses static AWSCredentials for the aws processors
 */
@OnScheduled
public void onScheduled(ProcessContext context) {
    ControllerService service = context.getProperty(AWS_CREDENTIALS_PROVIDER_SERVICE).asControllerService();
    if (service != null) {
        getLogger().debug("Using aws credentials provider service for creating client");
        onScheduledUsingControllerService(context);
    } else {
        getLogger().debug("Using aws credentials for creating client");
        super.onScheduled(context);
    }
}
 
Example #25
Source Project: localization_nifi   Author: wangrenlei   File: SplitContent.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void initializeByteSequence(final ProcessContext context) throws DecoderException {
    final String bytePattern = context.getProperty(BYTE_SEQUENCE).getValue();

    final String format = context.getProperty(FORMAT).getValue();
    if (HEX_FORMAT.getValue().equals(format)) {
        this.byteSequence.set(Hex.decodeHex(bytePattern.toCharArray()));
    } else {
        this.byteSequence.set(bytePattern.getBytes(StandardCharsets.UTF_8));
    }
}
 
Example #26
Source Project: localization_nifi   Author: wangrenlei   File: GetFileTransfer.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) {
    listingLock.lock();
    try {
        final BlockingQueue<FileInfo> fileQueue = fileQueueRef.get();
        if (fileQueue != null) {
            fileQueue.clear();
        }
        fileQueueRef.set(null); // create new queue on next listing, in case queue type needs to change
    } finally {
        listingLock.unlock();
    }
}
 
Example #27
Source Project: localization_nifi   Author: wangrenlei   File: GenerateTableFetch.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(final ProcessContext context) {
    // Pre-fetch the column types if using a static table name and max-value columns
    if (!isDynamicTableName && !isDynamicMaxValues) {
        super.setup(context);
    }
}
 
Example #28
Source Project: localization_nifi   Author: wangrenlei   File: TransformCSVToJson.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
@OnScheduled
public void onScheduled(ProcessContext context) {
    super.onScheduled(context);
    this.quoteChar = context.getProperty(QUOTE).getValue().charAt(0);
}
 
Example #29
Source Project: localization_nifi   Author: wangrenlei   File: ValidateCsv.java    License: Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setPreference(final ProcessContext context) {
    // When going from the UI to Java, the characters are escaped so that what you
    // input is transferred over to Java as is. So when you type the characters "\"
    // and "n" into the UI the Java string will end up being those two characters
    // not the interpreted value "\n".
    final String msgDemarcator = context.getProperty(END_OF_LINE_CHARACTER).getValue().replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t");
    this.preference.set(new CsvPreference.Builder(context.getProperty(QUOTE_CHARACTER).getValue().charAt(0),
            context.getProperty(DELIMITER_CHARACTER).getValue().charAt(0), msgDemarcator).build());
}
 
Example #30
Source Project: localization_nifi   Author: wangrenlei   File: ConsumeWindowsEventLogTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = ProcessException.class)
public void testScheduleQueueStopThrowsException() throws Throwable {
    ReflectionUtils.invokeMethodsWithAnnotation(OnScheduled.class, evtSubscribe, testRunner.getProcessContext());

    WinNT.HANDLE handle = mockEventHandles(wEvtApi, kernel32, Arrays.asList("test")).get(0);
    getRenderingCallback().onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER, null, handle);

    try {
        ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, evtSubscribe, testRunner.getProcessContext());
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}