Home > SOA Tips > The Web Services Advisor > How Web services can use JavaSpaces
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

THE WEB SERVICES ADVISOR

How Web services can use JavaSpaces


By William Brogden
04.17.2007
Rating: --- (out of 5)


Enterprise IT tips and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


In my previous article I laid out some differences between the various technologies that get lumped under the term "grid computing" and how Web services and grid computing can work together. Now I would like to describe in more detail how "space" style grid computing actually works, using open source JavaSpaces as an example.

To recap, "space" style distributed computing is characterized by loosely coupled systems, which are coordinated through a single service acting as a shared associative memory for data containing objects. In a Web service context, the service would take a request that requires extensive computation or other resources and create an object representing the job. This object would be written into a space where worker processes have registered as having the capability of doing specific kinds of jobs. On completion of the job, the Web service would get back an object containing the results and format a reply to the requesting system.

The Example Problem

I am going to use an example that is a simple version of a general information lookup problem: given a partial description, locate all the entities that might fit that description. In this case we have a word which may or may not be spelled correctly. This may come from a court reporter notes trying to represent what a witness said phonetically. We have the attempt at spelling the word plus some context as to the way the word was used. We need to find a list of words that might have been intended. This will be done by creating an object containing the information we have and letting lookup workers try to match it.

What a JavaSpace Holds

In order to place objects in a JavaSpace, you must have a class which implements the Entry interface (which extends the Serializable interface). Furthermore, each field must have a public object reference - no primitives. Here is the Java class I used - "Metaphone" is the name of the phonetic encoding algorithm. Entries are used both to represent jobs and as templates by which workers notify a space that they want entries having certain characteristics.

public class MetaphoneLookupEntry implements
net.jini.core.entry.Entry {

public String word ; // the starting point word
public String domain ; // ie names, places, companies, etc
public Boolean filled = Boolean.FALSE ;
public String code ; // metaphone code
public String worker ; // so we can track who does what public String[] matching ;
public MetaphoneLookupEntry() {
}
public MetaphoneLookupEntry(String wd, String type ){ word = wd ; domain = type ;
}
}

A worker will calculate the Metaphone code for a word and use that to look up possible matches in a list for the specified domain. Matches go into the "matching" String array and the "filled" field will be set to TRUE. If there is no match the String array will be empty.

Basic JavaSpace Operations

JavaSpaces support four basic operations that turn out to provide tremendous capabilities for organizing distributed computing. Note that a space does not modify an entry object, it only holds objects and communicates with other programs. The basic operations are "write," "take," "read" and "notify." For the lookup service we only need the simplest versions.

The "write" operation puts an object into a space and specifies the length of time the entry will be valid, known as the lease duration. For a Web service, the lease should be short so that a failure becomes apparent quickly. For example, a service needing a lookup might write a MetaphoneLookupEntry with name="pittsburgh", type="place" and the filled field equal FALSE into a space with a lease time of 10 seconds.

The "take" operation uses an Entry as a template where data fields that are null act as wild cards and data fields that have values must be matched. A worker that knows how to look up "place" names would create a MetaphoneLookupEntry object where domain="place," filled=FALSE and all other fields remain null so anything will match and use that in a "take" operation. "Take" operations also specify an amount of time to wait. The "take" operation will either return an Entry with a job or null indicating that no job is available.

The "read" operation is similar to "take," but only gets a copy, the original Entry remains in the space. The "notify" operation sets up a call-back link by which the space server will notify a worker when a matching Entry has been written into the space.

An Example Sequence of Events

Here is how a Web service could make use of a JavaSpaces service. We assume that one or more worker processes has done a "take" operation with a template specifying type="place" and filled=FALSE. Note that the worker process thread will be stalled until the take returns or the lease times out. Any number of worker process threads may be in this state.

  * The Web service does a write operation with an Entry having type="place," name="pittsburgh" and filled=FALSE. Immediately it does a "take" with the same values except having filled=TRUE, this will retrieve the Entry when a worker writes it back to the space.

  * One of the worker "take" operations succeeds, resulting in an Entry specifying a needed lookup. The worker fills in the matching String array, sets filled=TRUE and writes the Entry back to the space.

  * The Web service "take" with filled=TRUE succeeds, recovering the Entry with lookup results filled in with possible matches. In the word list I used, "Pitsburg", "Pittsboro", "Pittsburg" and "Pottsboro" were found as phonetic matches.

Advantages and Disadvantages

Although JavaSpaces servers are not trivial to set up, they are much easier than any other type of grid computing server. Furthermore, the simplicity of the interface makes the learning curve easier. The greatest advantage of the JavaSpaces approach is the ease with which additional workers can be added to the grid.

It should be clear from the example that there is a lot of extra communication traffic in a JavaSpaces solution so the only reason to use JavaSpaces or any other form of grid computing in support of a Web service is a requirement for computing power or special resources that are not feasible to supply on the server directly.

Resources

Recent tutorial on JavaSpaces

Jini starter kit, including a JavaSpaces implementation

GigaSpaces commercial and community edition JavaSpaces implementations

Apache Jakarta implementation of the Metaphone Algorithm

Moby Words public domain source

Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
The Web Services Advisor
Backup to the compute cloud
SPARQL shines as RDF's query language
Testing Web services: Unit testing and monitoring
Web services for Windows CE
Testing Web services and RIAs
The problem with IT project management
Web services with Open and Microsoft Office
REST with Axis, Struts, ColdFusion and WCF
Cross-site XMLHttpRequest: Boon or Pandora's Box
SOA and Web 2.0: The odd couple?

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2001 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts