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


Java ProcessSession.penalize方法代码示例

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


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

示例1: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
       String attemptsAttribute = context.getProperty(CLIENT_NAME) + ".attempts";
       String source = context.getProperty(TOPIC).getValue();
       Long requiredEnrichments = context.getProperty(ENRICHMENTS).asLong();
       
       
       boolean jsonMode = context.getProperty(JSON_CONTENT_MODE).asBoolean();
       String jsonField = context.getProperty(JSON_ENRICHMENT_FIELD).getValue();
       
       FlowFileEnricher ffe = null;
       if (jsonMode) {
           ffe = new JSONFlowFileEnricherImpl(jsonField);
       } else {
           ffe = new AttributeFlowFileEnricherImpl();
       }

       final List<FlowFile> flowFiles = session.get(FlowFileFilters.newSizeBasedFilter(1, DataUnit.MB, 100));
       if (flowFiles.isEmpty()) {
           return;
       }

       final ProcessorLog logger = getLogger();
       try (Jedis jedis = jedisPool.getResource()) {
           for (FlowFile flowFile : flowFiles) {
               // try to hit the needed values in redis
               String uuid = flowFile.getAttribute("uuid");
               String flowFileKey = source + ":" + uuid;
               
               if (requiredEnrichments == 0) {
                   logger.info("Transferred {} to 'success'", new Object[] {flowFile});
                   session.transfer(flowFile, REL_SUCCESS);
               } else if (jedis.hlen(flowFileKey) != requiredEnrichments) {
                   String attemptsStr = flowFile.getAttribute(attemptsAttribute);
                   Integer attempts = (attemptsStr == null) ? 0 : Integer.valueOf(attemptsStr);
                   attempts += 1;
                   
                   flowFile = session.putAttribute(flowFile, attemptsAttribute, String.valueOf(attempts));                 
                   flowFile = session.penalize(flowFile);
                   logger.info("Transferred {} to 'retry', attempt {}", new Object[] {uuid, attempts});
                   session.getProvenanceReporter().modifyAttributes(flowFile, "FlowFile modified with attempt attribute");
                   session.transfer(flowFile, REL_RETRY);
               } else {
                   Map<String, String> enrichments = jedis.hgetAll(flowFileKey);
                   flowFile = ffe.enrich(session, flowFile, enrichments);
                   logger.info("Transferred {} to 'success'", new Object[] {flowFile});
                   session.transfer(flowFile, REL_SUCCESS);
                   jedis.del(flowFileKey);
               }
           }
       } catch (JedisConnectionException e) { 
           logger.error("Failed to connect to Redis due to {}; routing flowfiles to failure", new Object[] { e.getMessage() });
           session.transfer(flowFiles, REL_FAILURE);
       }
}
 
开发者ID:qntfy,项目名称:nifi-redis,代码行数:56,代码来源:GetRedisEnrichment.java


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