Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
We developed the graphical aspects of the whiteboard last month (shown below), so now we're ready to add the networking features
to the application. We are going to accomplish this by networking the
ObservableList class. As we discussed last month, this class creates a list of the displayed elements of the whiteboard. If you need a refresher,
take this opportunity to reread part 1.
The graphical whiteboard
Our whiteboard tools manipulate the whiteboard by altering the list of elements. When changes are made to the list, all interested listeners are notified. Listeners, such as the display area, can then automatically update themselves to reflect these changes.
To enable networking, we will simply replace
ObservableList with a distributed
ObservableList, which ensures changes are propagated over the Internet. The distributed list presents exactly the same API as the original
local list and so requires no changes to (or knowledge of) any parts of the whiteboard.
In the course of this article, we will look at two different approaches to networking -- socket-based and RMI-based -- and examine the pros and cons of each approach.
IDList. This class is essentially a combination of the traditional
Vectorclasses; it is an ordered list (
Vector) of identifier-element pairs (
Hashtable). As objects are added to the
IDList, they are automatically assigned an associated identifier. The list can then be manipulated by addressing the elements by their identifiers (instead of the traditional mode of addressing the elements by their index number, which can change if any element is removed or inserted).
The IDList class
When we network the
IDList class, the element identifiers will be distributed to all connected whiteboards. The whiteboards can then communicate coherently
about elements of the list through the use of their identifiers.
The interface that
class IDList presents is fairly rudimentary; however, it is sufficient to serve our purposes. Let's quickly review the methods available
to this class:
public Object addElement (Object element)
This method adds an element to the list, assigns it a VM-unique identifier (based on the VM hashcode of the element) and returns this identifier.
The effects of replaceElement()
public Object replaceElement (Object oldID, Object element)
This method replaces the old element identified by
oldID with the new element
element. The new element is added to the end of the list and the identifier that it is allocated is returned. If the specified old
element was not present in the list, this method returns
null without adding the new element.