本文整理汇总了Java中org.apache.nifi.processor.ProcessContext.yield方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessContext.yield方法的具体用法?Java ProcessContext.yield怎么用?Java ProcessContext.yield使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.processor.ProcessContext
的用法示例。
在下文中一共展示了ProcessContext.yield方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rendezvousWithJms
import org.apache.nifi.processor.ProcessContext; //导入方法依赖的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();
}
}
}
示例2: onTrigger
import org.apache.nifi.processor.ProcessContext; //导入方法依赖的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);
}
}
示例3: onTrigger
import org.apache.nifi.processor.ProcessContext; //导入方法依赖的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();
}
}
}