Service-oriented architecture using Jini (continued)

Service-oriented architectures are becoming an integral aspect of the IT strategy, offering the ability to register, discover and use services, where the architecture is dynamic in nature. However, the technologies that provide the implementation of these features are by its very core, statically based. In this article, Jini will be used as the implementation of a service-oriented architecture. The reader will be able to understand why Jini is needed, how to use Jini services and solving "real-world" problems with Jini.

The following is part two of an article written by Ron Dearing, Senior Software Engineer of Cysive, Inc. Ron has

worked in the software industry for six years, and is a software engineer at Cysive, Inc. where he works in Product Development on the Cymbio Interaction Server. Ron has a BS in Computer Science from North Carolina A&T. Ron may be reached at rdearing@cysive.com.

Click to return to part one.


Service-oriented architecture using Jini (continued)
by Ron Dearing

Implementing a Jini Service

Defining the Interface
To define a Jini service, you must create a Java interface. The interface may or not be remote depending on the architecture you require. A service proxy can communicate directly with the backend service using RMI or any other protocol.

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface HelloWorldServiceInterface extends Remote
{
public String getMessage() throws RemoteException;
}

Creating the Service Proxy
The service proxy implements the Remote interface and is returned to the client when querying the lookup service. When joining the lookup service, the Jini Service registers the Service Proxy.

import java.io.Serializable;
import java.rmi.RemoteException;

public class HelloWorldProxy implements HelloWorldServiceInterface, Serializable
{
private HelloWorldServiceInterface helloService_ = null;

public HelloWorldProxy()
{
}
public HelloWorldProxy(HelloWorldServiceInterface helloService)
{
helloService_ = helloService;
}

public String getMessage() throws RemoteException
{
try
{
return helloService_.getMessage();
}
catch (RemoteException rex)
{
return ("Unable to communicate with the service: " + rex.getMessage());
}
}

}

Creating the Jini Service
The Jini service is responsible for discovering, and joining the lookup service. The service proxy will be registered with the lookup service and available to clients to query. We will use the utility classes provided by Jini to discover and join the lookup service.

A portion of the code is below:

package examples.service;

import examples.HelloWorldServiceInterface;
import examples.HelloWorldProxy;

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.io.IOException;

import net.jini.core.discovery.LookupLocator;
import net.jini.core.lookup.ServiceID;
import net.jini.discovery.DiscoveryGroupManagement;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.lookup.JoinManager;
import net.jini.lookup.ServiceIDListener;

public class HelloWorldService extends UnicastRemoteObject implements HelloWorldServiceInterface, Runnable
{
// Utility to locate the lookup service
private LookupDiscoveryManager lookupDiscoveryManager_ = null;

private LookupLocator locators_[] = null;

private String groups_[] = DiscoveryGroupManagement.ALL_GROUPS;

// Utility to join the lookup service, once it is found
private JoinManager joinManager_ = null;

// Unique ID of this service return from the lookup service
private ServiceID serviceID_ = null;

public HelloWorldService() throws IOException
{
super();

initialize();
}

private void initialize() throws IOException
{
try
{
lookupDiscoveryManager_ = new
LookupDiscoveryManager(groups_, locators_, null);
}
catch (IOException ioe)
{
System.out.println("Error starting discovery");
ioe.printStackTrace();

throw new IOException("Error starting discovery: " + ioe.getMessage());
}

if (serviceID_ == null)
{
joinManager_ =
new JoinManager
(createProxy(), // service object
null, // service attributes, not needed
new ServiceIDListenerImpl(),
// ServiceIDListener -helper
lookupDiscoveryManager_, // DiscoveryManager
null); // Lease Renewal manager
}
else // rejoin the community
{
joinManager_ =
new JoinManager
(createProxy(), // service object
null, // service attributes, not needed
serviceID_, // service ID returned from reggie

lookupDiscoveryManager_, // DiscoveryManager
null); // Lease Renewal manager
}
}

Create the Client
The client uses a Jini utility, ServiceDiscoveryManager to locate the lookup service and a service that implements the HelloWorldServiceInterface.

import examples.HelloWorldServiceInterface;

import net.jini.lookup.ServiceDiscoveryManager;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.core.lookup.ServiceItem;
import java.rmi.RMISecurityManager;

public static void main(String args[])
{
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}

try
{
ServiceDiscoveryManager sdm = new ServiceDiscoveryManager(null, null);

Class [] name = new Class[]{HelloWorldServiceInterface.class};

ServiceTemplate template = new ServiceTemplate(null, name, null);

ServiceItem serviceItem = sdm.lookup(template,null, Long.MAX_VALUE);

if (serviceItem == null)
{
System.out.println("Can't find the service.");
}
else
{
System.out.println("Found service"); HelloWorldServiceInterface service = (HelloWorldServiceInterface) serviceItem.service;

System.out.println("The helloService said: " + service.getMessage());
}
}
catch (Exception ex)
{
System.out.println("Jini exception: " + ex);
ex.printStackTrace();
}
}

