The Artima Developer Community
Sponsored Link

Browse User Interfaces for Jini Services
Build a JFC-Based Application for Browsing and Launching Jini Services
by Jeffrey Peden
First Published in JavaWorld, March 2001

<<  Page 2 of 7  >>

Advertisement

Getting Started

Before we get too far along in the development process, you should first make sure that your development environment is properly set up. While Jini is compatible with J2SE 1.2.2 and above, I recommend using JDK 1.3 from Sun on either Linux or Windows 2000.

You'll also need the Jini Technology Starter Kit 1.1. We'll be using the jini-core.jar and jini-ext.jar libraries for development. In addition, you'll need a Jini lookup server somewhere on your network.

Finally, our project will use the ServiceUI 1.0 API from the Jini.org community, as well as a utility class from the Jini-Tools project. Check out the Resources section for locations of these items.

TimeService Interface

The most important component of any Jini service is its interface. The interface provides a layer of abstraction, under which services can choose varying implementations, while clients only need to know how to operate on an instance of the interface.

Designing truly generic service interfaces is not a simple matter. As a rule of thumb, check first with the Jini.org community to see if others have crafted an interface that suits your needs. If they have not, you may want to start a community project, working with others to craft a pseudostandard interface or set of interfaces that provide a generic API for services such as yours. There may be times when a proprietary interface is the best course of action, but if you plan to introduce a service that others could use, keep the community in mind.

That said, our service here offers little practical use, so we will be crafting a proprietary interface. Below is the code for our interface:


public interface TimeService extends java.io.Serializable{
    public java.util.Date getTime() throws java.rmi.RemoteException;
}

That interface declares a single method, getTime(), which returns an instance of java.util.Date.

You'll notice that the interface extends java.io.Serializable instead of java.rmi.Remote. For that example, we'll use a specific type of Jini service in which the entire service is contained within the proxy. However, we've already made sure to declare that our single method may throw java.rmi.RemoteException. That is done so that we may later implement a remote version of the service, while still allowing client code to interact with the TimeService interface. Although we won't be using it in this example, I'll define the interface for the remote version of TimeService below:


public interface RemoteTimeService extends TimeService, java.rmi.Remote{

}

That interface defines no new methods (although it could), and simply extends both the TimeService interface and java.rmi.Remote. If a service were to implement that interface, the RMI stub would be substituted as a proxy when registered with the Jini lookup service.

<<  Page 2 of 7  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us