O'Reilly logo

JXTA in a Nutshell by Li Gong, Bernard Traversat, Scott Oaks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pipe Messages

The next step in the implementation of our RestoPeer is to implement its handleFriesRequest( ) method. This method is responsible for reading requests from HungryPeers and sending responses to them; it shows us how to pass messages over pipes.

Here’s how we implement this method:

// Method to handle fries auction requests from HungryPeers. The method // waits for HungryPeer requests' pipe messages to arrive. Incoming requests // contain a pipe advertisement for responding to the HungryPeer's requester // and a fries size. The method generates a bid offer for the request, opens // an output pipe to the HungryPeer requester, and sends the response. private void handleFriesRequest( ) { InputStream ip = null; // Input stream to read message PipeAdvertisement hungryPipe = null; // HungryPeer requester pipe StructuredDocument request = null; // Request document StructuredDocument bid = null; // Response document // Document mime types MimeMediaType mimeType = new MimeMediaType("text", "xml"); Element el = null; // Element in document String name = null; // Name of the sender String size = null; // Fries size requested OutputPipe pipeOut = null; // Output pipe to respond to // HungryPeer requester System.out.println("RestoNet Restaurant (" + brand + ") waiting for HungryPeer requests"); // Loop waiting for HungryPeer requests while (true) { Message msg = null; // Incoming pipe message try { // Block until a message arrives on the RestoPeer pipe msg = pipeIn.waitForMessage( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required