当前位置: 首页>>代码示例>>Java>>正文


Java ProcessSession.transfer方法代码示例

本文整理汇总了Java中org.apache.nifi.processor.ProcessSession.transfer方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessSession.transfer方法的具体用法?Java ProcessSession.transfer怎么用?Java ProcessSession.transfer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.nifi.processor.ProcessSession的用法示例。


在下文中一共展示了ProcessSession.transfer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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.processor.ProcessSession; //导入方法依赖的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: rendezvousWithJms

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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

示例4: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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

示例5: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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

示例6: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext ctx, ProcessSession session) throws ProcessException {

    FlowFile flowFile = session.get();

    if (flowFile == null) {
        return;
    }

    final DelegatedAuthorizationProviderService authProviderSvc = ctx.getProperty(AUTHORIZATION_PROVIDER_SERVICE_PROP).asControllerService(DelegatedAuthorizationProviderService.class);
    final String tokenValueAttribute = ctx.getProperty(TOKEN_ATTRIBUTE_NAME_PROP).getValue();

    final String tokenValue = flowFile.getAttribute(tokenValueAttribute);
    if (StringUtils.isEmpty(tokenValue)) {
        session.transfer(flowFile, UNAUTHORIZED_REL);
        return;
    }

    session.adjustCounter(tokenValue, 1, false);

    final AuthorizationToken authorizationToken = new StandardAuthorizationToken(tokenValue);
    final Set<AuthorizationToken> authorizationTokens = authProviderSvc.getAuthorizationTokens();

    session.transfer(flowFile, authorizationTokens.contains(authorizationToken) ? AUTHORIZED_REL : UNAUTHORIZED_REL);
}
 
开发者ID:apiri,项目名称:nifi-delegated-authorization-bundle,代码行数:26,代码来源:AuthorizeOnAttribute.java

示例7: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
	// TODO Auto-generated method stub
	FlowFile flowfile = session.get();
       
    flowfile = session.putAttribute(flowfile, "Directory", "/home/sivaprakash/Siva/Edgent/NifiTestout");  
    session.transfer(flowfile,REL_SUCCESS);
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:9,代码来源:Update.java

示例8: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
	public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
		// TODO Auto-generated method stub
		FlowFile flowfile = session.get();
		Map<String,String> attr =flowfile.getAttributes();
		String batchID = flowfile.getAttribute("batchID");
		if(attr.containsKey("fromEdgent")) {
			//String imageId = flowfile.getAttribute("imageID");
			if(batchMap.containsKey(batchID)) {
				session.transfer(flowfile, REL_SUCCESS);
				batchMap.put(batchID, "");
			} else {
				session.remove(flowfile);
            }
		}
		else {
            batchMap.put(batchID, "");
            session.remove(flowfile);
        }
        session.commit();
//		else
//		{
//			String url = flowfile.getAttribute("URL");
//			urlMap.put(batchID,url);
//			if(imageMap.containsKey(batchID)) {
//				flowfile = session.putAttribute(flowfile, "imageID",imageMap.get(batchID));
//				session.transfer(flowfile, REL_SUCCESS);
//				imageMap.remove(batchID);
//				batchMap.put(batchID, "");
//			}
//			else
//				session.remove(flowfile);
//		}
	}
 
开发者ID:dream-lab,项目名称:echo,代码行数:35,代码来源:JoinTF.java

示例9: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
	FlowFile flowFile = session.get();
	if (flowFile == null) {
		flowFile = session.create();
	}
	try {
		flowFile.getAttributes();
		flowFile = session.putAttribute(flowFile, "mime.type", "application/json");
		flowFile = session.write(flowFile, new StreamCallback() {
			@Override
			public void process(InputStream inputStream, OutputStream outputStream) throws IOException {
				Tika tika = new Tika();
				String text = "";
				try {
					text = tika.parseToString(inputStream);
				} catch (TikaException e) {
					getLogger().error("Apache Tika failed to parse input " + e.getLocalizedMessage());
					e.printStackTrace();
				}
				// TODO: wrap in JSON???
				outputStream.write(text.getBytes());
			}
		});
		session.transfer(flowFile, REL_SUCCESS);
		session.commit();
	} catch (final Throwable t) {
		getLogger().error("Unable to process ExtractTextProcessor file " + t.getLocalizedMessage());
		getLogger().error("{} failed to process due to {}; rolling back session", new Object[] { this, t });
		throw t;
	}
}
 
