Jini-like
discovery for RMI
Tutorial Details:
Jini-like discovery for RMI
Jini-like discovery for RMI
By: By Philip Bishop and Nigel Warren
Take advantage of Jini's discovery mechanism for RMI development
f you follow Jini developments, you know that Jini clients don't need to know where a service is located; they simply use the discovery mechanism to obtain a proxy to the service they want to use. Conversely in RMI (Remote Method Invocation), you must know the URL of the server you want to use. In this article, we show how you can implement a Jini-like discovery mechanism for RMI, which frees some clients from having to know an RMI server's lookup URL.
Your first thought may be, Why bother to do this in the first place; why not just use Jini? We would agree with this logic, especially for new systems. However, many RMI-based systems still exist, and until Jini is accepted into mainstream Java development, we need to provide more elegant RMI solutions. In fact, the work described here is the result of such a requirement: to develop a Jini service that can also run as a standalone RMI server, but uses Jini-like discovery.
This article is primarily targeted at RMI developers who haven't adopted Jini. By giving insight into what occurs under the Jini hood, we hope you begin to understand how powerful Jini mechanisms are. We certainly don't encourage you to reimplement Jini, but this article may help you understand how these mechanisms work. It may even help you convince your managers or department heads that they should consider Jini as a viable technology for distributed systems.
We won't go into depth about the Jini discovery mechanism, so if you are not familiar with it, we recommend you quickly review Bill Venners's " Locate Services with the Jini Lookup Service ."
Basic RMI and Jini lookups
In RMI, a client must know the location of the server to which it wants to connect. An RMI server's address is in the URL form rmi://:/ , where the port number is the port on which the rmiregistry listens for requests. For example:
Translator service
=(Translator)Naming.lookup("rmi://theHost/SpanishTranslator");
In Jini, a client finds a service using a Jini utility class, such as ServiceDiscoveryManager . In the example below, we create a ServiceTemplate instance with a list of classes; or in our case, the class we want to match -- the Translator.class :
Class [] classes=new Class[]{Translator.class};
ServiceTemplate tmpl=new ServiceTemplate(null,classes,null);
ServiceDiscoveryManager lmgr=new ServiceDiscoveryManager(null,null);
ServiceItem serviceItem =lmgr.lookup(tmpl,null);
Translator service=serviceItem.service;
As you can see from the example, the ServiceDiscoveryManager uses the lookup() method to find any available services that match the ServiceTemplate . You may also associate any number of attributes with a service lookup; we didn't here in order to keep things simple and essential.
Comparing both lookup mechanisms, you will notice that the service location isn't specified in the Jini version. It's worth pointing out that you can specify a lookup service location if required, but not the location of the actual service you want. The Jini model's power is that we don't have to know or care where a service is located.
Having compared both RMI and Jini lookup mechanisms, we can now think about how to access an RMI server in a Jini-like fashion.
A location-neutral RMI lookup
Ideally, we would like to find the first matching instance of a discovered Translator :
Translator service
=(Translator)RMIDiscovery.lookup(clazz,id);
Here, clazz is the RMI service's interface, and id is some unique string to differentiate between server instances implementing the clazz interface. For example, to find a Spanish translator, we use the following:
Class clazz=Translator.class;
String id="Spanish";
Now that we have a high-level idea of how to use RMI discovery, we can start investigating how to implement it. As we attempt to implement a "poor man's" discovery for RMI, we can look at how Jini does it and then adapt those principles/concepts in a way that suits an RMI server and client.
The discovery mechanism
Jini's primary discovery mechanism uses a combination of multicast UDP (User Datagram Protocol) and unicast TCP/IP. In simple terms, this means that a client sends a multicast request packet, which gets picked up by lookup services listening for it. The lookup services make unicast connections back to the client and serialize their proxy down the stream available over the connection. The client then interacts with the lookup service (proxy) to locate the service it wants. Figure 1 illustrates this process.
Figure 1. Jini multicast discovery
There is considerably more to discovery than this, but we're only interested in the key concepts of multicast UDP and unicast TCP/IP.
We won't attempt to implement a standalone RMI lookup service equivalent. Instead we will implement a simple multicast listener/unicast dispatcher that an RMI server can use, effectively making each RMI server act as its own lookup service. On the client side, we write the counterparts for the server-side sockets -- a multicast dispatcher/unicast listener. This means that the participants in Figure 1 become the RMI client and RMI server, shown below in Figure 2.
Figure 2. RMI multicast discovery
The table below describes in more detail the interactions between the RMI client and RMI server.
Interactions between RMI client and RMI server
Server
Client
Start listening on multicast address.
Start ServerSocket to listen for unicast responses from the server.
Begin sending UDP packets to multicast address.
Parse received UDP packet. If valid, connect back to the client via unicast TCP/IP.
Send remote stub to client.
Read remote object from stream.
Close ServerSocket . Stop sending UDP multicast packets.
Start using service.
The discovery protocol
Earlier we outlined how we want an RMI client to discover a server: it would specify an interface class and a unique name to identify a server instance. This is because multiple servers that implement the same interface may be running concurrently.
Before we implement our RMI discovery mechanism, we must define the protocol for message passing between participants. For simplicity, we'll use a delimited string containing all the information a RMI server needs to respond to a matching request. First, we define a protocol header. This prevents the server classes from attempting to fully parse packets that arrive from other sources. The remainder of the message packet will contain the unicast response port, the server's interface class name, and the server instance's unique identifier.
Below is the format of the discovery request message we will use:
,,,
Now let's look at a sample message packet a client might send to discover a Spanish instance of the Translator server. RMI-DISCOVERY is the protocol header, and 5000 is the port number on which the client is listening for responses:
RMI-DISCOVERY,5000,Translator,Spanish
We don't include the client's hostname in the request because that information can be obtained from the UDP packet received on the server. Having defined our message format, we can start implementing the discovery classes.
Implement the server-side classes
Our cunning plan is to write a utility class that RMI servers can use to create their own personal lookup service:
//instantiate RMI server
Remote server=new SpanishTranslator();
//initiates discovery listener
RMILookup.bind(server,"Spanish")
The Remote parameter checks if the server implements the interface the client is trying to discover and whose RMI stub is ultimately serialized back to the client. The String parameter compares the server name with the name in the request packet.
Before going forward, let's quickly recap the server-side classes' responsibilities:
Set up a multicast UDP socket to listen for requests
Check the protocol header when a packet arrives
Parse the message packet
Match the unique server name parameter
Match the interface parameter
If 4 and 5 match, serialize the server's remote stub to the client via unicast TCP/IP socket
Set up a multicast UDP listener
To set up a multicast listener, you must use a known multicast address and port; those in the range 224.0.0.1 to 239.255.255.255, inclusive. Some vendors reserve some of these address/port combinations; for example, Sun reserves Jini the combination 224.0.1.85:4160. (A list of reserved addresses can be found at http://www.iana.org/assignments/multicast-addresses .) Operating on the same frequencies as other vendors is not recommended, so we chose to use the same combination used in the MulticastSocket Javadoc example:
int port=6789;
String multicastAddress="228.5.6.7";
MulticastSocket socket=new MulticastSocket(port);
InetAddress address=InetAddress.getByName(multicastAddress);
socket.joinGroup(address);
byte[] buf = new byte[512];
DatagramPacket packet=new DatagramPacket(buf, buf.length);
socket.receive(packet);
//parse packet etc
socket.leaveGroup(address);
The above example shows how simply you can set up a multicast listener and receive packets on that address/port combination. In the above example, only a single packet can be processed, so we must create a loop around the DatagramPacket creation and socket.receive() ; otherwise only one client will be able to discover the server:
while(active){
byte[] buf=new byte[512];
DatagramPacket packet=new DatagramPacket(buf,buf.length);
socket.receive(packet);
//process packet
}
We could use several strategies to process packets received:
Thread per request : Create a new thread to handle each request
Thread from a thread pool : Use a preinstantiated thread from a (possibly fixed) resource thread pool (see " Java Tip 78: Recycle Broken Objects in Resource Pools ")
Blocking: Only process one request at a time, other r
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Jini-like
discovery for RMI
View Tutorial: Jini-like
discovery for RMI
Related
Tutorials:
|
Displaying 1 - 50 of about 54 Related Tutorials.
|
RMI Plugin for Eclipse
Eclipse Plugin-Language
RMI Plugin for Eclipse...;
The RMI Plug-in for Eclipse is the most comprehensive
solution for developing Java
RMI systems using the Eclipse
platform. Besides generation |
Displaying Hello using RMI
Displaying Hello using RMI, RMI Tutorial
Displaying Hello using RMI
 ... to display Hello message using
RMI. By RMI we mean Remote Method Invocation. RMI |
CORBA and RMI Books
CORBA and RMI
Books
CORBA and RMI
Books... involved in choosing among sockets, HTTP/CGI, remote method invocation (RMI...-by-Value, IDL-to-Java, and RMI-to-IIOP Uses tutorials and client/server |
Eclipse plugin-Network
;
RMI Plugin for Eclipse
Genady's RMI Plug-in for Eclipse is the comprehensive solution for developing RMI applications. Apart from the automatic generation of RMI stubs, the RMI Plugin makes it simple |
Open Source JMS (Java Message Service) Implementations written in Java
|
Welcome to Java Developers paradise!
|
Web Services - Web Services Tutorials
. Enterprise JavaBeans (EJBs)
requires a Remote Method Invocation (RMI) Protocol.... The
proxy looks and feels like the real remote type and exposes the same set... efforts.
Universal Description, Discovery, and Integration (UDDI)
is a protocol |
Lunar Linux 1.6.0 RC2 is released
. Dmidecode was added to aid hardware
discovery - it shows a ton of handy output |
Why Web Services?
and Service Discovery layers) uses
the well defined protocol in the Web Services... advantages like wide range of choices,
reduction in the cost due to competition... to proprietary solutions like EDI/B2B.
Support for Other communication |
CentOS 3.7 is available now
discovery of sensors in
the system and the ability to monitor the sensors.... It provides for dynamic discovery of sensors in
the system and the ability to monitor |
WSMO Studio
for service discovery
components: EPFL QoS based discovery
Integrated WSML |
The Complete Spring Tutorial
;
Part 4
Spring's RMI service example |
Configuration, Resource Usage and StdSchedulerFactory
a name, told its
RMI settings, and handed instances of a JobStore and ThreadPool. The RMI settings include
the Scheduler should create itself as an RMI... create Scheduler instances that are actually proxies (RMI stubs) to Schedulers |
Web 3.0
of Semantic Web describes: ?Web 3.0
makes the discovery of content streams effortless. It introduces automatic
discovery of like-minded users and automatic |
Message Driven Beans
challenges in several areas like:
Asynchrony: A typical RMI-IIOP client has... topics like gotchas and possible actions.
Motivations for messaging: EJB....
Distributed computing network uses the RMI-IIOP protocol to communicate |
Developing Distributed application using Enterprise Java Beans, J2EE Architecture, EJB Tutorial, WebLogic Tutorial.
Remote Method
Invocation (RMI)
Java IDL... and directory services like DNS, LDAP, local file system,
or objects...
.
6. Remote Method
Invocation (RMI |
Openmake Meister For Java
Meister for Java provides the deep dependency discovery needed for exposing.... With Meister for Java's advanced dependency discovery and reporting, every item used |
Free JSP, Free EJB and Free Servlets Hosting Servers
Support: Cocoon
1.8.2
-Struts
-RMI, JMS, JNDI
-WAP (Wireless |
Free JSP, Free EJB and Free Servlets Hosting Servers
1.8.2
-Struts
-RMI, JMS, JNDI
-WAP (Wireless |
Java 5 Features
for Loop
RMI compiler-rmic
Class-data |
Programming Books
CORBA and RMI Books
Java Reference Books
HTML Books |
Continuous Testing
evidence that reducing the
time between the introduction of an error and its discovery |
Java Interview Questions - Page 12
,
RMI tunnelling is a way to make RMI application get through firewall |
Core Java Training Topics
patterns
Java RMI
7. Developing Real-Time Programming |
Definition of Bioinformatics
largely for the identification of new molecular targets for drug discovery... as follows:
bioinformatics refers to database-like
activities... an essential tool for the
biologist just like the microscope. Eventually |
Developer's Jukebox
the Europa Discovery Site as well in the update site dialog.
Use
First open |
Setting up MySQL Database and Tables
Java, JSP Tutorials, Hibernate Tutorials, Struts Tutorials, JSF Tutorials, RMI... is provided with the example code. Many advance topics like Tiles, Struts |
Alvicom LoadManager
, RMI.
Result data is collected in a central repository
This data can |
istory of Bioinformatics
.
Introduction:
The history of biology in
general, B.C. and before the discovery of genetic |
What is Service-Oriented Architecture?
the result of a service
supplied by a provider.
discovery
Service |
Java Compiler
of Java Compiler. When we write any program in a text editor like
Notepad, we use... discovery process
-processorpath <path> Specify where to find... and
gives the Syntax error, if there is any. Like in this example, we haven't |
Java Compiler
of Java Compiler. When we write any program in a text editor like
Notepad, we use... discovery process
-processorpath <path> Specify where to find... and
gives the Syntax error, if there is any. Like in this example, we haven't |
Java Compiler
of Java Compiler. When we write any program in a text editor like
Notepad, we use... processors to run; bypasses default discovery process... the program and
gives the Syntax error, if there is any. Like in this example, we |
What is the use of java?
on a different computers,
supports various Operating System like Windows PCs... Interface TM ("J.N.D.I.") API, Java RMI,
and Java Remote Method Invocation over Internet Inter-ORB Protocol
Technology (Java RMI-IIOP |
New Features of JAVA SE 6.
Enhancements has been made to the JMX API in Java SE 6 like : JMX API now completely... deleted in JAVA SE 6 and JPDA has been added. Some new Methods are included like... in java.lang.Class like : getInterfaces(), getClasses(), getConsturctors(), getMethod |
Design patterns interview questions1
be accessed from the client side. This would result in considerable RMI |
Downloading and Installing Apache Geronimo Application Server
org.apache.geronimo.framework/rmi-naming/2.1/car
started in .000s
Module 3/64.../
into the browser, your browser should look like following screen shot:
In the next |
Java EJB 3.0 Tutorials
micro system added the features like annotation in jdk 5.
The main objectives.... Annotations behaves like the meta
 ...
Tracking
Session
Tracking Example
RMI |
Open Source Books
of Pauling's foundational work that made possible the discovery of the structure of DNA.
The actual discovery was made Francis Crick and James Watson... like SOAP, WSDL, UDDI which will provide solutions to the industry for many more |
Database books Page20
Internet standards like WSDL(Web Services Description Language),
Simple Object Access Protocol (SOAP), and Universal Description Discovery |
Servlet Tutorials Links
from a simple "Hello World" Servlet to advanced Servlet features like session..., and act as RMI servers, as well as a class to help applets communicate... (like Apache) in order to use java, servlets and JSPs to generate dynamic content |
JDBC (Java Database Connectivity) -Tutorials
the same Web application using Java RMI
to retrieve the data from a single... can combine with Java RMI
to develop distributed enterprise-scale... direct socket connections with the database like Oracle Thin
JDBC Driver |
Java SE 6
to return the key value pair like
navMap.put(1, "January"); whereas...
Enhancements has been made to the JMX API in Java SE 6 like : JMX API now completely... deleted in JAVA SE 6 and JPDA has been added. Some new Methods are included like |
Serializable Exception
such as RMI AND CORBA used to transmit their parameter across
the network... that is not serialized like your collection element, these
method throws not serialized |
Eclipse Plunging/Tool
;
Discovery
Machine Gear Eclipse Plug-in
The Discovery Machine Eclipse Gear Plugin is a wizard which aids a developer
in calling a Discovery... stand-bys, you'll find
enough to keep you interested and enough to feel like |
Struts integration with EJB in JBOSS3.2
as function bean called in RMI-IIOP style from Enterprise container. Two types... in RMI style from Enterprise
container in Enterprise data store. Two types... technology
( Object-Relational Mapping Technology … like Hibernate |
Struts integration with EJB in WEBLOGIC7
can be defined as function bean called in RMI-IIOP style from Enterprise..., invoked in RMI style from Enterprise container in Enterprise data store. Two... ( Object-Relational Mapping Technology …like Hibernate. and Hibernate |
Misc.Online Books
such as Galeon and Camino, and chat clients like ChatZilla and JabberZilla... that made possible the discovery of the structure of DNA.
The actual discovery was made Francis Crick and James Watson, and is famously chronicled |
JSF Tutorial for Beginners
the backing from all the big players in J2EE field, like
SUN,IBM,ORACLE,WEBLOGIC... of the number of advanced features like 'Intelli-sense', class
browser... be,equally numerous programmers prefer to use the visual tools like
JBuilder, JDeveloper |
IT Training in India
to your logic using RMI or web services,
mailing facilities and various options... to many others
like MS Access and price, performance advantages over unnecessarily heavy
database servers like Oracle, DB2 and SQL Server.
  |
|
|
|