當前位置: 首頁>>代碼示例>>Java>>正文


Java FlowFile類代碼示例

本文整理匯總了Java中org.apache.nifi.flowfile.FlowFile的典型用法代碼示例。如果您正苦於以下問題:Java FlowFile類的具體用法?Java FlowFile怎麽用?Java FlowFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FlowFile類屬於org.apache.nifi.flowfile包,在下文中一共展示了FlowFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
    FlowFile original = session.get();

    FlowFile flowFile;
    if (original == null) {
        flowFile = session.create();
        session.getProvenanceReporter().create(flowFile);
    } else {
        flowFile = session.clone(original);
        session.transfer(original, REL_ORIGINAL);
    }

    final String updatedContent = StringFormatter.format(context.getProperty(CONTENT_FIELD).getValue(), flowFile.getAttributes());
    this.getLogger().debug("Created content: {}", new Object[]{updatedContent});

    flowFile = session.write(flowFile, outputStream -> outputStream.write(updatedContent.getBytes(StandardCharsets.UTF_8)));
    session.getProvenanceReporter().modifyContent(flowFile);
    session.transfer(flowFile, REL_SUCCESS);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:21,代碼來源:CreateContent.java

示例2: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
  final ProcessorLog log = this.getLogger();
  final AtomicReference<String> value = new AtomicReference<>();
  final Map<String, String> tessProperties = toProperties(context.getProperty(TESS_PROPERTIES).getValue());
  final File tessDataDir = new File(context.getProperty(TESS_DATA).getValue());
  System.getProperties().setProperty("jna.library.path", context.getProperty(JNI_PATH).getValue());
  FlowFile flowfile = session.get();
  if (null != flowfile) {
    session.read(flowfile, in -> {
      try {
        value.set(TesseractUtil.INSTANCE.ocr(in, tessDataDir, tessProperties));
      } catch (Exception e) {
        log.error("Unable to ocr: " + e.getMessage(), e);
      }
    });

    flowfile = session.write(flowfile, out -> {
      out.write(value.get().getBytes());
      out.flush();
    });
    session.transfer(flowfile, SUCCESS);
  } else {
    log.warn("NULL flow file");
  }
}
 
開發者ID:mmiklavc,項目名稱:scalable-ocr,代碼行數:27,代碼來源:ExtractionProcessor.java

示例3: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {

    FlowFile flowfile = session.get();
    OutputStream outputStream = new ByteArrayOutputStream();
    Path path = FileSystems.getDefault().getPath("/tmp","nifi.file");
    session.exportTo(flowfile, path, false);

    String batchID = flowfile.getAttribute("batchID");
    String dbName = context.getProperty(DB_NAME).getValue();
    writeImageToDatabase(batchID, path, dbName);
    // session.
    // put the flowfile into the db
    int count = 0;
    if (batchCounterMap.containsKey(batchID))
        count = batchCounterMap.get(batchID);
    batchCounterMap.put(batchID, ++count);

    if (count >= Integer.parseInt(context.getProperty(BATCH_SIZE).getValue())) {
        session.transfer(flowfile, REL_SUCCESS);
        batchCounterMap.remove(batchID);
    } else
        session.remove(flowfile);

    session.commit();
}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:27,代碼來源:PutToSQL.java

示例4: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {

    FlowFile flowfile = session.get();
    String batchID = flowfile.getAttribute("batchID");
    String dbName = context.getProperty(DB_NAME).getValue();
    ArrayList<Path> paths = getFilePaths(batchID, dbName);
    // loop through paths and send flowfiles
    for (Path path : paths) {
        FlowFile newFlowfile = session.create();
        session.importFrom(path, true, newFlowfile);
        session.putAttribute(newFlowfile, "batchID", batchID);
        session.transfer(flowfile, REL_SUCCESS);
    }
    session.commit();

}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:18,代碼來源:JoinFromSQL.java

示例5: rendezvousWithJms

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
/**
 * Will construct JMS {@link Message} by extracting its body from the
 * incoming {@link FlowFile}. {@link FlowFile} attributes that represent
 * standard JMS headers will be extracted from the {@link FlowFile} and set
 * as JMS headers on the newly constructed message. For the list of
 * available message headers please see {@link JmsHeaders}. <br>
 * <br>
 * Upon success the incoming {@link FlowFile} is transferred to the'success'
 * {@link Relationship} and upon failure FlowFile is penalized and
 * transferred to the 'failure' {@link Relationship}
 *
 */
@Override
protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession) throws ProcessException {
    FlowFile flowFile = processSession.get();
    if (flowFile != null) {
        try {
            String destinationName = context.getProperty(DESTINATION).evaluateAttributeExpressions(flowFile).getValue();
            this.targetResource.publish(destinationName, this.extractMessageBody(flowFile, processSession), flowFile.getAttributes());
            processSession.transfer(flowFile, REL_SUCCESS);
            processSession.getProvenanceReporter().send(flowFile, context.getProperty(DESTINATION).evaluateAttributeExpressions().getValue());
        } catch (Exception e) {
            processSession.transfer(flowFile, REL_FAILURE);
            this.getLogger().error("Failed while sending message to JMS via " + this.targetResource, e);
            context.yield();
        }
    }
}
 
