|
|
|
Advertisement
|
Interaction between aglet and host
An aglet interacts with its environment (its aglet host) through an
AgletContext object. An aglet can obtain a handle to its
context by invoking getAgletContext(), a method it
inherits from base class Aglet. The aglet context has
methods such as createAglet() and
retractAglet(), which allow an aglet to add new aglets (or
get an old aglet back) to its local host.
Interaction between aglets
To interact with each other, aglets do not normally invoke each other's
methods directly. Instead they go through AgletProxy
objects, which serve as aglet representatives. For example, if a
BossAglet wishes to make a request of an
EmployeeAglet, the BossAglet obtains a handle
to a proxy object that "represents" the
EmployeeAglet. The BossAglet then makes a
request by invoking a method in the EmployeeAglet's proxy,
which in turn forwards the request to the actual
EmployeeAglet.
The AgletProxy class contains methods that allow aglets
to request other aglets to take actions, such as
dispatch(), clone(),
deactivate(), and dispose(). The aglet that
has been requested to take an action can comply, refuse to comply, or
decide to comply later.
The proxy also allows an aglet to send a message, either
synchronously or asynchronously, to another aglet. A
Message object is supplied for this purpose; it carries
a String to indicate the kind of message plus one other
optional piece of data, either a String or one of Java's
primitive types. To send a message you create a Message
object and pass it as a parameter to the sendMessage() or
sendAsynchMessage() method of the proxy object.
An aglet must go through a proxy object to interact with an aglet,
even if both aglets are in the same aglet host. The reason aglets
aren't allowed to directly interact with one another is that the
aglet's callback and initialization methods are public.
These methods should be invoked only by the aglet host, but if an aglet
could get a handle to another aglet, it could invoke that aglet's
callback or initialization methods. An aglet could become very
confused if another aglet inadvertently or maliciously invoked these
methods directly.
The aglet being represented by a proxy might be local or remote, but
the proxy object is always local. For example, if a
BossAglet in Silicon Valley wants to communicate with
an EmployeeAglet on a South Pacific island, the
BossAglet gets a local AgletProxy object,
which represents the remote EmployeeAglet. The
BossAglet merely invokes methods in the local proxy, which
in turn communicates across the network to the
EmployeeAglet. Only aglets, not proxies, migrate across
the network. A proxy communicates with a remote aglet that it represents
by sending data across the network.
You get a proxy to an aglet in one of three ways, each of which involves invoking a method in the context object:
createAglet(). (This returns a proxy object.)
getAgletProxies().
getAgletProxy(). (Every
aglet, upon creation or cloning, is assigned a globally unique aglet
identifier.)
Security
Mobile-agent systems, such as aglets, require high levels of security,
because they represent yet another way to transmit a malicious
program. Before aglets can be used in practice, there must be an
infrastructure of aglet hosts that prevent untrusted aglets from doing
damage but provide trusted aglets with useful access to the host's
resources. Security is amply provided for in Java's intrinsic
architecture and in the extra security features of JDK 1.1, but as with
applets, some attacks (such as denial of service by allocating memory
until the host crashes) are still possible. Currently, the aglet hosts
from IBM (named Tahiti and Fiji) place very severe security
restrictions on the activities of any aglet that didn't originate
locally.
Next month
Will aglets become as ubiquitous as their plastic cousins, which
quietly perch on the ends of everyone's shoelaces? Aglets represent a
good example of innovation on top of Java's network-oriented
architecture, but what new benefits do they offer developers and
end users that client/server, applets, and servlets don't already
offer? In next month's Under The Hood, I will analyze the real-world
utility of mobile agents in general and aglets in particular.
About the author
Bill Venners has been writing software professionally for 12 years.
Based in Silicon Valley, he provides software consulting and training
services under the name Artima Software Company.
Over the years he has developed software for the consumer electronics,
education, semiconductor, and life insurance industries. He has
programmed in many languages on many platforms: assembly language
on various microprocessors, C on Unix, C++ on Windows, Java on the Web.
He is author of the book: Inside the Java
Virtual Machine, published by McGraw-Hill. You can reach
him at bv@artima.com.
This article was first published under the name Under the Hood: The architecture of aglets in JavaWorld, a division of Web Publishing, Inc., April 1997.
|
Sponsored Links
|