sunlabs.brazil.sunlabs
Class PipeTemplate
java.lang.Object
sunlabs.brazil.template.Template
sunlabs.brazil.sunlabs.PipeTemplate (view source)
- All Implemented Interfaces:
- TemplateInterface
public class PipeTemplate
- extends Template
Template to run a program, in a pipe, feed data to its stdin, and
get data back from its stdout.
This template processes the <pipe ...>
tag.
The following attributes are supported. ${...} substitutions are
preformed before the command is run. This template implements a
"coprocess" model of IPC, where a process is started, then communicates
with templates via its stdin and stdout. The "Stdout" of the co-process
(e.g. the "command"), must have line-buffered input and output for this to
work.
- command
-
The command to run. The environment (and path) are inherited
from the server. This is a required parameter.
- stdoutQ
- The name of the Queue to listen on for output (required)
- stdinQ
- The name of the Queue that accepts stdin (required)
- id
- If specified, this names the process. The "id" will be
available along with each "line" dequeued. The "id" may also
be used to Kill the process.
- kill=[id]
- Termimates a previously started process named "id", if any.
"id"'s are global for each invoking template. If "kill" is speicified,
all other attributes are ignored.
Each line of output is placed into the "stdoutQ" queue as a single element
map named "line". If the process terminates, the "error" element of the
map is set instead. Lines destined for the "stdin" of the process are placed
in the "line" element of a map, end enqueued to the "stdinQ" using the
QueueTemplate. Both stdout and stderr are placed into the "stdoutQ".
The "source" element is set to "stdout" and "stderr" accordingly, so
they may be distinguished. Although "stdout" is line buffered, "stdout"
is not, and the data is queued (in the "line" element) in arbibrary up
to 256 character chunks.
Example:
- <pipe command="runme" stdinQ=in stdoutQ=out>
- Start the command "runme" in a pipeline
- <enqueue name=in data=line#to_runme>
- send the line "to_runme" to the stdin of the "runme" process
- <dequeue name=out prepend=q. timelimit=5>
- Read a line from the stdout of the "runme" process
Fields inherited from class sunlabs.brazil.template.Template |
debug |
PipeTemplate
public PipeTemplate()
tag_pipe
public void tag_pipe(RewriteContext hr)