開發者ID:lsac,項目名稱:nifi-jms-jndi,代碼行數:29,代碼來源:PublishJMS.java

示例6: createPut

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
protected PutFlowFile createPut(final ProcessSession session, final ProcessContext context, final FlowFile flowFile) {
    final String tableName = context.getProperty(TABLE_NAME).evaluateAttributeExpressions(flowFile).getValue();
    final String row = context.getProperty(ROW_ID).evaluateAttributeExpressions(flowFile).getValue();
    final String columnFamily = context.getProperty(COLUMN_FAMILY).evaluateAttributeExpressions(flowFile).getValue();
    final String columnQualifier = context.getProperty(COLUMN_QUALIFIER).evaluateAttributeExpressions(flowFile).getValue();
    final String columnVisibility = context.getProperty(COLUMN_VISIBILITY).evaluateAttributeExpressions(flowFile).getValue();

    final byte[] buffer = new byte[(int) flowFile.getSize()];
    session.read(flowFile, new InputStreamCallback() {
        @Override
        public void process(final InputStream in) throws IOException {
            StreamUtils.fillBuffer(in, buffer);
        }
    });

    final Collection<PutMutation> mutations = Collections.singletonList(new PutMutation(columnFamily, columnQualifier, columnVisibility, buffer.toString()));
    return new PutFlowFile(tableName, row, mutations, flowFile);
}
 
開發者ID:pinkdevelops,項目名稱:nifi-accumulo-bundle,代碼行數:20,代碼來源:PutAccumuloCell.java

示例7: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    ComponentLog logger = getLogger();
    FlowFile flowFile = session.get();

    // Create the flowfile, as it probably does not exist
    if (flowFile == null)
        flowFile = session.create();

    // Get the data
    String data = generateData(context.getProperty(PRINT_HEADER).asBoolean(), context.getProperty(LONG_TIMESTAMP).asBoolean(), context.getProperty(TIMEZONE).toString(), context.getProperty(DATA_FORMAT).getValue());

    // Write the results back out to flow file
    try{
        flowFile = session.write(flowFile, out -> out.write(data.getBytes()));
        session.getProvenanceReporter().create(flowFile);
        session.transfer(flowFile, SUCCESS);
    } catch (ProcessException ex) {
        logger.error("Unable to write generated data out to flowfile. Error: ", ex);
    }
}
 
開發者ID:hashmapinc,項目名稱:nifi-simulator-bundle,代碼行數:22,代碼來源:GenerateTimeSeriesFlowFile.java

示例8: ensureDirectoryExists

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void ensureDirectoryExists(final FlowFile flowFile, final File directoryName) throws IOException {
    if (directoryName.getParent() != null && !directoryName.getParentFile().equals(new File(File.separator))) {
        ensureDirectoryExists(flowFile, directoryName.getParentFile());
    }

    final String remoteDirectory = directoryName.getAbsolutePath().replace("\\", "/").replaceAll("^.\\:", "");
    final FTPClient client = getClient(flowFile);
    final boolean cdSuccessful = setWorkingDirectory(remoteDirectory);

    if (!cdSuccessful) {
        logger.debug("Remote Directory {} does not exist; creating it", new Object[] {remoteDirectory});
        if (client.makeDirectory(remoteDirectory)) {
            logger.debug("Created {}", new Object[] {remoteDirectory});
        } else {
            throw new IOException("Failed to create remote directory " + remoteDirectory);
        }
    }
}
 
開發者ID:clickha,項目名稱:nifi-tools,代碼行數:20,代碼來源:FTPTransferV2.java

示例9: sendCommands

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
public void sendCommands(final List<String> commands, final FlowFile flowFile) throws IOException {
    if (commands.isEmpty()) {
        return;
    }

    final FTPClient client = getClient(flowFile);
    for (String cmd : commands) {
        if (!cmd.isEmpty()) {
            int result;
            result = client.sendCommand(cmd);
            logger.debug(this + " sent command to the FTP server: " + cmd + " for " + flowFile);

            if (FTPReply.isNegativePermanent(result) || FTPReply.isNegativeTransient(result)) {
                throw new IOException(this + " negative reply back from FTP server cmd: " + cmd + " reply:" + result + ": " + client.getReplyString() + " for " + flowFile);
            }
        }
    }
}
 
開發者ID:clickha,項目名稱:nifi-tools,代碼行數:19,代碼來源:FTPTransferV2.java

示例10: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
    DesiredCapabilities DesireCaps = new DesiredCapabilities();
    DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, context.getProperty(DRIVER_LOCATION).getValue());
    driver = new PhantomJSDriver(DesireCaps);
    FlowFile flowFile = session.create();
    try {
        driver.get(url);
        (new WebDriverWait(driver, timeout)).until(
                ExpectedConditions.visibilityOfElementLocated(getExpectedCondition(selectorType, selector))
        );

        final byte[] page = formatToXHtml(driver.getPageSource(), StandardCharsets.UTF_8);
        flowFile = session.write(flowFile, outputStream -> outputStream.write(page));
        session.transfer(flowFile, REL_SUCCESS);
    } catch (Exception e) {
        flowFile = session.write(flowFile, outputStream -> outputStream.write(e.getMessage().getBytes()));
        session.transfer(flowFile, REL_FAILURE);
    } finally {
        driver.quit();
    }
    session.getProvenanceReporter().create(flowFile);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:24,代碼來源:GetWebpage.java