Real-World Problems that Jini Solves

In the static world of our current architecture, we have the opportunity to introduce a dynamic Jini system within our enterprise. Currently, the typical 3-tier architecture is used to implement business requirements, where the first tier is the client, the second tier is the application server and the final tier is the database. Within the application server, there are separate layers that handle the presentation, the business logic, and the persistence layer. Normally, these systems have built their architecture around J2EE technology, which was created to connect and reuse legacy applications. Jini may be inserted in the business logic tier as a mechanism to move towards a dynamic system that can survive application server crashes and heavily loaded servers. For example, the business logic for an Order Entry application may be implemented as a Jini Service, where the OrderEntry service validates the order before sending the Order to a lightweight session bean to communicate to the persistence tier. Jini allows the application server reboots and maintenance upgrades not to effect the tier that is isolated within the Jini system. Transactions are handled through the Jini system and coordinated through the Jini transaction manager.

Summary

The SOA is based on the ability to locate, publish, and invoke services. Web services are an application of the SOA within the IT enterprise. Currently the majority of implementations for Web services, continue to rely on technology that is not well suited for the dynamic environment that is required for creating an effective Web services implementation.

Jini's architecture is built from the ground up that the system must be dynamic, the network is not reliable, and reducing the impact of having an administrator of the system. The Jini system registers services, locate services, and invoke services. Service proxy is downloaded to the client machine dynamically without the overhead of an administrator installing the proxy on the target machine.

Jini is an advanced technology that is easy to grasp. The architecture is ahead of its time and other technologies are starting to mimic the concept found in Jini. Distributed systems are making another surge within the enterprise due to the economies of scale, and the processing power that the enterprise can achieve as opposed to the single server architecture prevalent legacy architectures. Let's start writing Jini services and fulfilling the promise of Web services as a revolutionary platform for delivering services to the user community at large.

Future

A Jini service can be registered as a "first-class" Web service. In the future, we may examine the relationship between UDDI and the Lookup service.

References

  1. http://archive.devx.com/xml/articles/sm100901/sidebar1.asp
  2. http://wwws.sun.com/software/jini/specs/
  3. http://pandonia.canberra.edu.au/java/jini/tutorial/Jini.xml
  4. Edwards, W. Keith. Core Jini 2nd Edition. Upper Saddle River, NJ: Prentice Hall PTR, 2001.
  5. Edwards, W. Keith and Tom Rodden. Jini Example by Example. Upper Saddle River, NJ: Prentice Hall PTR, 2001.

<< Previous Page


Copyright 2002. Reprinted with permission. Cysive, Inc. builds mission-critical business systems for Global 2000 firms to help orchestrate interactions with customers, partners and employees across multiple channels such as web, wireless, voice and Web services.



For more information:

  • Looking for free research? Browse our comprehensive White Papers section by topic, author or keyword.
  • Are you tired of technospeak? The Web Services Advisor column uses plain talk and avoids the hype.
  • For insightful opinion and commentary from today's industry leaders, read our Guest Commentary columns.
  • Hey Codeheads! Start benefiting from these time-saving XML Developer Tips and .NET Developer Tips.

  • Visit our huge Best Web Links for Web Services collection for the freshest editor-selected resources.
  • Visit Ask the Experts for answers to your Web services, SOAP, WSDL, XML, .NET, Java and EAI questions.
  • Couldn't attend one of our Webcasts? Don't miss out. Visit our archive to watch at your own convenience.
  • Choking on the alphabet soup of industry acronyms? Visit our helpful Glossary for the latest lingo.
  • Discuss this article, voice your opinion or talk with your peers in the SearchWebServices Discussion Forums.

Dig deeper on Service-oriented architecture (SOA) implementations

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close