Flylib.com

Books Software

 
 
 

Jini Packages

previous chapter table of contents next chapter
  

Jini Packages

A typical Jini package error looks like this:

Exception in thread "main" java.lang.NoClassDefFoundError:
     net/jini/discovery/DiscoveryListener

The Jini class files are all in jar files. The Jini distribution puts them in a lib subdirectory when they are unpacked. There are a whole bunch of these jar files:

jini-core.jar            mahalo-dl.jar    sun-util.jar
jini-examples-dl.jar     mahalo.jar       tools.jar
jini-examples.jar        reggie-dl.jar    reggie.jar
jini-ext.jar

The jini-core.jar jar file contains the major packages of Jini:

net.jini.core                 net.jini.core.discovery
net.jini.core.entry           net.jini.core.event
net.jini.core.lease           net.jini.core.lookup
net.jini.core.transaction

If the Java compiler or runtime can't find a class in one of these packages, then you need to make sure that the jini-core.jar file is in your CLASSPATH .

The jar file jini-ext.jar contains a set of packages that are not in the core, but are still heavily used:

net.jini.admin      net.jini.discovery
net.jini.entry      net.jini.lease
net.jini.lookup     net.jini.lookup.entry
net.jini.space

If the Java compiler or runtime can't find a class in one of these packages, then you need to make sure that the jini-ext.jar file is in your CLASSPATH .

The sun-util.jar jar file contains the packages from the com.sun.jini hierarchy. These contain a number of "convenience" classes that are not essential but can be useful. These are less frequently used.

A compile or run of a Jini application will typically have an environment set something like this:

JINI_HOME=wherever_Jini_home_is
CLASSPATH=.:$JINI_HOME/lib/jini-core.jar:$JINI_HOME/lib/jini-ext.jar

  

previous chapter table of contents next chapter
  

Chapter 14: Remote Events

Overview

COMPONENTS OF A SYSTEM CAN CHANGE STATE and may need to inform other components that this change has happened . Java Beans and user -interface elements such as AWT or Swing objects use events to signal these changes. Jini also has an event mechanism, and this chapter looks at the distributed event model that is part of Jini. It looks at how remote event listeners are registered with objects, and how these objects notify their listeners of changes. Event listeners may disappear, and so the Jini event mechanism uses leases to manage listener lists.

This chapter also looks at how leases are managed by event sources. Finally, we'll look at how events can be used by applications to monitor when services are registered or discarded from service locators.

  

previous chapter table of contents next chapter
  

Images

User interfaces often contain images. They may be used as icons in toolbars , as general images on the screen, or as the icon image when the application is iconified . When a user interface is created on the client, these images will also need to be created and installed in the relevant part of the application. Images are not serializable, so they cannot be created on the server and exported as live objects in some manner. They need to be created from scratch on the client.

The Swing package contains a convenience class called ImageIcon . This class can be instantiated from a byte array, a filename, or most interestingly here, from a URL. So, if an image is stored where an HTTP server can find it, the ImageIcon constructor can use this version directly. There may be failures in this approach: the URL may be incorrect or malformed or the image may not exist on the HTTP server. Suitable code to create an image from a URL is as follows :

ImageIcon icon = null;
        try {
            icon = new ImageIcon(new URL("http://localhost/images/MINDSTORMS.ps"));
            switch (icon.getImageLoadStatus()) {
            case MediaTracker.ABORTED:
            case MediaTracker.ERRORED:
                System.out.println("Error");
                icon = null;
                break;
            case MediaTracker.COMPLETE:
                System.out.println("Complete");
                break;
            case MediaTracker.LOADING:
                System.out.println("Loading");
                break;
            }
        } catch(java.net.MalformedURLException e) {
            e.printStackTrace();
        }
        // icon is null or is a valid image