示例11: sendStatsIfPresent

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
/**
 * Send a flowfile with the stats as attributes: IF the report time is exceeded AND there are
 * stats to send
 */
private void sendStatsIfPresent(ProcessSession session, long currentTimestamp) {
    if (currentTimestamp < lastReportTime + reportingIntervalMillis) {
        return;
    }

    for (Map.Entry<String, Optional<Map<String, String>>> statsMap : latestStats.entrySet()) {

        String statsMapKey = statsMap.getKey();
        Optional<Map<String, String>> result = buildStatAttributes(currentTimestamp, momentsMap.get(statsMapKey));
        if (result.isPresent()) {
            Map<String, String> attrs = new HashMap<>(result.get());
            attrs.put("AbstractStatsProcessor.correlationKey", statsMapKey);
            String uuid = UUID.randomUUID().toString();
            attrs.put(CoreAttributes.UUID.key(), uuid);
            attrs.put(CoreAttributes.FILENAME.key(), statsMapKey + "_" + System.currentTimeMillis() + "_" + uuid);
            FlowFile statsFlowFile = session.create();
            statsFlowFile = session.putAllAttributes(statsFlowFile, attrs);
            session.getProvenanceReporter().create(statsFlowFile);
            session.transfer(statsFlowFile, REL_STATS);
        }
    }
    lastReportTime = currentTimestamp;
    momentsMap.values().forEach(MomentAggregator::reset);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:29,代碼來源:AbstractStatsProcessor.java

示例12: onTrigger

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    List<FlowFile> incoming = session.get(batchSize);
    if (incoming.isEmpty()) {
        return;
    }

    /*
        Each relationship can have multiple connections.
        context.getAvailableRelationships().contains(PASS_THROUGH) will return true if all
        PASS_THROUGH connections are available (not back pressured). So if a PASS_THROUGH
        relationship has 2 connections with back pressure of 10 and 20 and only the 10's
        connection is back pressured, contains(PASS_THROUGH) will return false
     */
    final boolean isPassthroughClear = context.getAvailableRelationships().contains(PASS_THROUGH);
    session.transfer(incoming, isPassthroughClear ? PASS_THROUGH : BACK_PRESSURED);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:18,代碼來源:RouteOnBackPressure.java

示例13: payloadWithSubstitutions

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Test
public void payloadWithSubstitutions() {

    String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"boolean\": {{boolean}}}";
    final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
    runner.setProperty(CreateContent.CONTENT_FIELD, payload);

    ProcessSession session = runner.getProcessSessionFactory().createSession();
    FlowFile ff = session.create();
    Map<String, String> props = new HashMap<>();
    props.put("from", "\"[email protected]\"");
    props.put("pi", "3.14");
    props.put("boolean", "true");
    ff = session.putAllAttributes(ff, props);
    runner.enqueue(ff);
    runner.run();

    runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
    runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
    runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);

    String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"boolean\": true}";
    final MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
    assertEquals(expected, new String(out.toByteArray()));
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:26,代碼來源:CreateContentTest.java

示例14: payloadWithMissingAttributes

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Test
public void payloadWithMissingAttributes() {

    String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"boolean\": {{boolean}}}";
    final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
    runner.setProperty(CreateContent.CONTENT_FIELD, payload);

    ProcessSession session = runner.getProcessSessionFactory().createSession();
    FlowFile ff = session.create();
    Map<String, String> props = new HashMap<>();
    props.put("from", "\"[email protected]\"");
    props.put("pi", "3.14");
    ff = session.putAllAttributes(ff, props);
    runner.enqueue(ff);
    runner.run();

    runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
    runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
    runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);

    String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"boolean\": null}";
    MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
    String actual = new String(out.toByteArray());
    assertEquals(expected, actual);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:26,代碼來源:CreateContentTest.java

示例15: payloadWithTokenAttributes

import org.apache.nifi.flowfile.FlowFile; //導入依賴的package包/類
@Test
public void payloadWithTokenAttributes() {

    String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
    final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
    runner.setProperty(CreateContent.CONTENT_FIELD, payload);

    ProcessSession session = runner.getProcessSessionFactory().createSession();
    FlowFile ff = session.create();
    Map<String, String> props = new HashMap<>();
    props.put("from", "\"[email protected]\"");
    props.put("pi", "3.14");
    props.put("text", "\"here is some {{text}}\"");
    ff = session.putAllAttributes(ff, props);
    runner.enqueue(ff);
    runner.run();

    runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
    runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
    runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);

    String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some {{text}}\"}";
    MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
    String actual = new String(out.toByteArray());
    assertEquals(expected, actual);
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:27,代碼來源:CreateContentTest.java


注:本文中的org.apache.nifi.flowfile.FlowFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。