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:
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
- A set of text fields that let you define the fields of an entry and then write it into a JavaSpaces service
- A list and set of buttons that let you work with transactions
- A message window for results
- A list of the results and buttons which let you cancel and renew an entry's lease
FullRFBobject; otherwise it will be anRFBobject.FullRFBis a subclass ofRFB.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
Countto 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 areRFBobjects, the rest areFullRFBobjects 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
Nonebutton 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).
RFBandFullRFBentries 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 anet.jini.lease.Leaseconstant (FOREVERorANY).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.
- A set of text fields that let you define a template for reading or taking an entry from a space
- A list and buttons that let you work with transactions
- A message window for results
- A list of notification registrations and buttons which let you cancel and renew their leases
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
RFBtemplate that can match bothRFBandFullRFBentries. 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 aFullRFB, the ISBN field is filled in withNONE.Clear clears out all the fields.If a
readortakefails, 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
readandtaketo 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
Newbutton is used when you want to create a new transaction. All existing transactions appear in the listTransactions. Any transaction from the list may be selected. Doing so will cause a particular transaction to be hilighted. TheCommitandAbortbuttons are used to commit and abort a highlighted transaction. TheNonebutton is used to unselect a highlighted transaction.The third section displays timing information for the
ReadandTakebuttons. 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.Leaseconstant (FOREVERorANY).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:
- A set of text fields and buttons that let you define a template for iteration and control the watcher itself
- A list and buttons that let you work with transactions
- A message window for results. Mostly this shows how long the operations watcher performed have taken.
- A list of the results of the last iteration through the space
- An area for working with leases acquired by the watcher. Currently the watcher does not acquire any leases so this area is unused.
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:
- Clear - Clears the template text fields
- Update - Displays in the window the entries in the space that match the template
- Stop - Determines whether the space is auto-updated every five seconds. The label toggles between Stop and Watch
- Use - Tells the applet to start using the template defined by the current values of its fields
- Destroy - Invokes the
DestroyAdmin.destroymethod of the space's admin. The destroy method destroys the space and any persistent data associated with the space.