Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

The architecture of aglets

Find out about the inner workings of aglets, IBM Japan's Java-based autonomous software agent technology

  • Print
  • Feedback

Page 2 of 6

Likewise, an aglet requires a host Java application, an "aglet host," to be running on a computer before it can visit that computer. When aglets travel across a network, they migrate from one aglet host to another. Each aglet host installs a security manager to enforce restrictions on the activities of untrusted aglets. Hosts upload aglets through class loaders that know how to retrieve the class files and state of an aglet from a remote aglet host.

The aglet lifestyle

An aglet can experience many events in its life. It can be:

Created: a brand new aglet is born -- its state is initialized, its main thread starts executing
Cloned: a twin aglet is born -- the current state of the original is duplicated in the clone
Dispatched: an aglet travels to a new host -- the state goes with it
Retracted: an aglet, previously dispatched, is brought back from a remote host -- its state comes back with it
Deactivated: an aglet is put to sleep -- its state is stored on a disk somewhere
Activated: a deactivated aglet is brought back to life -- its state is restored from disk
Disposed of: an aglet dies -- its state is lost forever

Note that every activity besides creation and disposal involve either duplication, transmission across a network, or persistent storage of the aglet's state. Each of these activities uses the same process to get the state out of an aglet: serialization.

Serializing the state...

Aglet hosts use object serialization, available in JDK 1.1 or with the RMI (remote method invocation) add-on to JDK 1.0.2, to export the state of an aglet object to a stream of bytes. Through this process, the aglet object and the tree of serializable objects reachable from it, are written to a stream. An object is serializable if it implements either the Serializable or the Externalizable interface. In a reverse process, the state of the aglet can be reconstructed from the stream of bytes. Serialization allows an image of the heap (the heap's state) to be exported to a byte stream (such as a file) and then reconstructed from that byte stream.

...but not all of the state

The state of the execution stacks and program counters of the threads owned by the aglet are not serialized. Object serialization touches only data on the heap, not the stacks or the program counters. Thus when an aglet is dispatched, cloned, or deactivated, any relevant state sitting on any stack of a running aglet, as well as the current program counter for any thread, is lost.

In theory, a software agent should be able to migrate with all its state: heap, execution stack, and registers. Some will likely consider the inability of aglets to do this as a flaw in the aglet's implementation of mobile-agent theory. This feature of aglets arises out of the architecture of the JVM, which doesn't allow a program to directly access and manipulate execution stacks. This is part of the JVM's built-in security model. Unless there is a change to the JVM, aglets and any other mobile Java-based agent will be unable to carry the state of their execution stacks with them as they migrate.

  • Print
  • Feedback

Resources
  • Previous Under The Hood articles:
  • The lean, mean virtual machine -- Gives an introduction to the Java virtual machine. Look here to see how the garbage collected heap fits in with the other parts of the Java virtual machine.
  • The Java class file lifestyle -- Gives an overview to the Java class file, the file format into which all Java programs are compiled.
  • Java's garbage-collected heap -- Gives an overview of garbage collection in general and the garbage-collected heap of the Java virtual machine in particular.
  • Bytecode basics -- Introduces the bytecodes of the Java virtual machine, and discusses primitive types, conversion operations, and stack operations in particular.
  • Floating Point Arithmetic -- Describes the Java virtual machine's floating-point support and the bytecodes that perform floating point operations.
  • Logic and Arithmetic -- Describes the Java virtual machine's support for logical and integer arithmetic, and the related bytecodes.
  • Objects and Arrays -- Describes how the Java virtual machine deals with objects and arrays, and discusses the relevant bytecodes.
  • Exceptions -- Describes how the Java virtual machine deals with exceptions, and discusses the relevant bytecodes.
  • Try-Finally -- Describes how the Java virtual machine implements try-finally clauses, and discusses the relevant bytecodes.
  • Control Flow -- Describes how the Java virtual machine implements control flow and discusses the relevant bytecodes.