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

The following examples show how to use org.apache.nifi.annotation.lifecycle.OnScheduled. 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: TransformXml.java    From localization_nifi with Apache License 2.0 7 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 #2
Source File: ExecuteFlumeSink.java    From localization_nifi with 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 #3
Source File: BinFiles.java    From localization_nifi with 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 #4
Source File: GetTCP.java    From localization_nifi with 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 #5
Source File: AbstractListenEventProcessor.java    From localization_nifi with 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 #6
Source File: ExecuteFlumeSource.java    From localization_nifi with 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 #7
Source File: PutAzureEventHub.java    From localization_nifi with 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 #8
Source File: RouteText.java    From localization_nifi with 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 #9
Source File: ExecuteScript.java    From localization_nifi with 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 #10
Source File: GetHDFS.java    From localization_nifi with 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 #11
Source File: ControllerStatusReportingTask.java    From localization_nifi with 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 #12
Source File: AttributeRollingWindow.java    From localization_nifi with 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 #13
Source File: DataDogReportingTask.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(final ConfigurationContext context) {
    metricsService = getMetricsService();
    ddMetricRegistryBuilder = getMetricRegistryBuilder();
    metricRegistry = getMetricRegistry();
    metricsMap = getMetricsMap();
    metricsPrefix = METRICS_PREFIX.getDefaultValue();
    environment = ENVIRONMENT.getDefaultValue();
    virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    ddMetricRegistryBuilder.setMetricRegistry(metricRegistry)
            .setTags(metricsService.getAllTagsList());
}
 
Example #14
Source File: RouteOnAttribute.java    From localization_nifi with Apache License 2.0 5 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 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 #15
Source File: UpdateAttribute.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    criteriaCache.set(CriteriaSerDe.deserialize(context.getAnnotationData()));

    propertyValues.clear();

    if(stateful) {
        StateManager stateManager = context.getStateManager();
        StateMap state = stateManager.getState(Scope.LOCAL);
        HashMap<String, String> tempMap = new HashMap<>();
        tempMap.putAll(state.toMap());
        String initValue = context.getProperty(STATEFUL_VARIABLES_INIT_VALUE).getValue();

        // Initialize the stateful default actions
        for (PropertyDescriptor entry : context.getProperties().keySet()) {
            if (entry.isDynamic()) {
                if(!tempMap.containsKey(entry.getName())) {
                    tempMap.put(entry.getName(), initValue);
                }
            }
        }

        // Initialize the stateful actions if the criteria exists
        final Criteria criteria = criteriaCache.get();
        if (criteria != null) {
            for (Rule rule : criteria.getRules()) {
                for (Action action : rule.getActions()) {
                    if (!tempMap.containsKey(action.getAttribute())) {
                        tempMap.put(action.getAttribute(), initValue);
                    }
                }
            }
        }

        context.getStateManager().setState(tempMap, Scope.LOCAL);
    }

    defaultActions = getDefaultActions(context.getProperties());
    debugEnabled = getLogger().isDebugEnabled();
}
 
Example #16
Source File: ConvertAvroToORC.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(ProcessContext context) {
    boolean confFileProvided = context.getProperty(ORC_CONFIGURATION_RESOURCES).isSet();
    if (confFileProvided) {
        final String configFiles = context.getProperty(ORC_CONFIGURATION_RESOURCES).getValue();
        orcConfig = HiveJdbcCommon.getConfigurationFromFiles(configFiles);
    }
}
 
Example #17
Source File: SelectHiveQL.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(ProcessContext context) {
    // If the query is not set, then an incoming flow file is needed. Otherwise fail the initialization
    if (!context.getProperty(HIVEQL_SELECT_QUERY).isSet() && !context.hasIncomingConnection()) {
        final String errorString = "Either the Select Query must be specified or there must be an incoming connection "
                + "providing flowfile(s) containing a SQL select query";
        getLogger().error(errorString);
        throw new ProcessException(errorString);
    }
}
 
Example #18
Source File: ConsumeMQTT.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException, ClassNotFoundException {
    qos = context.getProperty(PROP_QOS).asInteger();
    maxQueueSize = context.getProperty(PROP_MAX_QUEUE_SIZE).asLong();
    topicFilter = context.getProperty(PROP_TOPIC_FILTER).getValue();

    buildClient(context);
    scheduled.set(true);
}
 
Example #19
Source File: PutHDFS.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(ProcessContext context) throws Exception {
    super.abstractOnScheduled(context);

    // Set umask once, to avoid thread safety issues doing it in onTrigger
    final PropertyValue umaskProp = context.getProperty(UMASK);
    final short dfsUmask;
    if (umaskProp.isSet()) {
        dfsUmask = Short.parseShort(umaskProp.getValue(), 8);
    } else {
        dfsUmask = FsPermission.DEFAULT_UMASK;
    }
    final Configuration conf = getConfiguration();
    FsPermission.setUMask(conf, new FsPermission(dfsUmask));
}
 
