oreilly.comSafari Books Online.Conferences.
Articles Radar Books  

Learning the JXTA Shell
Pages: 1, 2, 3, 4, 5

P2P Piping

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.

JXTA>pipeadv = mkadv -p apipe
JXTA>inpipe = mkpipe -i pipeadv
JXTA>Shell -s
JXTA>pigletmsg = recv inpipe

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.

JXTA>opipe = mkpipe -o pipeadv
JXTA>mymsg = mkmsg
JXTA>importfile -f hellopooh file1
JXTA>put mymsg hello file1
JXTA>importfile -f byepooh file2
JXTA>put mymsg bye file2
JXTA>send opipe mymsg

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 ...

recv has received a message
JXTA>cat pigletmsg
Tag: hello
Body:
<?xml version="1.0"?>

<ShellDoc>
  <Item>
    Hello, Pooh!
  </Item>
</ShellDoc>
Tag: bye
Body:
<?xml version="1.0"?>

<ShellDoc>
  <Item>
    Goodbye, Pooh!
  </Item>
</ShellDoc>

JXTA>data1 = get pigletmsg hello
JXTA>cat data1
<?xml version="1.0"?>

<ShellDoc>
  <Item>
    Hello, Pooh!
  </Item>
</ShellDoc>
JXTA>data2 = get pigletmsg bye
JXTA>cat data2
<?xml version="1.0"?>

<ShellDoc>
  <Item>
    Goodbye, Pooh!
  </Item>
</ShellDoc>

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 get command.



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.

Pages: 1, 2, 3, 4, 5

Next Pagearrow





P2P Weblogs

Richard Koman Richard Koman's Weblog
Supreme Court Decides Unanimously Against Grokster
Updating as we go. Supremes have ruled 9-0 in favor of the studios in MGM v Grokster. But does the decision have wider import? Is it a death knell for tech? It's starting to look like the answer is no. (Jun 27, 2005)

> More from O'Reilly Developer Weblogs


More Weblogs
FolderShare remote computer search: better privacy than Google Desktop? [Sid Steward]

Data Condoms: Solutions for Private, Remote Search Indexes [Sid Steward]

Behold! Google the darknet/p2p search engine! [Sid Steward]

Open Source & The Fallacy Of Composition [Spencer Critchley]