New to Java? We'll help you get started with our revised beginner's tutorial, or our free online textbook.


Get the latest Java books
h t t p : / /w w w . j a v a c o f f e e b r e a k . c o m /

Java Coffee Break

Chapter 4: Entry Objects

Contents

Entries are used to pass additional information about services that clients can use to decide if a particular service is what it wants.

4.1. Entry class

When a server registers a service, it places a copy of the service (or a suitable proxy) on the lookup service. This copy is an instance of an object, albeit in serialised form. The server can optionally register sets of attributes along with the service instance. Each set is given by an instance of a type or class. So what is stored on each service locator is an instance of a class along with a set of attribute entries. For example, a set of file editors may be available as services. Each editor is capable of editing different types of file as in

Figure 4.1: Editor class diagram
(Note: these would probably be interfaces, rather than instantiable classes.)

A client can search for a suitable editor in two ways

  1. By asking for an instance of a specific class such as ImageEditor
  2. By asking for an instance of the general class Editor with the additional information that it can handle a certain type of file
The type of search performed depends on the problem domain and the amount of information that clients have. Jini can handle either case. It handles the first case by only specifying a class object, such as ImageEditor.class. The Jini Entry class is designed to help with the second situation by specifying a superclass object such as Editor.class and allowing the additional information to be given in the request by adding extra objects.

The Entry class also allows services to advertise their capabilities in ways that would otherwise require use of multiple inheritance, which is not available in Java. Suppose an editor belonged to class SuperEditor which can handle plain text, RTF files and image files. In a multiple inheritance system it would do so by subclassing from all of the classes. In Jini, it just advertises itself as being an Editor, but has entries attached for each of the types that it can handle.

To manage this, we would have a class FileType which gives information about the types of file handled:


public Class FileType implements Entry {
    public String type; // this is a MIME type

    public FileType(String type) {     
       this.type = type;
    }
}
For a text editor, the attribute set would be FileType("plain/text"). For a RTF editor, the attribute set would be FileType("application/rtf"). (Of course, there may be more than one field in the class!)

For the SuperEditor, its capabilities would be given by using an array of entries:


Entry[] entries = new Entry[] {new FileType("plain/text"),
                               new FileType("application/rtf")
                               new FileType("image/gif")
                              };

On the other side, a client wishes to find services that can handle the attributes that it requires. The client uses the same Entry class for this. For any particular Entry, the client specifies

  1. Which fields must match exactly (a non-null value)
  2. Which fields it does not care about - a null value)
For example, to search for a plain text editor, an entry would be used such as

Entry[] entries = new Entry[] {new FileType("plain/text")};
If any editor will do,

Entry[] entries = new Entry[] {new FileType(null)};

4.1.1 Simplistic

The matching mechanism is pretty crude. A printer typically has the capacity to print a certain number of pages per minute. If it specifies this using an Entry, then it actually makes it rather hard to find! A client can request a printer service in which it does not care about speed, or request for a particular speed. It cannot ask for printers with a speed greater than some value. It cannot ask for a printer without a capability, such as anything except a color printer. An attribute must either match exactly or be ignored. The relational operators such as `<' and `!=' are not supported.

If you want to search for a printer at a particular speed, then printer speed capabilities may need to be given simpler descriptive values such as ``fast'', ``average'' or ``slow''. Then, once you have a ``fast'' printer service returned to the client, it can perform a query on the service itself for its actual speed. This would be done outside of the Jini mechanisms, using whatever interface has been agreed for the description of printers. A similar problem, that of finding a physically ``close'' service is taken up in the chapter on ``More Complex Examples''.

The mechanism chosen, of exact matches with wildcards, is comparatively easy to implement. It is a pity from the programmer's view that a more flexible mechanism was not used. One suggestion often made in the Jini mailing list is that there should be a boolean matches() method on the service object. However, it would involve un-marshalling the service on the locator in order to run the matches() method and this suffers from a variety of problems

  1. What security permissions should the filter run with?
  2. Slows the lookup service down
  3. What happens if the filter modifies its arguments - deep copying to avoid this will cause further slow-downs
(The ClientLookupManager - discussed in a much later chapter - has the ability to do client-side filtering to partly rectify this.)

4.2. Restrictions on entries

Entries are shipped around in marshalled form. Exported service objects are serialized, moved around and reconstituted as objects at some remote client. Entries are similarly serialized and moved around. However, when it comes to comparing them, this is usually done on the lookup service and they are not reconstituted on the lookup service. So when it comes to comparing an entry from a service and an entry from a client request, it is the serialized forms that are compared.

An entry cannot have as field one of the primitive types such as int or char. If one of these fields is required, then it must be wrapped up in a class such as Integer or Character. This to make it easier to perform ``wildcarding'' for matching (see next chapter for details). A wildcard for any object can be the ``pattern'' null which will work for any class, including wrapper classes such as Boolean (on the other hand, what is the wildcard for boolean: true or false?).

The only fields of interest are public, non-static, non-transient and non-final.

An entry class must have a no-args constructor.

4.3. Convenience Classes

The class AbstractEntry is a subclass of Entry, and is designed as a convenience class. It implements methods such as equals() and toString(). It is easy enough to use this for subclasses instead of Entry.

In addtion, Sun's implementation of Jini contains a further set of convenience classes, all subclassed out of AbstractEntry. These require the jini-ext.jar file and are

For example, the Address class contains


String country;
String locality;           // City or locality name.
String organization;       // Name of the company or organization that provides this service.
String organizationalUnit; // The unit within the organization that provides this service.
String postalCode;         // Postal code.
String stateOrProvince;    // Full name or standard postal abbreviation of a state or province.
String street;             // Street address.
You may find these classes useful; on the other hand, what services would like to advertise, and what clients would like to match on is pretty much unknown as yet. These classes are not part of the formal Jini specification.

4.4. Further Uses of Entries

The primary intention of entries is to provide extra information about services so that clients can decide whether or not they are the services they want to use. An expectation in this is that the information in an entry is primarily static. However, entries are objects, and could also implement behaviour as well as state. This could be used to extend the behaviour of a service, beyond that of the service itself.

The main use of this at present is to define the user interface for a service. This topic is looked at in detail in a much later chapter, but in brief: to allow for differing display devices, there may be a need for many user interfaces, or none. If all the possibilities have to be included in the service itself then it will become cumbersome and inflexible. It is better to put this elsewhere, such as in entry objects.

4.5. Summary

An entry is additional information about a service. A service may have any number of entries. Clients requests services by class and by entries, using a simple matching system. There are a number of convenience classes that subclass Entry.


This file is Copyright (©) 1999, 2000 by Jan Newmarch (http://pandonia.canberra.edu.au) jan@ise.canberra.edu.au.
This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v0.4 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.

Back to main


Copyright 1998, 1999, 2000 David Reilly

Privacy | Legal | Linking | Advertise!

Last updated: Monday, June 05, 2006