Title: Aglets 3 Mobile Agents with Java Kenji Taguchi Dept' Information Science Uppsala University
1Aglets (3) - Mobile Agents with Java -Kenji
TaguchiDept. Information ScienceUppsala
University
2Aglets
- Aglet is a Java API (Application Programming
Interface). - Thus it is inevitable being influenced by its
platform language Java.
3Benefits
- Platform Independence
- byte code interpreter
- platform independent GUI
- Secure Execution
- clean language semantics w.r.t. pointers and
types - restrictions to access local resources
- secure runtime system by JVM
- Dynamic Class Loading
- via the network
- Multithread Programming
- multiple lightweight processes
- synchronisation primitives for messaging
- Object Serialisation
- an object state can be serialised and
deserialised - Reflection
- An object can find out its own methods,
variables, etc.
4Drawbacks
- Inadequate Support for Resource Control
- No control the resources consumed by an object
- No ability to allocate resources external to the
program. - No Protection of References
- No way to monitor and control accesses to agents
methods - No Object Ownership of References
- No way to collect garbage which still has some
reference - No Support for Preservation and Resumption of the
Execution State - Impossible to retrieve the full execution state
of an object.
5The Aglets Model
- Basic Elements
- Aglet
- Proxy
- Context
- Identifier
6Aglet
- A Mobile Java Object
- Its characteristics
- Autonomous
- Reactive
7Proxy
- A representative of an aglet
- protects the aglet
- no access to its public methods is allowed
- location transparency
- hides its real location
8Aglet and Proxy
Proxy
Aglet
Interaction
Client
9Context
- Workplace (place)
- Stationary
10Host, Engine and Contexts
Network
11Identifier
- Each aglet has its own unique identifier
- globally unique and immutable throughout the
lifetime of the aglet
12Aglet Life-Cycle Model
- Creation
- Cloning
- Dispatching
- Retraction
- Activation and Deactivation
- Disposal
13Creation
1. An identifier is assigned, 2. Inserted into
the context, 3. initialised
Context
Aglet
Create
Class File
14Cloning
1. An identical copy is created in the same
context, 2. Assigned a new identifier
Context
Aglet
Clone
Class File
Remark execution threads are not cloned
15Dispatching
ContextB
ContextA
Dispatch
Aglet
Aglet
Class File
1. Remove the aglet to another context.
16Activation and Deactivation
Activation
1. Restore the state in the same context
Context
Aglet
Deactivate
Activate
Deactivation
Disk Storage
1. Store the state in secondary storage
17Dispose
Dispose
1. Halt its execution, 2. Remove it from the
context.
Context
Aglet
Class File
18Aglet Event Model
- Programming Style
- Event-based
- The following Listeners are provided
- for taking actions when some particular events
would occur. - Clone Listener
- Listening for cloning events
- Mobility Listener
- Listening for mobility events
- Persistence Listener
- Listening for persistence events.
19Aglet Event Model (Diagram)
Aglet
Clone Event
Clone Listener
Mobility Event
MobilityListener
Persistence Event
PersistenceListener
20Clone Listener
- Listens for cloning events.
- Specify the behaviour when
- an aglet is about to be cloned,
- when the clone is created,
- after the cloning has taken place.
21Mobility Listener
- Listens for mobility events.
- Specify the behaviour when
- an aglet is about to be dispatched to another
context, - when it is about to be retracted from a context,
- when it actually arrives in a new context.
22Persistence Listener
- Listens for persistent events.
- Specify the behaviour when
- an aglet is about to be deactivated,
- after it has been activated.
23BoomerangItenerary
- The aglet will always return to you no matter
where you send it. - It implements three methods
- onDispatching
- onArrival
- onRetract
- Too may mistakes in the source code
24BoomerangItenerary (Code) 1
public class BoomerangItinerary implements
MobilityListener Aglet target null String
origin null public BoomerangItinerary (Aglet
target) target.addMobilityListener((MobilityLi
stner)this) origin target.getAgletInfo().getO
rigin() public void onDispatching(MobilityEven
t ev) target.setText(Im leaving for
ev.getLocation()) public void
onArrival(MobilityEvent ev) if (atOrigin
(ev.getLocation()) false) try
target.dispatch( newURL(origin )) catch
(Exception ex)
25BoomerangItenerary (Code) 2
boolean atOrigin (URL current) return
origin.equals(current.toString())
public void onRetract(MobilityEvent ev)
26Aglet Communication Model
- Based on Message Passing
- Message
- an object
- Future Reply
- asynchronous message
- Reply Set
- a set of future reply objects
- Does not support concurrent message handling
- Detailed discussion (Chap. 6)
27Aglet-Aglet Messaging
Message
Message
Reply
Reply
28Core Classes and Interfaces
- Included in the package com.ibm.aglet
- Aglet Class
- the abstract class
- basic methods
- AgletProxy Interface
- the handle of an aglet
- AgletContext Interface
- equivalent of a place
- Message Class
- for messaging
- FutureReply Class
- for the asynchronous message-sending
- AgletID Class
- globally unique identity for an aglet
29Aglet Class (1)
import com.ibm.aglet. public class
MyFirstAglet extends Aglet public void
onCreation( Object init) // Do some
initialization here ...
30Aglet Class (2)
public void run() // Do something when
arrives at a new context
31Transfer of an Aglet
dispatch( new URL(atp//some.host.com/contexts)
)
ATP (Agent Transfer Protocol) (see Chap. 9 )
1.
Host
Host
Sending
Receiving
2.
Host
Host
3.
Host
Host
32AgletProxy Interface
- AgletContext.createAglet
- will return the proxy of the newly created aglet
- AgletContext.retractAglet,
- AgletProxy.clone,
- AlgetProxy.dispatch
- also returns the proxy
- Aglet.getProxy()
- can get its own proxy.
- AgletContext.getAgletProxies
- can retrieve an enumeration of proxies in a
context - We skip other methods here
33AgletContext Interface
- A method of the Aglet class which can access to
its current context - context getAgletContext()
- With access to the context, the aglet can create
new aglets - context.createAglet(...)
- It can retract remotely located aglets into the
current context - context.retractAglet( remoteContextURL, agletID)
- It can retrieve a list of proxies of its fellow
aglets in the same context - proxies context.getAgletProxies()
34Message Class
- First parameter kind distinguishes messages
- Second parameter an optional message arg.
- Message myName new Message(my name, Jacob)
- Message yourName new Message(your name?)
- Messages can be sent by one of the following
methods - Object sendMessage( Message msg)
- FutureReply sendFutureMessage( Message msg)
- sendAsyncMessage is a correct method name
- void sendOnewayMessage( Message msg)
35How to use Messages (1)?
public boolean handleMessage(Message msg) if
(msg.sameKind(hello)) doHello() return
true else return false
36How to use Messages (2)?
public boolean handleMessage(Message msg) if
(msg.sameKind(my name)) String name
(String)msg.getArg() return true else if
(msg.samekind(your name?)) msg.sendReply(Yi
na) return true else return false
37FutureReply Class
- A sender will perform a task (doPeriodicWork() )
while waiting for the reply
FutureReply future proxy.sendFutureMessage(msg)
FutureReply future proxy.sendAsyncMessage(msg)
while (!future.isAvailable())
doPeriodicWork () Object reply
future.getReply()
It can wait for the result with a specified
time-out value.
38AgletID Class
- An AgletID can be retrieved from the aglet and
its proxy
AgletID aid proxy.getAgletID()
- The aglet proxies can be retrieved from the aglet
id and a context
proxy context.getAgletProxy(aid)
39Multiple Aglets Updating Files in Parallel
Aglet
Host (Updating)