What’s an Agent? The AI-based Definition An agent is that assists people and acts on their behalf. Agents work by allowing people Java Mobile Agents to delegate work that they could have done, to the agent software.

Danny B. Lange ü Autonomous ü Social Director, Agent Technology ü Goal-driven üAdaptive ü Reactive ü Mobile General Magic, Inc.

myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

What’s an Agent? Objective and Agenda The “Object” Definition What are mobile agents? An agent is an object with its private thread of What are they good for? execution, a.k.a. an active object. How do I get started? –Definitions ü Thread-based programming (autonomous) –Seven Good Reasons ü Conditional statements (goal-driven) –Applications ü Objects with methods (reactive) –Java ü Object interaction (social) –Getting Started with Aglets ü Exception handling (adaptive) –Future ü Serializable and Persistent (mobile) myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

What’s a Mobile Agent?

– Not bound to the host where it begins DEFINITIONS execution. – Unique ability to transport itself from one host in a network to another. A mobile agent moves to a host that contains an object with which the agent wants to interact, then takes advantage of being in the same host as the object. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

1 Agent is Travelling from Mobile Agent Computer to Computer

Computer Agent Agent Computer Principals

Interface Network Implementation

Agent State Identifier Computer myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Place

• Engine: Workhorse and virtual machine for MOBILE AGENT MODEL one or more places • Resources: Databases, processors, and other services provided by the host • Location: The network address of a given place • Principals: Those legally responsible for the operation of a place myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Mobile Agent Place

• State: needed for the agent to resume computation after travelling Host • Implementation: needed for location- independent agent execution Agents • Interface: needed for agent communication • Identifier: needed to recognize and locate Place Resources traveling agents • Principals: needed to determine legal and Engine moral responsibility myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

2 Seven Good Reasons for Using Mobile Agents - #3 • They encapsulate protocols SEVEN GOOD REASONS > As protocols evolve to accommodate new efficiency or security requirements, it is a cumbersome if not impossible task to upgrade protocol code properly. > Mobile agents are able to move to remote hosts in order to establish "channels" based on proprietary protocols.

myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Seven Good Reasons for Using Seven Good Reasons for Using Mobile Agents - #1 Mobile Agents - #4 • They reduce the network load • They execute asynchronously and autonomously

App Service App Service Send agent RPC-based

Host A Host B App Service Disconnect

App Service

Mobile Agent-based App Service approach Reconnect and return myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Seven Good Reasons for Using Seven Good Reasons for Using Mobile Agents - #2 Mobile Agents - #5 • They overcome network latency • They adapt dynamically > Critical real-time systems such as robots in > Mobile agents have the ability to sense their manufacturing processes need to respond to execution environment and react autonomously changes in their environments in real time. to changes. > Mobile agents offer a solution, since they can > Multiple mobile agents possess the unique be dispatched from a central controller to act ability to distribute themselves among the hosts locally and directly execute the controller's in the network in such a way as to maintain the directions. optimal configuration for solving a particular problem. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

3 Seven Good Reasons for Using So What About Mobile Agents - #6 Mobile Agent Applications? • They are naturally heterogeneous > Network computing is fundamentally • There are no “Mobile Agent Applications” heterogeneous, often from both hardware and software perspectives. > As mobile agents are generally computer- and • But there are plenty of applications that highly transport-layer-independent, and dependent benefit from using mobile agents only on their execution environment, they provide optimal conditions for seamless system integration. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Seven Good Reasons for Using Applications... Mobile Agents - #7 • They are robust and fault-tolerant • Telecommunication networks services > The ability of mobile agents to react > Support and management of advanced dynamically to unfavorable situations and telecommunication services are characterized events makes it easier to build robust and fault- by dynamic network reconfiguration. tolerant distributed systems. > The physical size of these networks and the > If a host is being shut down, all agents strict requirements under which they operate executing on that machine will be warned and call for mobile agent technology to form the given time to dispatch and continue their "glue" that keeps such systems flexible yet operation on another host in the network. effective. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Applications...