开发者ID:tspannhw,项目名称:nifi-extracttext-processor,代码行数:33,代码来源:ExtractTextProcessor.java

示例10: transferFlowFiles

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
protected void transferFlowFiles(ProcessSession session, List<FlowFile> flowFilesAttemptedUpdate, Map<Integer, BulkWriteError> writeErrors) {

        ComponentLog logger = this.getLogger();

        if (!writeErrors.isEmpty()) {
            logger.debug("Encountered errors on write");
            /*
             * For each Bulk Updated Document, see if it encountered an error.
             * If it had an error (based on index in the list), add the Mongo
             * Error to the FlowFile attribute and route to Failure. Otherwise,
             * route to Success
             */
            for (int i = 0; i < flowFilesAttemptedUpdate.size(); i++) {
                FlowFile ff = flowFilesAttemptedUpdate.get(i);
                if (writeErrors.containsKey(i)) {

                    logger.debug("Found error for FlowFile index {}", new Object[]{i});

                    // Add the error information to the FlowFileAttributes, and
                    // route to failure
                    BulkWriteError bwe = writeErrors.get(i);

                    logger.debug("FlowFile ID {} had Error Code {} and Message {}", new Object[]{ff.getId(), bwe.getCode(), bwe.getMessage()});

                    Map<String, String> failureAttributes = getAttributesForWriteFailure(bwe);
                    ff = session.putAllAttributes(ff, failureAttributes);

                    session.transfer(ff, REL_FAILURE);
                } else {
                    logger.debug("Routing FlowFile ID {} with Index {} to Success", new Object[]{ff.getId(), i});
                    // Flow File did not have error, so route to success
                    session.transfer(ff, REL_SUCCESS);
                }
            }
        } else {
            logger.debug("No errors encountered on bulk write, so routing all to success");
            // All succeeded, so write all to success
            session.transfer(flowFilesAttemptedUpdate, REL_SUCCESS);
        }
    }
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:41,代码来源:UpdateMongo.java

示例11: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
	FlowFile flowFile = session.get();
	if (flowFile == null) {
		flowFile = session.create();
	}
	try {
		Map<String, String> attributes = flowFile.getAttributes();
		Map<String, String> attributesClean = new HashMap<>();
		String tempKey = "";
		
		for (Map.Entry<String, String> entry : attributes.entrySet())
		{
			tempKey = entry.getKey().replaceFirst("[^A-Za-z]", "");
			tempKey = tempKey.replaceAll("[^A-Za-z0-9_]", "");
			tempKey = tempKey.replaceAll("\\:", "");
			tempKey = tempKey.replaceAll("\\.", "");
		    attributesClean.put(tempKey, entry.getValue());
		    session.removeAttribute(flowFile, entry.getKey());
		}
	
		session.putAllAttributes(flowFile, attributesClean);
		session.transfer(flowFile, REL_SUCCESS);
		session.commit();
	} catch (final Throwable t) {
		getLogger().error("Unable to process Attribute Cleaner file " + t.getLocalizedMessage());
		getLogger().error("{} failed to process due to {}; rolling back session", new Object[] { this, t });
		throw t;
	}
}
 
开发者ID:tspannhw,项目名称:nifi-attributecleaner-processor,代码行数:31,代码来源:AttributeCleanerProcessor.java

示例12: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    List<FlowFile> flowFiles = session.get(delayFilter);

    if (flowFiles.isEmpty()) {
        logger.debug("no flowFiles ready to be processed, yielding");
        context.yield();
    } else {
        for (FlowFile flowFile : flowFiles) {
            delayMap.remove(flowFile.getAttribute(CoreAttributes.UUID.key()));
        }
        logger.debug("transferring {} files to 'success': {}", new Object[]{flowFiles.size(), flowFiles});
        session.transfer(flowFiles, REL_SUCCESS);
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:16,代码来源:DelayProcessor.java

示例13: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    final byte[] buffer = new byte[(int) flowFile.getSize()];
    try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer)) {
        session.read(flowFile, in -> StreamUtils.fillBuffer(in, buffer));

        try (ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream)) {
            // Check the first entry.
            ZipEntry zipEntry = zipInputStream.getNextEntry();

            String name = "";
            if (zipEntry != null) {
                name = zipEntry.getName();
            }
            flowFile = session.putAttribute(flowFile, ATTR, name);
            session.getProvenanceReporter().modifyAttributes(flowFile);
            session.transfer(flowFile, REL_SUCCESS);
        }

    } catch (Exception e) {
        getLogger().error("Unable to update flowFile {} due to {}", new Object[]{flowFile, e.getMessage()}, e);
        session.transfer(flowFile, REL_FAILURE);
    }

}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:31,代码来源:InspectZipContents.java

