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 5 of 6

onCloning() -- called before a clone operation
onDispatch() -- called before a dispatch
onReverting() -- called before a retraction
onDeactivating() -- called before a deactivation
onDisposing() -- called before a dispose operation (Unlike real life, an aglet can throw an exception if it doesn't want to die.)

For each of these processes, the Aglet class has a corresponding method that triggers the action: clone(), dispatch(), retract(), deactivate(), and dispose(). Some time after these are called, the aglet host will invoke the appropriate callback method.

Each time an aglet begins execution at a host, the host invokes an initialization method on the aglet. When the initialization method returns, the host invokes run(). Depending on the event that precipitated the aglet's new life, the aglet host will choose to invoke one of these four initialization methods:

onCreation() -- called the first time an aglet springs to life
onClone() -- called on a clone after a clone operation
onArrival() -- called after a dispatch or a retraction
onActivation() -- called after an activation

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.

  • 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.