sunlabs.brazil.sunlabs
Class PipeTemplate

java.lang.Object
  extended by sunlabs.brazil.template.Template
      extended by 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


Field Summary
 
Fields inherited from class sunlabs.brazil.template.Template
debug
 
Constructor Summary
PipeTemplate()
           
 
Method Summary
 void tag_pipe(RewriteContext hr)
           
 
Methods inherited from class sunlabs.brazil.template.Template
done, init
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PipeTemplate

public PipeTemplate()
Method Detail

tag_pipe

public void tag_pipe(RewriteContext hr)

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.