示例14: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession processSession) {
    List<FlowFile> flowFiles = processSession.get(batchSize);
    if (flowFiles.isEmpty()) {
        return;
    }

    Session jschSession = null;
    Channel channel = null;
    try {
        jschSession = openSession(context);
        final String remotePath = context.getProperty(REMOTE_PATH).evaluateAttributeExpressions().getValue();
        channel = openExecChannel(context, jschSession, "scp -r -d -t " + remotePath);

        InputStream channelIn = channel.getInputStream();
        OutputStream channelOut = channel.getOutputStream();

        channel.connect();
        waitForAck(channelIn);

        ListIterator<FlowFile> fileIt = flowFiles.listIterator();
        while (fileIt.hasNext()) {
            final FlowFile flowFile = fileIt.next();

            // conditionally reject files that are zero bytes or less
            if (context.getProperty(REJECT_ZERO_BYTE).asBoolean() && flowFile.getSize() == 0) {
                logger.warn("Rejecting {} because it is zero bytes", new Object[]{flowFile});
                processSession.transfer(processSession.penalize(flowFile), REL_REJECT);
                fileIt.remove();
                continue;
            }

            final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
            final String permissions = context.getProperty(PERMISSIONS).evaluateAttributeExpressions(flowFile).getValue();

            // destination path + filename
            // final String fullPath = buildFullPath(context, flowFile, filename);

            processSession.read(flowFile, new InputStreamCallback() {
                @Override
                public void process(final InputStream flowFileIn) throws IOException {
                    // send "C0644 filesize filename", where filename should not include '/'
                    StringBuilder command = new StringBuilder("C").append(permissions).append(' ');
                    command.append(flowFile.getSize()).append(' ');
                    command.append(filename).append('\n');

                    channelOut.write(command.toString().getBytes(StandardCharsets.UTF_8));
                    channelOut.flush();
                    waitForAck(channelIn);

                    IOUtils.copy(flowFileIn, channelOut);
                    channelOut.flush();
                    sendAck(channelOut);
                    waitForAck(channelIn);
                }
            });

            processSession.transfer(flowFile, REL_SUCCESS);
            processSession.getProvenanceReporter().send(flowFile, remotePath);
            fileIt.remove();
            if (logger.isDebugEnabled()) {
                logger.debug("Sent {} to remote host", new Object[]{flowFile});
            }
        }

    } catch (JSchException | IOException ex) {
        context.yield();
        logger.error("Unable to create session to remote host due to {}", new Object[]{ex}, ex);
        processSession.transfer(flowFiles, REL_FAILURE);

    } finally {
        if (channel != null) {
            channel.disconnect();
        }
        if (jschSession != null) {
            jschSession.disconnect();
        }
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:80,代码来源:PutScp.java

示例15: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
  final ProcessorLog log = this.getLogger();
  final AtomicReference<List<Map.Entry<File, Boolean>>> value = new AtomicReference<>();
  final File tempDir = new File(context.getProperty(TEMP_DIR).getValue());
  System.getProperties().setProperty("jna.library.path", context.getProperty(JNI_PATH).getValue());
  FlowFile flowfile = session.get();
  session.read(flowfile, in -> {
    try {
      value.set(convert(in, tempDir));
    }
    catch(Exception e) {
      log.error("Unable to convert: " + e.getMessage(), e);
    }
  });
  if(value.get() != null) {
    for(Map.Entry<File, Boolean> kv : value.get()) {
      final File convertedFile = kv.getKey();
      try {
        final int pageNumber = getPageNumber(convertedFile.getName());
        if(kv.getValue()) {
          FlowFile ff = session.clone(flowfile);
          ff = session.putAttribute(ff, "pageNumber", "" + pageNumber);
          ff = session.write(ff, out -> IOUtils.copy(new BufferedInputStream(new FileInputStream(convertedFile)), out));
          session.transfer(ff, SUCCESS);
        }
      }
      finally {
        if(convertedFile != null && convertedFile.exists()) {
          convertedFile.delete();
        }
      }
    }
  }
  session.transfer(flowfile, RAW);
}
 
开发者ID:mmiklavc,项目名称:scalable-ocr,代码行数:37,代码来源:ConversionProcessor.java


注:本文中的org.apache.nifi.processor.ProcessSession.transfer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。