NIFI-421: Deleted unused method; formatted whitespace

This commit is contained in:
Mark Payne 2015-04-29 14:52:20 -04:00
parent ad98ac50ca
commit fb8984cfa5

View File

@ -212,17 +212,16 @@ public class ExecuteProcess extends AbstractProcessor {
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
final long startNanos = System.nanoTime();
if (proxyOut==null)
if (proxyOut==null) {
proxyOut = new ProxyOutputStream(getLogger());
}
final Long batchNanos = context.getProperty(BATCH_DURATION).asTimePeriod(TimeUnit.NANOSECONDS);
final List<String> commandStrings = createCommandStrings(context);
final String commandString = StringUtils.join(commandStrings, " ");
if (longRunningProcess == null || longRunningProcess.isDone())
if (longRunningProcess == null || longRunningProcess.isDone()) {
try {
longRunningProcess = launchProcess(context, commandStrings, batchNanos, proxyOut);
} catch (final IOException ioe) {
@ -230,8 +229,9 @@ public class ExecuteProcess extends AbstractProcessor {
context.yield();
return;
}
else
} else {
getLogger().info("Read from long running process");
}
if (!isScheduled()) {
getLogger().info("User stopped processor; will terminate process immediately");
@ -239,10 +239,8 @@ public class ExecuteProcess extends AbstractProcessor {
return;
}
// Create a FlowFile that we can write to and set the OutputStream for
// the FlowFile
// as the delegate for the ProxyOuptutStream, then wait until the
// process finishes
// Create a FlowFile that we can write to and set the OutputStream for the FlowFile
// as the delegate for the ProxyOuptutStream, then wait until the process finishes
// or until the specified amount of time
FlowFile flowFile = session.create();
flowFile = session.write(flowFile, new OutputStreamCallback() {
@ -252,8 +250,7 @@ public class ExecuteProcess extends AbstractProcessor {
proxyOut.setDelegate(out);
if (batchNanos == null) {
// we are not creating batches; wait until process
// terminates.
// we are not creating batches; wait until process terminates.
// NB!!! Maybe get(long timeout, TimeUnit unit) should
// be used to avoid waiting forever.
try {
@ -280,8 +277,7 @@ public class ExecuteProcess extends AbstractProcessor {
// If no data was written to the file, remove it
session.remove(flowFile);
} else if (failure.get()) {
// If there was a failure processing the output of the Process,
// remove the FlowFile
// If there was a failure processing the output of the Process, remove the FlowFile
session.remove(flowFile);
getLogger().error("Failed to read data from Process, so will not generate FlowFile");
} else {
@ -291,13 +287,11 @@ public class ExecuteProcess extends AbstractProcessor {
session.transfer(flowFile, REL_SUCCESS);
}
// Commit the session so that the FlowFile is transferred to the next
// processor
// Commit the session so that the FlowFile is transferred to the next processor
session.commit();
}
protected List<String> createCommandStrings(final ProcessContext context) {
final String command = context.getProperty(COMMAND).getValue();
final List<String> args = splitArgs(context.getProperty(COMMAND_ARGUMENTS).getValue());
@ -381,8 +375,7 @@ public class ExecuteProcess extends AbstractProcessor {
// setting a batch during means text.
// Also, we don't want that text to get split up in the
// middle of a line, so we use BufferedReader
// to read lines of text and write them as lines of
// text.
// to read lines of text and write them as lines of text.
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(newProcess.getInputStream()))) {
String line;
@ -402,12 +395,10 @@ public class ExecuteProcess extends AbstractProcessor {
int exitCode;
try {
exitCode = newProcess.exitValue();
} catch (Exception e) {
} catch (final Exception e) {
exitCode = -99999;
}
getLogger().info("Process finished with exit code {} ", new Object[] { exitCode });
// getLogger().info("Process finished with exit code {} after creating {} FlowFiles in {} millis",
// new Object[]{exitCode, flowFileCount, millis});
}
return null;
@ -417,18 +408,6 @@ public class ExecuteProcess extends AbstractProcessor {
return future;
}
// NB!!! Currently not used, Future<?> longRunningProcess is used to check whether process is done or not.
private boolean isAlive(final Process process) {
// unfortunately, java provides no straight-forward way to test if a Process is alive.
// In Java 8, Process.isAlive() is introduced, but NiFi needs to run against Java 7,
// so we have this solution in the mean time.
try {
process.exitValue();
return false;
} catch (final IllegalThreadStateException itse) {
return true;
}
}
/**
* Output stream that is used to wrap another output stream in a way that the underlying output stream can be swapped out for a different one when needed