本文整理汇总了Java中org.apache.nifi.processor.ProcessSession.clone方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessSession.clone方法的具体用法?Java ProcessSession.clone怎么用?Java ProcessSession.clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.processor.ProcessSession
的用法示例。
在下文中一共展示了ProcessSession.clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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<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);
}
示例3: 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) {
return;
}
flowFile = session.clone(original);
Map<String, String> flowFileAttributes = flowFile.getAttributes();
session.transfer(original, REL_ORIGINAL);
String content = context.getProperty(CONTENT_FIELD).getValue().trim();
if (content.isEmpty()) {
return;
}
final JsonObject json = (JsonObject) JSON_PROVIDER.parse(content);
String[] attrSplit;
String value = null;
JsonElement replacement;
for (Map.Entry<String, String> entry : pathsForTemplating.entrySet()) {
String attrKey = entry.getValue().trim();
String entryKey = entry.getKey();
try {
attrKey = attrKey.substring(2, attrKey.length() - 2).trim();
String type = null;
if (attrKey.contains(":")) {
attrSplit = attrKey.split(":");
attrKey = attrSplit[0];
type = attrSplit[1];
value = flowFileAttributes.get(attrKey);
} else {
value = flowFile.getAttribute(attrKey);
}
replacement = processJson(type, value);
JsonUtil.updateField(json, entryKey.substring(2), replacement);
} catch (Exception e) {
getLogger().error("Unable to update {} with {} for attributes {}", new Object[]{entryKey, attrKey, flowFileAttributes}, e);
Map<String, String> failureAttributes = new HashMap<>();
failureAttributes.put("json.error.message", e.getMessage());
failureAttributes.put("json.error.key", entryKey);
failureAttributes.put("json.error.value", value);
flowFile = session.putAllAttributes(flowFile, failureAttributes);
session.transfer(flowFile, REL_FAILURE);
return;
}
}
flowFile = session.write(flowFile, outputStream -> outputStream.write(json.toString().getBytes(StandardCharsets.UTF_8)));
session.getProvenanceReporter().modifyContent(flowFile);
session.transfer(flowFile, REL_SUCCESS);
}
示例4: onTrigger
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
ComponentLog logger = this.getLogger();
// Evaluate expression language and create BSON Documents
Document query = (queryProperty.isSet()) ? Document.parse(queryProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
Document projection = (projectionProperty.isSet()) ? Document.parse(projectionProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
Document sort = (sortProperty.isSet()) ? Document.parse(sortProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
try {
FindIterable<Document> it = (query != null) ? collection.find(query) : collection.find();
// Apply projection if needed
if (projection != null) {
it.projection(projection);
}
// Apply sort if needed
if (sort != null) {
it.sort(sort);
}
// Apply limit if set
if (limit != null) {
it.limit(limit.intValue());
}
// Iterate and create flowfile for each result
final MongoCursor<Document> cursor = it.iterator();
try {
while (cursor.hasNext()) {
// Create new flowfile with all parent attributes
FlowFile ff = session.clone(flowFile);
ff = session.write(ff, new OutputStreamCallback() {
@Override
public void process(OutputStream outputStream) throws IOException {
IOUtils.write(cursor.next().toJson(), outputStream);
}
});
session.transfer(ff, REL_SUCCESS);
}
} finally {
cursor.close();
session.remove(flowFile);
}
} catch (Exception e) {
logger.error("Failed to execute query {} due to {}.", new Object[]{query, e}, e);
flowFile = session.putAttribute(flowFile, "mongo.exception", e.getMessage());
session.transfer(flowFile, REL_FAILURE);
}
}