本文整理汇总了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);
}
}