• Personal assistance. APPLICATIONS > The mobile agent's ability to execute on remote hosts makes it suitable as a "assistant" capable of performing tasks in the network on behalf of its creator. > The remote assistant will operate independently of its limited network connectivity, and the creator can feel free to turn his or her computer off. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

4 Applications... The Impact of Java

• Workflow applications and groupware • Secure execution • Electronic Commerce > Java has a pointer model that eliminates the • Secure Brokering possibility of overwriting memory and • Distributed information retrieval corrupting data. • Monitoring and notification > The security architecture of Java makes it reasonably safe to host an untrusted agent, • Information dissemination because it cannot tamper with the host or access • Parallel processing private information.

myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

The Impact of Java

• Dynamic class loading JAVA > Allows the virtual machine to load and define classes at runtime. • Multithread programming > Agents are by definition autonomous. > Java not only allows multithread programming, but also supports a set of synchronization primitives that are built into the language. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

The Impact of Java The Impact of Java

• Platform-independence • Object serialization > Java is designed to operate in heterogeneous > A key feature of mobile agents is that they can networks. be serialized and deserialized. > Primitive data types are rigorously specified > Java conveniently provides a built-in and not dependent on the underlying processor serialization mechanism that can represent the or . state of an object in a serialized form > It allows us to create a mobile agent without sufficiently detailed for the object to be knowing the types of computers it is going to reconstructed later. run on. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

5 Significant Shortcomings The Aglet Package

• Inadequate support for resource control • The aglet API is simple and flexible. > Unfortunately, Java provides no ways for the • Created in the spirit of Java and representing a host to limit the processor and memory lightweight pragmatic approach to mobile agents, the resources allocated by a given object or thread. aglet API is a Java package consisting of classes and Enables denial of service attacks. interfaces, most notably: > A related issue is the ability of the agent to • Aglet allocate resources external to the program, for • AgletProxy example by opening files and sockets, and • AgletContext creating windows. • Message • FutureReply • AgletID myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Significant Shortcomings Aglet Class

• No support for preservation and • The abstract class that you use as base class when you resumption of the execution state create your customized aglets. • Defines methods for controlling its own life cycle, > It is currently impossible in Java to retrieve the namely, methods for cloning, dispatching, full execution state of an object. deactivating, and disposing of itself. > Information such as the status of the program • It also defines methods that are supposed to be counter and frame stack is permanently overridden in its subclasses by the aglet programmer, forbidden territory for Java programs. and provides you with the necessary "hooks" to customize the behavior of the aglet. myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

My First Aglet

IBM’S AGLETS SOFTWARE DEVELOPMENT KIT (ASDK) import aglet.*; public class MyFirstAglet extends Aglet {

// Put aglet's methods here

}

myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

6 Collaboration Diagram My First Aglet for Dispatch • Initialization run() public void onCreation(Object init) { // Do some initialization here... dispatch() Origin } onDispatching()

• Execution onArrival() public void run() { Destination // Do something else here... run() } myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Collaboration Diagram Dispatching My First Aglet for Cloning dispatch(new URL("atp://some.host.com/context"));

State run()

1: Bytecode

Host Host onCloning() Original

Sending Receiving onCloned() 2:

Host Host onClone() Clone

State

run()

3: Bytecode

Host Host myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Mobility Listener Reusable Clone Listener

public class CloneLimiter implements CloneListener() { public void onCreation(Object o) { final integer MAX = 5; addMobilityListener( boolean original = true; new MobilityAdapter() { int number_of_clones = 0; public void onDispatching(MobilityEvent e) { public void onCloning(CloneEvent event) { ... if (original == false) } throw new SecurityException(”Cannot clone"); if (number_of_clones > MAX) public void onArrival(MobilityEvent e) { throw new SecurityException(”Limit Exceeded"); ... } } public void onClone(CloneEvent event) { } original = false; ); } public void onCloned(CloneEvent event) { } clone++; } } ©1998 General Magic, Inc. ©1998 General Magic, Inc. myTalk.com my}Talk.com

7 AgletContext Aglet Proxy

