The JXTA shell extends the concept of the piping between local
commands (as in
man | wc) to inter-peer communication.
JXTA pipes are unidirectional and asynchronous.
Since JXTA pipes are asynchronous, an output pipe connection can be dynamically disconnected and reconnected to a different input pipe. This disconnection operation can be performed multiple times over the lifetime of the pipe. The ability to transparently redirect output of pipes is an essential feature to build highly available services in a loosely coupled and unreliable environment such as peer-to-peer networks. -- JXTA Shell Documentation (PDF)
While not quite as elegant as using the
| character, piping
from one peer to another in JXTA is almost trivial. As an example,
we'll open two shell windows (call them Pooh
and Piglet) and pipe a couple of simple
text messages between them (from Piglet to
Pooh). Pretend for a moment that these are
two separate peers running on machines on opposite sides of the Hundred Acre Wood.
First, Pooh creates a pipe advertisement and gives it a name ("pipeadv").
He uses this pipe advertisement to create an input pipe
("inpipe") -- the receiving end. After launching another shell window
Shell -s) for Piglet, an environment variable ("pigletmsg") is
readied to receive input from our input pipe. We leave this shell
window in a waiting state and wander over to Piglet's.
Piglet uses the same pipe advertisement to create an output pipe ("opipe"). A new message is created and stored in the environment variable "mymsg." Now Piglet has created a couple of text files named hellopooh and byepoo containing one line of text apiece. In turn, each file is imported and stuffed into the variables "file1" and "file2." The contents are packed into "mymsg" with an associated arbitrary tag, so as to be able to sort them at the other end. Finally, Piglet sends his message via the output pipe and ...
Instantly (or so the theory goes), Pooh receives Piglet's message.
Simply printing the value of the "pigletmsg" variable reveals a
message composed of a couple of XML documents and the associated tags
given to them by Piglet. Instead of simply being displayed, individual documents
can be extracted from the
message and assigned to a variable using the
Since inter-peer messages are nothing more than XML documents, this provides various interesting intersections with Web Services (via XML-RPC and SOAP), syndication (via RSS), Instant Messaging a la Jabber, and more.