Running the Book-Buyer Example


How to Use the Example

We have provided a simple "book buying" system as an example of a JavaSpacesTM technology implementation, in which a JavaSpaces service provides a place for a book buyer to write "Request For Bid" (RFB) objects. RFBs come in two varieties: regular (without an ISBN number) and full (with an ISBN number). Book buyers can write either kind of RFB entry into the space. Book sellers read from the space, and can request notification based on templates. Zero or more sellers or buyers may be created to interact with the space, but we'll start by taking you through the process of bringing up a single buyer, a single seller, and a "watcher," that acts as an observer, indepent of either the seller or the buyer. The steps you'll need to take are:

  1. Start your supporting services, either by using the GUI provided or from the command line.
  2. Bring up three applets, either by using the GUI provided or from the command line:

The BookBuyer Window

The BookBuyer window is blue and grey, and has black text on an off-white background:

You can use theBookBuyer window to write entries into a JavaSpaces service. This window has four sections from top to bottom: Section one has three fields (ISBN, Title, and Count) and three buttons (Clear, Write, and Blast). The Order label at the top is generated automatically, and is the order number of the next order to be written. There are three fields of the RFB that can be specified: ISBN, Title and Count. If you specify an ISBN, the entry written will be a FullRFB object; otherwise it will be an RFB object. FullRFB is a subclass of RFB.

When you have finished typing your information into the fields, you can use the Write button to write that entry into the space. The Clear button clears out the fields, setting the Count to 1. The Blast button "blasts" entries into the space so you can populate it more easily. When you hit Blast, the Count field is examined, and that many random entries with random titles from a resource file and random counts and ISBNs are written. One third of the written entries are RFB objects, the rest are FullRFB objects with ISBNs.

Section two maintains a list of transactions under which operations on a JavaSpaces service may be performed. There is one list, (Transactions) and four buttons (New, Commit, Abort, and None). The New button is used when you want to create a new transaction. All existing transactions appear in the list Transactions. Any transaction from the list may be selected. Doing so will cause a particular transaction to be highlighted. The Commit and Abort buttons are used to commit and abort a highlighted transaction. The None button is used to deselect a highlighted transaction.

Section three displays timing information for the Write and Blast buttons. These buttons are timed so you can see how long it took, for example, to write 100 entries into the space.

Section four has a list, two buttons (Cancel and Renew) and a field (Time). RFB and FullRFB entries written into the JavaSpaces service appear in the list. Items in the list may be selected by clicking on them. A selected item will appear highlighted. The Cancel button will cancel the lease on an entry selected from the list. The Renew button will renew the lease for a number of milliseconds specified in the Time field. The Time field will accept either a number (of milliseconds) or a net.jini.lease.Lease constant (FOREVER or ANY).

The BookSeller Window

The BookSeller window is magenta and pale yellow, and has black text on a light peach background:

A BookSeller window has four sections from top to bottom: In the first section, the BookSeller fields, are used to set fields for the template. Blank fields are template wildcards; non-blank fields are values that must be matched. This section has five buttons (Clear, Read, Take, Notify, and Unregister), two checkboxes (if exists and match any), and one field, Timeout.

Read and Take use values from the text fields, and optionally wildcards, to create a template. If nothing is specified in the ISBN field, the template is an RFB template that can match both RFB and FullRFB entries. If a match is found, the values from the match are filled into the fields (and into the Order label above). If the match is not a FullRFB, the ISBN field is filled in with NONE.

Clear clears out all the fields.If a read or take fails, the window's colors are inverted until the next operation (such as Clear).

Notify sets up a notification based on a template. The list below the Cancel and Renew buttons shows the current registrations of interest created by Notify. You can unregister a notification request by selecting it, and pressing the Cancel button. When a notification arrives, it is displayed in the message window where the times are. The notifications are also printed to the console, so you can see them arriving.

Selecting if exists causes the "if exists" version of read and take to be used. Selecting match any causes a null template to be used, ignoring any information specified in the fields. A null (empty) template can match any entry in the space.

The second section maintains a list of transactions under which operations on a JavaSpaces service may be performed. There is one field, (Transactions) and three buttons (New, Commit, Abort, and None). The New button is used when you want to create a new transaction. All existing transactions appear in the list Transactions. Any transaction from the list may be selected. Doing so will cause a particular transaction to be hilighted. The Commit and Abort buttons are used to commit and abort a highlighted transaction. The None button is used to unselect a highlighted transaction.

The third section displays timing information for the Read and Take buttons. These buttons are timed so you can see how long it took to, for example, take an entry from the space. Notification events also show up in this area.

Section four has a list, two buttons (Cancel and Renew) and a field (Time). Notification registrations with the space appear in the list. Items in the list may be selected by clicking on them. A selected item will appear highlighted. The Cancel button will cancel the lease on the registration selected from the list. The Renew button will renew the lease for a number of milliseconds specified in the Time field. The Time field will accept either a number (of milliseconds) or a net.jini.lease.Lease constant (FOREVER or ANY).

The Watcher Window

The largest window is the one for the service "watcher", or administrator. It is magenta and gray, with black text on a cream background:

The Watcher window has five areas, starting from the top:

The text fields define a template in the same way as for a book seller. This template is used to iterate through all the entries in the space. The entries that match the template are displayed in the area directly above the Cancel and Renew buttons.

The buttons work as follows:


Copyright © 1999 Sun Microsystems, Inc. All Rights Reserved.