blob: 09a30db52ff72c134bf64d3b7c4ccb6be63844ea [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_77) on Mon Oct 24 00:05:43 UTC 2016 -->
<title>CommandStreams (Edgent v1.0.0)</title>
<meta name="date" content="2016-10-24">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="CommandStreams (Edgent v1.0.0)";
}
}
catch(err) {
}
//-->
var methods = {"i0":9,"i1":9,"i2":9,"i3":9,"i4":9,"i5":9,"i6":9};
var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/CommandStreams.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev&nbsp;Class</li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/edgent/connectors/command/CommandStreams.html" target="_top">Frames</a></li>
<li><a href="CommandStreams.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.edgent.connectors.command</div>
<h2 title="Class CommandStreams" class="title">Class CommandStreams</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>org.apache.edgent.connectors.command.CommandStreams</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="typeNameLabel">CommandStreams</span>
extends java.lang.Object</pre>
<div class="block">Connector for creating a TStream from a Command's / OS Process's output
and sinking a TStream to a Command's / OS Process's input.
<P>
e.g., run a network monitor command (like Tiger Shark) and ingest its output.</div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>static <a href="../../../../../org/apache/edgent/function/Supplier.html" title="interface in org.apache.edgent.function">Supplier</a>&lt;java.util.List&lt;java.lang.String&gt;&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#commandReaderList-java.lang.ProcessBuilder-">commandReaderList</a></span>(java.lang.ProcessBuilder&nbsp;cmd)</code>
<div class="block">Create a <code>Supplier&lt;List&lt;String&gt;&gt;</code> to ingest a command's output.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>static <a href="../../../../../org/apache/edgent/function/Consumer.html" title="interface in org.apache.edgent.function">Consumer</a>&lt;java.lang.String&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#commandWriter-java.lang.ProcessBuilder-">commandWriter</a></span>(java.lang.ProcessBuilder&nbsp;cmd)</code>
<div class="block">Create a <code>Consumer&lt;String&gt;</code> to write UTF8 string data to a command's input.</div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>static <a href="../../../../../org/apache/edgent/function/Supplier.html" title="interface in org.apache.edgent.function">Supplier</a>&lt;java.lang.String&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#endlessCommandReader-java.lang.ProcessBuilder-">endlessCommandReader</a></span>(java.lang.ProcessBuilder&nbsp;cmd)</code>
<div class="block">Create an endless <code>Supplier&lt;String&gt;</code> for ingesting a long running command's output.</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>static <a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;java.lang.String&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#generate-org.apache.edgent.topology.Topology-java.lang.ProcessBuilder-">generate</a></span>(<a href="../../../../../org/apache/edgent/topology/Topology.html" title="interface in org.apache.edgent.topology">Topology</a>&nbsp;topology,
java.lang.ProcessBuilder&nbsp;cmd)</code>
<div class="block">Create an endless <code>TStream&lt;String&gt;</code> from a long running command's output.</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>static <a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;java.util.List&lt;java.lang.String&gt;&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#periodicSource-org.apache.edgent.topology.Topology-java.lang.ProcessBuilder-long-java.util.concurrent.TimeUnit-">periodicSource</a></span>(<a href="../../../../../org/apache/edgent/topology/Topology.html" title="interface in org.apache.edgent.topology">Topology</a>&nbsp;topology,
java.lang.ProcessBuilder&nbsp;cmd,
long&nbsp;period,
java.util.concurrent.TimeUnit&nbsp;units)</code>
<div class="block">Create a <code>TStream&lt;String&gt;</code> from a periodically run command's output.</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>static <a href="../../../../../org/apache/edgent/topology/TSink.html" title="interface in org.apache.edgent.topology">TSink</a>&lt;java.lang.String&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#sink-org.apache.edgent.topology.TStream-java.lang.ProcessBuilder-">sink</a></span>(<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;java.lang.String&gt;&nbsp;stream,
java.lang.ProcessBuilder&nbsp;cmd)</code>
<div class="block">Sink a <code>TStream&lt;String&gt;</code> to a command's input.</div>
</td>
</tr>
<tr id="i6" class="altColor">
<td class="colFirst"><code>static java.util.List&lt;java.lang.String&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-">tokenize</a></span>(java.lang.String&nbsp;cmdString)</code>
<div class="block">Tokenize the specified <code>cmdString</code> in the exact same manner as
done by <code>Runtime.exec(String)</code>.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="tokenize-java.lang.String-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>tokenize</h4>
<pre>public static&nbsp;java.util.List&lt;java.lang.String&gt;&nbsp;tokenize(java.lang.String&nbsp;cmdString)</pre>
<div class="block">Tokenize the specified <code>cmdString</code> in the exact same manner as
done by <code>Runtime.exec(String)</code>.
<P>
This function provides a convenience for creating a <code>ProcessBuilder</code>
for use by the other CommandStreams methods.
</P>
<P>
Sample use:
<pre><code>
ProcessBuilder cmd = new ProcessBuilder(tokenize("sh someShellCmd.sh and args"));
TStream&lt;String&gt; stream = CommandStreams.generate(topology, cmd);
</code></pre></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>cmdString</code> - a command string</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the tokens</dd>
</dl>
</li>
</ul>
<a name="generate-org.apache.edgent.topology.Topology-java.lang.ProcessBuilder-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>generate</h4>
<pre>public static&nbsp;<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;java.lang.String&gt;&nbsp;generate(<a href="../../../../../org/apache/edgent/topology/Topology.html" title="interface in org.apache.edgent.topology">Topology</a>&nbsp;topology,
java.lang.ProcessBuilder&nbsp;cmd)</pre>
<div class="block">Create an endless <code>TStream&lt;String&gt;</code> from a long running command's output.
<P>
The supplied <code>cmd</code> is used to start the command.
A tuple is created for each UTF8 line read from the command's
<code>output</code>.
The tuples contain output from stderr if cmd is configured to
<code>redirect stderr to stdout</code>.
The command is restarted if a read from the command's output stream
returns EOF or an error.
</P>
<P>
This is a convenience function equivalent to
<code>topology.generate(endlessCommandReader(cmd))</code>.
</P>
<P>
Sample use: create a stream of tuples for the output from a
continuously running and restartable command:
<pre><code>
ProcessBuilder cmd = new ProcessBuilder("myCommand");
TStream&lt;String&gt; cmdOutput = CommandStreams.generate(topology, cmd);
cmdOutput.print();
</code></pre></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>topology</code> - the topology to add the source stream to</dd>
<dd><code>cmd</code> - the <code>ProcessBuilder</code> to start the command</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the source <code>TStream&lt;String&gt;</code></dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#endlessCommandReader-java.lang.ProcessBuilder-"><code>endlessCommandReader(ProcessBuilder)</code></a>,
<a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-"><code>tokenize(String)</code></a></dd>
</dl>
</li>
</ul>
<a name="periodicSource-org.apache.edgent.topology.Topology-java.lang.ProcessBuilder-long-java.util.concurrent.TimeUnit-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>periodicSource</h4>
<pre>public static&nbsp;<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;java.util.List&lt;java.lang.String&gt;&gt;&nbsp;periodicSource(<a href="../../../../../org/apache/edgent/topology/Topology.html" title="interface in org.apache.edgent.topology">Topology</a>&nbsp;topology,
java.lang.ProcessBuilder&nbsp;cmd,
long&nbsp;period,
java.util.concurrent.TimeUnit&nbsp;units)</pre>
<div class="block">Create a <code>TStream&lt;String&gt;</code> from a periodically run command's output.
<P>
The supplied <code>cmd</code> is used to start the command
at the specified <code>period</code>.
The command's UTF8 <code>output</code> is read until EOF
and a <code>List&lt;String&gt;</code> tuple is created containing the collected output.
The tuples contain output from stderr if the cmd is configured to
<code>redirect stderr to stdout</code>.
</P>
<P>
This is a convenience function equivalent to
<code>topology.poll(commandReaderList(cmd), period, units)</code>.
</P>
<P>
Sample use: create a stream of tuples containing the output
from a periodically run command:
<pre><code>
ProcessBuilder cmd = new ProcessBuilder("date");
TStream&lt;List&lt;String&gt;&gt; cmdOutput =
CommandStreams.periodicSource(topology, cmd, 2, TimeUnit.SECONDS);
cmdOutput.print();
</code></pre></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>topology</code> - the topology to add the source stream to</dd>
<dd><code>cmd</code> - the <code>ProcessBuilder</code> to start the command</dd>
<dd><code>period</code> - the period to run the command and collect its output</dd>
<dd><code>units</code> - TimeUnit for <code>period</code></dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the source <code>TStream&lt;List&lt;String&gt;&gt;</code></dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#commandReaderList-java.lang.ProcessBuilder-"><code>commandReaderList(ProcessBuilder)</code></a>,
<a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-"><code>tokenize(String)</code></a></dd>
</dl>
</li>
</ul>
<a name="sink-org.apache.edgent.topology.TStream-java.lang.ProcessBuilder-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sink</h4>
<pre>public static&nbsp;<a href="../../../../../org/apache/edgent/topology/TSink.html" title="interface in org.apache.edgent.topology">TSink</a>&lt;java.lang.String&gt;&nbsp;sink(<a href="../../../../../org/apache/edgent/topology/TStream.html" title="interface in org.apache.edgent.topology">TStream</a>&lt;java.lang.String&gt;&nbsp;stream,
java.lang.ProcessBuilder&nbsp;cmd)</pre>
<div class="block">Sink a <code>TStream&lt;String&gt;</code> to a command's input.
<P>
The supplied <code>cmd</code> is used to start the command.
Each tuple is written as UTF8 and flushed to the command's <code>input</code>.
The command is restarted if a write encounters an error.
</P>
<P>
While each write is followed by a flush() that only helps to
reduce the time it takes to notice that cmd has failed and restart it.
Supposedly "successfully written and flushed" values are not guaranteed to
have been received by a cmd across restarts.
</P>
<P>
This is a convenience function equivalent to
<code>stream.sink(commandWriter(cmd))</code>
</P>
<P>
Sample use: write a stream of tuples to the input of a command:
<pre><code>
TStream&lt;String&gt; stream = topology.strings("one", "two", "three");
ProcessBuilder cmd = new ProcessBuilder("cat").redirectOutput(new File("/dev/stdout"));
CommandStreams.sink(stream, cmd);
</code></pre></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>stream</code> - the stream to sink</dd>
<dd><code>cmd</code> - the <code>ProcessBuilder</code> to start the command</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a <a href="../../../../../org/apache/edgent/topology/TSink.html" title="interface in org.apache.edgent.topology"><code>TSink</code></a></dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#commandWriter-java.lang.ProcessBuilder-"><code>commandWriter(ProcessBuilder)</code></a>,
<a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-"><code>tokenize(String)</code></a></dd>
</dl>
</li>
</ul>
<a name="endlessCommandReader-java.lang.ProcessBuilder-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>endlessCommandReader</h4>
<pre>public static&nbsp;<a href="../../../../../org/apache/edgent/function/Supplier.html" title="interface in org.apache.edgent.function">Supplier</a>&lt;java.lang.String&gt;&nbsp;endlessCommandReader(java.lang.ProcessBuilder&nbsp;cmd)</pre>
<div class="block">Create an endless <code>Supplier&lt;String&gt;</code> for ingesting a long running command's output.
<P>
This method is particularly helpful in creating a sensor or source connector
class that hides the fact that it uses a command, enabling it to be used
like any other sensor/connector.
</P>
For example:
<pre><code>
// ingest the sensor data
TStream&lt;MySensorData&gt; stream = topology.generate(new MySensor());
// MySensor class
class MySensor implements Supplier&lt;MySensorData&gt; {
private String[] cmd = new String[] {"mySensorCmd", "arg1"};
private Supplier&lt;String&gt; commandReader =
CommandStreams.endlessCommandReader(new ProcessBuilder(cmd));
// implement Supplier&lt;MySensorData&gt;.get()
public MySensorData get() {
// get the next line from the cmd and create a MySensorData tuple from it
return createMySensorData(commandReader.get());
}
}
</code></pre>
<P>
The supplied <code>cmd</code> is used to start the command.
A call to <a href="../../../../../org/apache/edgent/function/Supplier.html#get--"><code>Supplier.get()</code></a> reads the next UTF8 line from the command's
<code>output</code>.
The returned strings contain output from stderr if the cmd is configured to
<code>redirect stderr to stdput</code>.
The command is restarted if a read from the command's output stream
returns EOF or an error.
</P></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>cmd</code> - the <code>ProcessBuilder</code> to start the command</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the <code>Supplier&lt;String&gt;</code></dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#generate-org.apache.edgent.topology.Topology-java.lang.ProcessBuilder-"><code>generate(Topology, ProcessBuilder)</code></a>,
<a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-"><code>tokenize(String)</code></a></dd>
</dl>
</li>
</ul>
<a name="commandReaderList-java.lang.ProcessBuilder-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>commandReaderList</h4>
<pre>public static&nbsp;<a href="../../../../../org/apache/edgent/function/Supplier.html" title="interface in org.apache.edgent.function">Supplier</a>&lt;java.util.List&lt;java.lang.String&gt;&gt;&nbsp;commandReaderList(java.lang.ProcessBuilder&nbsp;cmd)</pre>
<div class="block">Create a <code>Supplier&lt;List&lt;String&gt;&gt;</code> to ingest a command's output.
<P>
This method is particularly helpful in creating a sensor or source connector
class that hides the fact that it uses a command, enabling it to be used
like any other sensor/connector.
</P>
For example:
<pre><code>
// ingest the sensor data
TStream&lt;MySensorData&gt; stream = topology.periodicSource(new MySensor());
// MySensor class
class MySensor implements Supplier&lt;MySensorData&gt; {
private String[] cmd = new String[] {"mySensorCmd", "arg1"};
private Supplier&lt;List&lt;String&gt;&gt; commandReader =
CommandStreams.commandReaderList(new ProcessBuilder(cmd));
// implement Supplier&lt;MySensorData&gt;.get()
public MySensorData get() {
// get the cmd output and create a MySensorData tuple from it
return createMySensorData(commandReader.get());
}
}
</code></pre>
<P>
The supplied <code>cmd</code> is used to start the command.
A call to <a href="../../../../../org/apache/edgent/function/Supplier.html#get--"><code>Supplier.get()</code></a> reads the command's UTF8
<code>input stream</code> until an EOF or error
and returns a <code>List&lt;String&gt;</code> of the collected input.
The tuples contain output from stderr if the cmd is configured to
<code>redirect stderr to stdout</code>.
</P></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>cmd</code> - the <code>ProcessBuilder</code> to start the command</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the <code>Supplier&lt;List&lt;String&gt;&gt;</code> for the command</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#periodicSource-org.apache.edgent.topology.Topology-java.lang.ProcessBuilder-long-java.util.concurrent.TimeUnit-"><code>periodicSource(Topology, ProcessBuilder, long, TimeUnit)</code></a>,
<a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-"><code>tokenize(String)</code></a></dd>
</dl>
</li>
</ul>
<a name="commandWriter-java.lang.ProcessBuilder-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>commandWriter</h4>
<pre>public static&nbsp;<a href="../../../../../org/apache/edgent/function/Consumer.html" title="interface in org.apache.edgent.function">Consumer</a>&lt;java.lang.String&gt;&nbsp;commandWriter(java.lang.ProcessBuilder&nbsp;cmd)</pre>
<div class="block">Create a <code>Consumer&lt;String&gt;</code> to write UTF8 string data to a command's input.
<P>
This method is particularly helpful in creating a sink connector
that hides the fact that it uses a command, enabling it to be used
like a native connector.
</P>
For example:
<pre><code>
// sink a stream to my connector
TStream&lt;MySensorData&gt; stream = ...;
stream.sink(new MySinkConnector());
// MySinkConnector class
class MySinkConnector implements Consumer&lt;MySensorData&gt; {
private String[] cmd = new String[] {"mySinkCmd", "arg1"};
private Consumer&lt;String&gt; commandWriter =
CommandStreams.commandWriter(new ProcessBuilder(cmd));
// implement Consumer&lt;MySensorData&gt;.accept()
public void accept(MySensorData data) {
// convert the data to a string and write it to the cmd
commandWriter.accept(convertMySensorData(data));
}
}
</code></pre>
<P>
The supplied <code>cmd</code> is used to start the command.
Each call to <a href="../../../../../org/apache/edgent/function/Consumer.html#accept-T-"><code>accept(String)</code></a> writes a
UTF8 string to the command's <code>input</code>.
Each write is followed by a flush.
The command is restarted if a write encounters an error.
</P>
<P>
While each write is followed by a flush() that only helps to
reduce the time it takes to notice that cmd has failed and restart it.
Supposedly "successfully written and flushed" values are not guaranteed to
have been received by a cmd across restarts.
</P></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>cmd</code> - the <code>ProcessBuilder</code> to start the command</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the <code>Consumer&lt;String&gt;</code> for the command</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#sink-org.apache.edgent.topology.TStream-java.lang.ProcessBuilder-"><code>sink(TStream, ProcessBuilder)</code></a>,
<a href="../../../../../org/apache/edgent/connectors/command/CommandStreams.html#tokenize-java.lang.String-"><code>tokenize(String)</code></a></dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/CommandStreams.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><a href="http://edgent.incubator.apache.org">Apache Edgent (incubating)</a></div>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev&nbsp;Class</li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/edgent/connectors/command/CommandStreams.html" target="_top">Frames</a></li>
<li><a href="CommandStreams.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2016 The Apache Software Foundation. All Rights Reserved - 59dfbdf-20161024-0005</small></p>
</body>
</html>