Example #20
Source File: UnpackContent.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(ProcessContext context) throws ProcessException {
    if (fileFilter == null) {
        fileFilter = Pattern.compile(context.getProperty(FILE_FILTER).getValue());
        tarUnpacker = new TarUnpacker(fileFilter);
        zipUnpacker = new ZipUnpacker(fileFilter);
    }
}
 
Example #21
Source File: MonitorMemory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onConfigured(final ConfigurationContext config) throws InitializationException {
    final String desiredMemoryPoolName = config.getProperty(MEMORY_POOL_PROPERTY).getValue();
    final String thresholdValue = config.getProperty(THRESHOLD_PROPERTY).getValue().trim();
    threshold = thresholdValue;

    final Long reportingIntervalValue = config.getProperty(REPORTING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    if (reportingIntervalValue == null) {
        reportingIntervalMillis = config.getSchedulingPeriod(TimeUnit.MILLISECONDS);
    } else {
        reportingIntervalMillis = reportingIntervalValue;
    }

    final List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (int i = 0; i < memoryPoolBeans.size() && monitoredBean == null; i++) {
        MemoryPoolMXBean memoryPoolBean = memoryPoolBeans.get(i);
        String memoryPoolName = memoryPoolBean.getName();
        if (desiredMemoryPoolName.equals(memoryPoolName)) {
            monitoredBean = memoryPoolBean;
            if (memoryPoolBean.isCollectionUsageThresholdSupported()) {
                long calculatedThreshold;
                if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
                    calculatedThreshold = DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
                } else {
                    final String percentage = thresholdValue.substring(0, thresholdValue.length() - 1);
                    final double pct = Double.parseDouble(percentage) / 100D;
                    calculatedThreshold = (long) (monitoredBean.getUsage().getMax() * pct);
                }
                monitoredBean.setUsageThreshold(calculatedThreshold);
            }
        }
    }

    if (monitoredBean == null) {
        throw new InitializationException("Found no JVM Memory Pool with name " + desiredMemoryPoolName + "; will not monitor Memory Pool");
    }
}
 
Example #22
Source File: AbstractListProcessor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public final void updateState(final ProcessContext context) throws IOException {
    final String path = getPath(context);
    final DistributedMapCacheClient client = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(DistributedMapCacheClient.class);

    // Check if state already exists for this path. If so, we have already migrated the state.
    final StateMap stateMap = context.getStateManager().getState(getStateScope(context));
    if (stateMap.getVersion() == -1L) {
        try {
            // Migrate state from the old way of managing state (distributed cache service and local file)
            // to the new mechanism (State Manager).
            migrateState(path, client, context.getStateManager(), getStateScope(context));
        } catch (final IOException ioe) {
            throw new IOException("Failed to properly migrate state to State Manager", ioe);
        }
    }

    // When scheduled to run, check if the associated timestamp is null, signifying a clearing of state and reset the internal timestamp
    if (lastListingTime != null && stateMap.get(LISTING_TIMESTAMP_KEY) == null) {
        getLogger().info("Detected that state was cleared for this component.  Resetting internal values.");
        resetTimeStates();
    }

    if (resetState) {
        context.getStateManager().clear(getStateScope(context));
        resetState = false;
    }
}
 
Example #23
Source File: BaseTransformer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(ProcessContext context) {
    List<PropertyDescriptor> propertyDescriptors = this.getSupportedPropertyDescriptors();
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        if (!propertyDescriptor.isExpressionLanguageSupported()){
            this.propertyInstanceValues.put(propertyDescriptor, context.getProperty(propertyDescriptor).getValue());
        }
    }
}
 
Example #24
Source File: EvaluateJsonPath.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(ProcessContext processContext) {
    representationOption = processContext.getProperty(NULL_VALUE_DEFAULT_REPRESENTATION).getValue();
    destinationIsAttribute = DESTINATION_ATTRIBUTE.equals(processContext.getProperty(DESTINATION).getValue());
    returnType = processContext.getProperty(RETURN_TYPE).getValue();
    if (returnType.equals(RETURN_TYPE_AUTO)) {
        returnType = destinationIsAttribute ? RETURN_TYPE_SCALAR : RETURN_TYPE_JSON;
    }
    pathNotFound = processContext.getProperty(PATH_NOT_FOUND).getValue();
    nullDefaultValue = NULL_REPRESENTATION_MAP.get(representationOption);
}
 
Example #25
Source File: ListenRELP.java    From localization_nifi with 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
    relpEncoder = new RELPEncoder(charset);
}
 
Example #26
Source File: ConsumeWindowsEventLogTest.java    From localization_nifi with 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();
    }
}
 
Example #27
Source File: ValidateCsv.java    From localization_nifi with 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 #28
Source File: TransformCSVToJson.java    From localization_nifi with 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 File: GenerateTableFetch.java    From localization_nifi with 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 #30
Source File: SplitContent.java    From localization_nifi with 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));
    }
}