Object sendMessage(Message msg)

FutureReply sendFutureMessage(Message msg)

User Security

Interface Manager void sendOnewayMessage(Message msg)

Aglet Context

Message Message Network Daemon Aglet/Application Proxy Aglet Reply Reply

Network myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Aglet Creation Messaging

Message myName = new Message("my name", "Jacob"); public class InitExample extends Aglet { Message yourName = new Message("your name?"); public void run() { try { proxy.sendMessage(myName); getAgletContext().createAglet(getCodeBase(), String name = (String)proxy.sendMessage(yourName); "InitChild", "Hello World"); public boolean handleMessage(Message msg) { } catch (Exception e) { if ("my name".equals(msg.kind)) { System.out.println(e.getMessage()); String name = (String)msg.getArg(); } return true; } } else if ("your name?".equals(msg.kind)) { msg.sendReply("Yina"); } return true; } else return false; } myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Aglet Retraction Location-transparency

retractAglet(destination, aid); Host A Before Dispatch Local Firewall Application Aglet Host Proxy Inside Outside Host

1: Dispatch Host A After Host Host 2: Roam Dispatch Remote Application Proxy 3: Retract Host B Host Aglet Host myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

8 Example: Client (Application) Remote File Updating 1: Init args = new Init(new URL("atp://killi.genmagic.com"), • The philosophy behind this aglet is the 2: new File("C:/public/test.dat"), following: For files over a certain size it is 3: "abc", 4: "xyz"); considered beneficial (saves network 5: AgletContext context = getAgletContext() bandwidth) to perform a distributed update 6: context.createAglet(null, "UpdateFile", args); of the files because > save downloading/uploading of file, and > distribute the load of the update to multiple servers myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Remote File Update

Host Host Host FUTURE OF MOBILE Aglet Aglet Aglet AGENT TECHNOLOGY

Aglet

Host (Updating) myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Remote File Update Aglet Future

1: public class UpdateFile extends Aglet { 2: Init args; • The future for mobile agents looks very 3: public void onCreation(Object o) { 4: args = (Init)o; promising. For the past year we have seen 5: addMobilityListener( 6: new MobilityAdapter() { 7: public void onArrival(MobilityEvent e) { > strong increase in research activity 8: replace(args.file, args.from, args.to); 9: dispose(); > commercial interest on the rise 10: } 11: } > increased availability of systems 12: ); 13: try { > application stories being published 14: dispatch(args.destination); 15: } catch (Exception e) { 16: System.out.println("Failed to dispatch."); • I predict mobile Java agents will become 17: } 18: } ubiquitous in distributed object computing 19: void replace(File file, String from, String to) { 20: // Open ‘file’ and replace ‘from’ with ‘to’. within the next two years 21: } my22:Talk } .com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

9 AGLETS Mailing Lists BOOK • The Aglets Mailing List: > [email protected] “subscribe aglets” • Aglets Portal: > http://luckyspc.lboro.ac.uk/Aglets • The Mobility Mailing List: > [email protected] “subscribe mobility” myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Mobile Java Agent Systems Book Information

• Aglets (IBM Corp.) • Text book jointly written with Mitsuru http://www.trl.ibm.co.jp/aglets Oshima from IBM’s Aglets team • Voyager (ObjectSpace Inc.) > Programming and Deploying Java™ Mobile http://www.objectspace.com/Voyager Agents with Aglets™ • Concordia (Mitsubishi USA) Danny B. Lange & Mitsuru Oshima Addison Wesley 1998 http://www.meitca.com/HSL/Projects/Concordia ISBN: 0-201-32582-9

myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

Conferences Contact Information

• Presenter’s email/Web: Agent Systems and Applications and [email protected] International Workshop on Mobile Agents http://www.acm.org/~danny ASA/MA’99 • General Magic, Inc. http://www.generalmagic.com Palm Spring, California, October 3-6 1999 http://www.genmagic.com/asa myTalk.com ©1998 General Magic, Inc. myTalk.com ©1998 General Magic, Inc.

10