8/3/2019 The Jini Technology Vision
1/13
The Jini Technology Vision
Print-friendly Version
Articles Index
Technology and the K Virtual Machine
By Michael DeleoSeptember 1999
This article describes a demonstration featuring 3ComPalm Pilots, Lego Mindstorm miniature tanks, and Jini
technology presented at this year's JavaOne Developer
Conference. This article explores some of thechallenges solved by the demonstration developers
with Jini technology and the K Virtual Machine
(KVM).
Computing technology has undergone dramatic
changes over the past 35 years. Computers are smaller,faster, and more energy efficient. The power that once required a mainframe or minicomputer
housed in a frigid, air-conditioned computer room is now contained in a small, consumer
device you can carry in your shirt pocket. Such devices are finding their way into our
everyday lives. As they do so, they contain increasing amounts of important, personalinformation. Small portable devices offer many benefits to users, but they present a new set of
difficulties for developers. One difficulty is connecting these devices into a network. Small
consumer devices demand a flexible, resilient networking architecture so that users can dothings like use personal digital assistants to exchange information with existing networks and
other computers.
For the developer, the most noticeable difficulty is the scarcity of resources inherent in tiny
consumer devices. Produced by the thousands (or even millions), these devices usually use
low-cost, low-performance processors with minimal memory. Although this slimmed-downhardware translates into lower unit cost for the manufacturer and eventually the consumer, it
ultimately puts the squeeze on the software developer. It forces the developer to write
applications in languages such as C or assembler that will generate small, efficient programs.
Unfortunately, "writing close to the hardware" means these applications have a lot ofimplementation dependencies. Application portability, code reuse, and, ultimately, the
developer suffer.
The K virtual machine (KVM) used with Jini connection technology provides excellent
solutions to these problems. Jini technology provides a flexible, resilient network architecture
to easily link together small computer devices onto a network. And KVM provides a Java
http://java.sun.com/jsp_utils/PrintPage.jsphttp://java.sun.com/jsp_utils/PrintPage.jsphttp://java.sun.com/developer/technicalArticles/http://java.sun.com/developer/technicalArticles/http://java.sun.com/jsp_utils/PrintPage.jsphttp://java.sun.com/jsp_utils/PrintPage.jsphttp://java.sun.com/jsp_utils/PrintPage.jsphttp://java.sun.com/developer/technicalArticles/http://java.sun.com/jsp_utils/PrintPage.jsp8/3/2019 The Jini Technology Vision
2/13
runtime environment tailor-made for small devices, making application portability and codereuse possible.
This article presents the use of Jini technology and the KVM in a simple and concise manner.However, to understand the technical aspects of the article, you should be reasonably
comfortable with the following technologies:
Java programming and debugging Network programming using sockets Java Remote Method Invocation (RMI)
You should also understand the C programming language at a basic level.
Jini Connection Technology
Jini Connection Technologyprovides networking mechanisms that let devices connect to one
another to form an impromptu community -- a community that puts itself together withoutany planning, installation, or human intervention. Each device provides services that otherdevices in the community may use, in addition to its own interface. A service can be
implemented anywhere in the community. Reliability and compatibility are ensured because
each service provides everything needed to interact with it.
K Virtual Machine
TheK virtual machine(KVM) is an entirely new Java runtime environment. Built from the
ground up, it provides an extremely lean implementation of the Java virtual machine1for
devices with a small memory footprint. The core of the Java 2 Micro Edition (J2ME), the
KVM works for 16/32-bit RISC/CISC microcontrollers with a miniscule total memory: a fewhundred kilobytes at most; sometimes fewer than 128 Kbytes of RAM.
KVM and Jini Technology in Action
In his keynote speech to attendees at this year's JavaOne Developer Conference, James
Gosling presented several Java technology demonstrations including a Jini Technology TankDemo. In this demo, players using3Com Palm Pilotsplayed a robotic game of laser tag with
remotely controlled miniature tanks built from aLego Mindstorms Robotics Invention kit.
The Palm Pilots and tanks were connected into an impromptu network using Jini connection
technology. A simple Java applet executing in the Palm Pilots' KVM lets players maneuver
their own tanks around obstacles, tag another tank, and move their tanks out of harm's way.
Sounds like fun. But the demonstration represents many real world possibilities, especiallyapplications that employ hand-held and other embedded devices, with different networking
requirements. This article describes several of the more complicated technical challenges
involved in building the demonstration. Each of the involved technologies and its use isexplained. Where appropriate, Java source code samples are provided. The objective is to
http://java.sun.com/developer/onlineTraining/Programminghttp://java.sun.com/developer/onlineTraining/Programminghttp://java.sun.com/docs/books/tutorial/networking/http://java.sun.com/docs/books/tutorial/networking/http://java.sun.com/products/jdk/1.2/docs/guide/rmi/http://www.sun.com/jini/http://www.sun.com/jini/http://java.sun.com/products/cldc/index.jsphttp://java.sun.com/products/cldc/index.jsphttp://java.sun.com/products/cldc/index.jsphttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/Javatanks.html#TJVMhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/Javatanks.html#TJVMhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/Javatanks.html#TJVMhttp://www.palm.com/http://www.palm.com/http://www.palm.com/http://legomindstorms.com/http://legomindstorms.com/http://legomindstorms.com/http://legomindstorms.com/http://www.palm.com/http://java.sun.com/developer/technicalArticles/jini/JavaTanks/Javatanks.html#TJVMhttp://java.sun.com/products/cldc/index.jsphttp://www.sun.com/jini/http://java.sun.com/products/jdk/1.2/docs/guide/rmi/http://java.sun.com/docs/books/tutorial/networking/http://java.sun.com/developer/onlineTraining/Programming8/3/2019 The Jini Technology Vision
3/13
show how Jini technology and KVM were used to handle this particular project. Anotherobjective is to show their possible uses in developing and deploying applications for small
consumer devices connected to a network.
Architectural Overview
Now for a look at the components that were used in the demonstration.
The Hardware Network
The diagram illustrates a network that includes Lego Mindstorms tanks, Palm Pilots,
workstations, and other hardware components.
8/3/2019 The Jini Technology Vision
4/13
The workstation communicates with the tanks by infrared (IR)
transmission. The workstation is connected to a device called an IR tower,which contains an IR transceiver. Each tank also has an IR transceiver,and each Palm Pilot sits in a HotSync cradle. A serial cable attached to the
cradle connects a Palm Pilot to a terminal concentrator. A terminalconcentrator provides a simple way of connecting several devices to a
TCP/IP network. The concentrator connects to the workstations throughan ethernet connection.
8/3/2019 The Jini Technology Vision
5/13
The Jini Network
That's the hardware network. But there's also a Jini network that connectsthese devices so they can take advantage of each other's services as
illustrated below. The illustration also provides links to full source codelike that provided for the key components of the demonstration.
8/3/2019 The Jini Technology Vision
6/13
8/3/2019 The Jini Technology Vision
7/13
The central element of the Jini network is the Jini lookup server. Thelookup server can reside anywhere on the network that a suitable JVM
exists, that is, one that supports the Java 2 platform and Java RemoteMethod Invocation. The lookup server manages a central registry ofservices that are available in the network. Also running in the workstationis a thin Java server process known as the "tank daemon". The tank
daemon handles the low-level details of IR communication between a tankand a workstation. Because they don't run a Java virtual machine, the
tanks need an intermediary to link them into the Jini network. Thisintermediary is called a "Jini proxy." This is a simple Java object that is
instantiated by the tank daemon when a tank is switched on. Once a tankis turned on it can be commanded to do something by making a method
call on the tank proxy object.
The Palm Pilots also require a proxy object, the palm proxy, to become
part of the Jini network. The palm proxy is also a Java object. It isinstantiated by a server process called the "palm daemon." The palmdaemon listens for connections from the Palm Pilot. When a tank proxy iscreated for a tank, the proxy can participate in a pair of Jini protocols
called "discovery" and "join." These protocols help find one or morelookup servers for a device. The protocols also allow a device to upload its
service interface to a lookup server. This makes the device's servicesavailable to other members of the Jini network. The palm proxies
represent the Palm Pilot devices as clients in the Jini network. Theseproxies also participate in the discovery protocol in order to find lookup
servers.
Once a lookup service is found, the Palm proxy searches it for services
that implement a "drivable" interface. When it finds an available tankproxy, the palm proxy downloads the tank service's interface from thelookup server. Then it can start making method calls on the tank proxyobject.
The lookup server uses a leasing mechanism to maintain a list of active
services. After a service successfully uploads its interfaces to the lookup
server, it receives a ServiceRegistration object. The ServiceRegistration
object can then be used to get the Lease object. This object must be usedto periodically renew a service's lease. If the service fails to renew itslease, it is dropped from the list of active services. This could happen, for
example, if a tank is switched off or moved out of range of an IR tower.Eventually the tank's service lease expires. At that point, the tank is
automatically removed from the Jini network.
8/3/2019 The Jini Technology Vision
8/13
Challenges and Solutions
Challenge #1 -- Communicating with a Lego Mindstorms RoboticTank
At the heart of the Lego Mindstorms Robotic Invention System is the RCXor "brick". The brick is a microcontroller that can receive data from
various input sensors, process data, and signal motors to turn on and off.Furthermore, the brick is programmable -- you can write a sensing or
control program on a workstation, compile it, and then download it by IRtransmission to the tanks.
This same communication mechanism can be used to communicate
between an application and the brick. Using a serial connection, an
application running on the workstation can send data to and receive data
from the brick.
Here's how the program communication with the tanks was set up:
A Java object was created to model the brick. A Java object and a supporting class were created to handle the
low-level details of communicating with the brick.
We've provided a sample class,IRTest, that shows how to instatiate anduse the brick object to communicate with the tank. The logic in IRTest
mirrors some of the logic to the tank daemon.
The Brick Object: The physical brick was modeled as abrick object. The
brick object communicates with the serial port using theJavaCommunication API.
This allows abstraction of the hardware and its low-level details, which in
turn creates small, manageable objects. Ultimately, this approach createsan application with no particular operating system or hardware platform
as its target.
The IR Protocol Object: TheIR Protocol Objectuses the JavaCommunications API to handle low-level details of IR communication withthe physical brick through the IR tower. Asupporting classwas created to
assist the IRProtocol object in the asynchronous receipt of messages fromthe brick.
The Lego Mindstorms Kit includes a sample graphical programming
http://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRTest.javahttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRTest.javahttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRTest.javahttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/Brick.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/Brick.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/Brick.htmlhttp://java.sun.com/products/javacomm/reference/docs/http://java.sun.com/products/javacomm/reference/docs/http://java.sun.com/products/javacomm/reference/docs/http://java.sun.com/products/javacomm/reference/docs/http://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRProtocol.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRProtocol.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRProtocol.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/MessageBuffer.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/MessageBuffer.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/MessageBuffer.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/MessageBuffer.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRProtocol.htmlhttp://java.sun.com/products/javacomm/reference/docs/http://java.sun.com/products/javacomm/reference/docs/http://java.sun.com/developer/technicalArticles/jini/JavaTanks/Brick.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/IRTest.java8/3/2019 The Jini Technology Vision
9/13
environment designed for people with little or no software experience.This tool provides an easy way to create and install simple programs on
the brick. However, the level of program flexibility and complexity was toolimited for this project. To fill its needs, the team selected a softwarepackage called "Not Quite C" (NQC), developed by David Baum andavailable under the Mozilla Public License. NQC, a simple programming
language with C-like syntax, available in binary form for Macintosh, Linux,and Windows, was used to create and install this application.
As an example, we've provided thesource codefor the application we
installed on the brick.
Challenge #2 -- Developing a Remote Control Application
The next challenge was to find a suitable client to control the Lego
Mindstorms tanks. The hardware platforms to be used could not bedetermined ahead of time. Because of that we needed client software that
could run on any platform with little or no modification. At that time,several companies, including Sun, were in the early stages of developing
extremely small Java virtual machines for consumer devices.
Among Sun Microsystems Laboratories research
projects was the Spotless system, anexperimental Java system for the Palm
Connected Organizer. KVM technology, theperfect platform for the project's client, grew
out of this system.
A remote-control application written in the Java
programming language and running in KVM forthe Palm III and Palm V could later run on
newer embedded devices without any codechanges. The requirements were simple: A user
would need the ability to move the tankforward, backward, turn left, right, or stop. This
functionality mapped simply into a Java applet with buttons arranged
much like the buttons on your television set's remote control.
In response to each button click, the applet sends a single-byte commandover a socket connection to a server process running on a networked
workstation. Here is the source code.
Challenge #3 -- Creating a Flexible, Multi-User Environment
http://java.sun.com/developer/technicalArticles/jini/JavaTanks/tank.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/tank.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/tank.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/TankRemote.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/TankRemote.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/TankRemote.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/tank.html8/3/2019 The Jini Technology Vision
10/13
The final challenge was connecting the tanks and the Palm Pilots into aflexible, dynamic network. The tanks had to be able to easily plug into the
network, making their "drivable" services available. The Palm Pilot clientsalso needed to automatically connect to the network and find somethingto drive. Both devices needed to be easily removable from the network, atany time, without affecting the rest of the network.
Jini technology was the obvious choice for addressing these challenges.
The Jini lookup service provided a central registry of services for thenetworked devices. When switched on, the Lego tanks used the discovery
and join protocol to find a lookup server and upload the tanks' serviceinterface. Similarly, the Palm Pilot used the discovery protocol to find a
lookup server and tanks. It then searched for a suitable, matching serviceinterface.
Sending and receiving messages to a single tank was reasonably
straightforward. Communicating with several tanks simultaneously provedto be a bigger challenge. The tank daemon only lets a single device
transmit at any given moment. If more than one device sends data viainfrared at the same time, it results in collisions and a loss of data.
To solve this problem, the tank daemon implements a protocol that allowsmultiple clients to communicate with individual tanks. The protocol used
the brick object. An additional server process, the palm daemon, wasdeveloped to accept incoming socket connections from the Palm Pilots.
To become part of a Jini network and make itself known to the rest of thenetwork, a device or service must participate in the Jini discovery
protocol. It must also register itself to a Jini lookup service. The Jinidiscovery protocol lets a device or service obtain a RMI reference to the
lookup service. Once obtained, this reference lets the service registeritself. The service can then be found and used by other members in the
network.
Smaller devices, like the Lego Mindstorms brick and the Palm Pilot, may
not have a full-featured Java virtual machine, which supports advancedfeatures, like RMI. In fact, many devices may not have a virtual machine
at all. This does not mean, however, that these devices cannot takeadvantage of Jini technology. The only requirement is that there be a Java
virtual machine somewhere on the network and that the devices cancommunicate with it. In this case, the tanks take advantage of a full JVM
resident on a local workstation. At startup, the tanks announce
8/3/2019 The Jini Technology Vision
11/13
themselves, one at a time, to the tank daemon. The tank daemon getsthe announcement and it creates a Jini proxy object. This proxy object
represents the physical tank. The proxy participates in the Jini discoveryand join protocol to find and register its interface to the Jini lookup server.This makes the tank's services available to other members of the network.
The Palm Pilots, which have a Java virtual machine but no RMI, similarlyconnect themselves to the Jini network. After a reliable TCP/IP connection
has been established over a serial line, the Palm Pilots use the KVM'ssocket class to connect to the Palm server process described earlier.
As client socket connections are accepted, apalm proxy objectis created.This object represents the Palm Pilot in the Jini network and participates
in the discovery protocol to find a lookup server. Once the object finds thelookup server, it searches for an available tank. The tank's interface is
then downloaded into the palm proxy's local virtual machine.
Because the palm proxy has a basic understanding of the tank proxy'sinterface, it can map commands sent from the Java applet running on the
Palm Pilot to method calls on the tank proxy. The tank proxy, in turn,forwards the transmitted commands to its associated specific tank.
Conclusion
Developing applications for embedded devices can be difficult. Limited
computing resources and flexible networking requirements presentinteresting roadblocks for software developers to overcome. Jini
technology and the K Virtual Machine helps developers get around theseobstacles by letting them focus on application-level issues rather thanlow-level hardware and connectivity details.
The Achievements
The demonstration described in this article showed that the K VirtualMachine can be used in today's embedded devices to develop and deploy
portable, real-world applications. It also showed that Jini technology gives
developers a resilient and flexible networking fabric into which embeddeddevices can be easily woven.
Lessons Learned
The success of this project taught the developers of the demonstration
several things:
http://java.sun.com/developer/technicalArticles/jini/JavaTanks/PalmProxy.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/PalmProxy.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/PalmProxy.htmlhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/PalmProxy.html8/3/2019 The Jini Technology Vision
12/13
Successful application developers will be those who writeapplications that run anywhere.
Writing applications targeted for multiple hardware platformdemands building in as few implementation details as possible.
The K Virtual Machine lets you use the Java programming languageto write reusable, maintainable objects for embedded devices.
The ability to represent devices and services as objects is veryimportant. The amount of information that can be stored on a given
amount of silicon roughly doubles every year. This trend makes itpossible to implement complex systems in single chips. These
systems can be interconnected to form larger, more complexsystems. In a Jini network, each of these devices and services is
treated as an object -- an object that can be moved throughout thenetwork. Developers no longer need to concern themselves with the
complexity of a system but rather how objects interact.
While this project may appear to many to be a major undertaking, thedevelopers involved in the project worked on the separate technologies,like the KVM and Jini technology, in distinct stages. Ultimately they built
on the experience they gained from doing smaller sub-projects. At keypoints during the project, technologies and the understanding of those
technologies were combined into something more complex. As a result wealso learned the most important lesson of all: the best way to evolve a
technology is to take on something small and do it very well.
Download the Demonstration
We've provided a compressed .tar file that contains all the files, including
documentation, for recreating the demonstration.tankdemo.tar.gz(Todownload, hold down Shift key and click)
More Information:
K Virtual Machine Jini Device Architecture Specification Lego Mindstorms Robotics Invention System Programming the Lego Brick Using NQC Palm Computing Platform Development Zone Jini Technology Architectural Overview Java Object Serialization Spotless System Page Lego Mindstorms Internals RCX Internals
http://java.sun.com/developer/technicalArticles/jini/JavaTanks/tankdemo.tar.gzhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/tankdemo.tar.gzhttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/tankdemo.tar.gzhttp://java.sun.com/products/cldc/index.jsphttp://java.sun.com/products/cldc/index.jsphttp://www.sun.com/jini/specs/devicearch1_1.pdfhttp://www.sun.com/jini/specs/devicearch1_1.pdfhttp://legomindstorms.com/http://www.enteract.com/~dbaum/lego/nqc/index.htmlhttp://www.palm.com/devzone/http://www.palm.com/devzone/http://www.sun.com/jini/whitepapers/architecture.htmlhttp://java.sun.com/products/jdk/1.2/docs/guide/serialization/http://www.sun.com/research/spotless/http://www.crynwr.com/lego-robotics/http://www.crynwr.com/lego-robotics/http://graphics.stanford.edu/~kekoa/rcx/http://graphics.stanford.edu/~kekoa/rcx/http://graphics.stanford.edu/~kekoa/rcx/http://www.crynwr.com/lego-robotics/http://www.sun.com/research/spotless/http://java.sun.com/products/jdk/1.2/docs/guide/serialization/http://www.sun.com/jini/whitepapers/architecture.htmlhttp://www.palm.com/devzone/http://www.enteract.com/~dbaum/lego/nqc/index.htmlhttp://legomindstorms.com/http://www.sun.com/jini/specs/devicearch1_1.pdfhttp://java.sun.com/products/cldc/index.jsphttp://java.sun.com/developer/technicalArticles/jini/JavaTanks/tankdemo.tar.gz8/3/2019 The Jini Technology Vision
13/13
_______1 As used on this web site, the terms "Java virtual machine" or "JVM"
mean a virtual machine for the Java platform.