移动 a gent 系统 ——aglets. 提纲 aglets 简介 aglets 模型 aglets api aglets 样例 2
TRANSCRIPT
![Page 1: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/1.jpg)
移动 AGENT系统——Aglets
![Page 2: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/2.jpg)
提纲 Aglets简介 Aglets模型 Aglets API Aglets样例
2
![Page 3: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/3.jpg)
AGLETS
Aglets IBM http://www.trl.ibm.com/aglets/ http://aglets.sourceforge.net/
Latest version 2.5-alpha Stable version: 2.0.2
3
![Page 4: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/4.jpg)
AGLETS
What are mobile agents? Mobile network agents are programs that can be
dispatched from one computer and transported to a remote computer for execution. Arriving at the remote computer, they present their credentials and obtain access to local services and data. The remote computer may also serve as a broker by bringing together agents with similar interests and compatible goals, thus providing a meeting place at which agents can interact.
4
![Page 5: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/5.jpg)
AGLETS
What is the Aglets Software Development Kit? The Aglets Software Development Kit is an
environment for programming mobile Internet agents in Java. (It is what we used to be called Aglets Workbench.)
5
![Page 6: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/6.jpg)
AGLETS
What is an aglet? The aglet represents the next leap forward in the
evolution of executable content on the Internet, introducing program code that can be transported along with state information. Aglets are Java objects that can move from one host on the Internet to another. That is, an aglet that executes on one host can suddenly halt execution, dispatch itself to a remote host, and resume execution there. When the aglet moves, it takes along its program code as well as its data.
6
![Page 7: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/7.jpg)
AGLETS
Aglet Mobile Agent Platform (Aglets MAP): is the core platform, able to manage mobile agents.
Tahiti: is the main server in charge of managing the mobility of agents. It comes with a GUI that helps administrators taking care of running agents.
Aglets Software Development Kit (Aglets SDK – ASDK): is a library that provides developers all the facilities required to write mobile agents compliant to the Aglets MAP.
7
![Page 8: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/8.jpg)
AGLETS
迁移机制通信机制安全保障
8
![Page 9: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/9.jpg)
MOBILITY
Strong Mobility vs. Weak Mobility
Example for (int i = 0; i<10; i++){ migrate ( remoteHosts[i] ); }
9
![Page 10: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/10.jpg)
MOBILITY
Aglets only support weak mobility!
In fact, almost all the Java MAP support only the weak mobility. No support in Java to get enough information
about the execution flow. The Thread class itself is not serializable, and so
cannot be transmitted over the network.
10
![Page 11: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/11.jpg)
MOBILITY
Aglets ensures that an agent will keep its Java state (i.e. the value of its inner variable) among migrations (at least if the Java state is serializable).
When the agent is going to be executed on the remote machine, the execution will start from a well defined entry point (a method), and no re-initialization will happen (in order to not override the current agent state).
11
![Page 12: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/12.jpg)
COMMUNICATION
Based on message passing!
Agents cannot directly reference other agents, so it is not possible for an agent to handle a “pointer” to another agent. For security reason
12
![Page 13: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/13.jpg)
COMMUNICATION
Proxy Pattern A proxy is an object that masquerades another
object (its owner) and that forwarders method calls to its owner.
13
![Page 14: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/14.jpg)
COMMUNICATION
Aglets are hidden by proxies, and other aglets can send messages or perform method calls against the proxy, having the proxy to forward such method calls on the owner agent.
Advantages: Aglets are always protected, being invisible and that
the system can create and manage a lot of proxies for the same aglet without breaking the agent protection.
The dispose of a proxy does not causes the disposing of the agent it is masquerading.
In Aglets, agents are created and managed by the MAP, while proxies represents “handles” to other agents, thanks to which agents can communicate each other.
14
![Page 15: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/15.jpg)
SECURITY
protection of the host against aglets, protection of other aglets, protection of the aglet from the host, and protection of the underlying network.
15
![Page 16: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/16.jpg)
SECURITY
16
![Page 17: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/17.jpg)
SECURITY
The Aglet security model supports the flexible definition of various security policies and describes how and where a secure system enforces these policies.
Security policies are defined in terms of a set of rules by one administrative authority.
17
![Page 18: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/18.jpg)
SECURITY POLICIES
the conditions under which aglets may access objects;
the authentication required of users and other principals, which actions an authenticated entity is allowed to perform, and whether entities can delegate their rights;
the communications security required between aglets and between contexts, including trust; and
the degree of accountability required for each security relevant activity. 1
8
![Page 19: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/19.jpg)
AGLET 体系结构
Interagent Communication Manager
AgentApplication Gateway
Agent Manager
Reliability Manager
Directory Manager
Security Manager
External Application
Generic Mobile Agent Server
Network
Generic Mobile Agent Server
Generic Mobile Agent Server 19
![Page 20: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/20.jpg)
AGLET 模型 What is java aglet?
Lightweight agent Java object that can move from one host to
anotherA mobile java agent that supports concepts
of autonomous execution and dynamic routing on its itinerary. Has its own thread of control Is event-driven Communicates by message passing “Write once, go anywhere”
20
![Page 21: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/21.jpg)
AGLET MODEL(1)
Basic Elements:Aglet – a mobile Java objectProxy – a representative of an
agletContext – an aglet’s workplaceIdentifier – bound to each aglet
21
![Page 22: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/22.jpg)
RELATIONSHIP BETWEEN AGLET AND PROXY
Proxy Represents the Aglet A handle for local, remote or deactivated aglet
Shields Public Methods for Potential Misuse Can Hide the “actual” Location of Aglet Proxy and Aglet on Different Computing
Nodes Proxy : Aglet < = > n : 1
22
![Page 23: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/23.jpg)
InteractionClients Proxy Aglet
InteractionClients Proxy
Aglet
H1
H2
23
![Page 24: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/24.jpg)
CONTEXT A context is an uniform execution
environment for aglet. a stationary objectprovides a means for maintaining and
managing running aglets One node in a computer network may run
multiple servers and each server may host multiple contexts.
Contexts are named and can thus be located by the combination of their server's address and their name.
24
![Page 25: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/25.jpg)
CONTEXT
Aglets must be instantiated within a context, and at any time belong to exactly one context.
Context can be used for: createAglet retractAglet getAgletProxies / getAgletProxy setProperty/getProperty
25
![Page 26: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/26.jpg)
RELATIONSHIP BETWEEN HOST, SERVER PROCESS(ENGINE), AND CONTEXTS
Context Context Context
Host
Server Process (Engine)
Network26
![Page 27: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/27.jpg)
CONTEXT, PROXY, AGLET
Context
Proxyaglet
27
![Page 28: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/28.jpg)
AGLET MODEL(2)
Basic ElementsAglet : a mobile java objectProxy : a representative of an agletContext : an aglet’s workplaceIdentifier : bound to each agletMessage : an object exchanged between agletsFuture reply : an asynchronous message-
sending
28
![Page 29: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/29.jpg)
AGLET MODEL(2)
Messagean object exchanged between aglets. It allows
for synchronous as well as asynchronous message passing between aglets.
Future replyA future reply is used in asynchronous message-
sending as a handler to receive a result later asynchronously
29
![Page 30: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/30.jpg)
AGLET : COMMUNICATION MODEL
Message passing: Allows aglets to create and exchange
messages in flexible ways. Key Components:
Aglet, AgletProxy, Message, Future reply, Reply set
Aglet/
Application
Message
Reply
Message
ReplyProxy Aglet
30
![Page 31: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/31.jpg)
AGLET MODEL(2)
Context
Proxyaglet Proxy aglet
Message
31
![Page 32: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/32.jpg)
AGLET: OPERATIONS
Six Basic Operations1. Creation2. Cloning3. Dispatching4. Retraction5. Activation and Deactivation6. Disposal
32
![Page 33: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/33.jpg)
AGLET: OPERATIONS
Creation Initializes a New Aglet Assigns Aglet an Identifier
Cloning Produce an Identical Copy of an Aglet Differences Between Clone and Original Aglet
Identifier Place of Execution
33
![Page 34: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/34.jpg)
AGLET: OPERATIONS
DispatchingAglet is Transported (Pushed) From One
Context to Another Retraction
Concept that Returns an Aglet Back to its Original Context
Original Context Pulls Back the Aglet From the Current Context
34
![Page 35: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/35.jpg)
AGLET: OPERATIONS
Deactivation and Activation Deactivation Must Occur Before Activation Deactivation Halts the Execution of an Aglet Activation Starts Execution of an Aglet Activation Must Occur to Restore the Aglet
Disposal Stops Execution of an Aglet Removes an Aglet From its Current Context
35
![Page 36: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/36.jpg)
BASIC OPERATIONS
Classification of Six Basic Aglet Operations Classified as the Life Cycle of an Aglet
Observation of Six Basic Aglet OperationsContext Functions Just Like a Place
36
![Page 37: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/37.jpg)
AGENT LIFE-CYCLE MODEL
Aglet Aglet
Class File
DiskStorage
Create Deactivate Activate
DisposeClone
Context A Context B
Retract
Dispatch
37
![Page 38: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/38.jpg)
AGENT LIFE-CYCLE MODEL
38
![Page 39: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/39.jpg)
AGLET EVENT MODEL
Aglet Programming Model Similar to the Java Event Model Event Based Listeners Used to Perform Event Actions
Three Event Model Listeners Clone Listener Mobility Listener Persistence Listener
Actions Listen for the Event They are Named After Listeners Can Be Customized to Perform Specific
Actions When the Listener Event Occurs 39
![Page 40: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/40.jpg)
RELATIONSHIP BETWEEN AGLET AND ITS LISTENERS
Aglet
Clone Events
Mobility Events
Persistence Events
CloneListener
MobilityListener
PersistenceListener
40
![Page 41: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/41.jpg)
EVENT MODEL LISTENERS
Clone Listener Listens for Cloning Events Actions Can Be Customized to Occur Before,
During, or After the Cloning Mobility Listener
Listens for Mobility Events Actions Can Be Customized to Occur When an
Aglet is About to Be Dispatched, Retracted, or Arrives in a New Context
Persistence Listener Listens for Persistence Events Actions Can Be Customized to Occur When an
Aglet is About to Be Deactivated or Has Been Activated
41
![Page 42: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/42.jpg)
EXAMPLE
Agent dispatch
42
![Page 43: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/43.jpg)
THE AGLET MODEL
Message Handling Aglets exploit a communication system based on
message passing. An agent that wants to explicitly manage
messages has to override the handleMessage(..) method, returning true in the case that the message is managed by the agent, and false otherwise.
43
![Page 44: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/44.jpg)
MESSAGE HANDLING
An aglet is not necessarily aware of message source, it just receives and handles messages. Message source should be included in some way in the message itself, since there is no other way to identify it.
Message handling is as complex as the handleMessage(…) implementation.
The method handleMessage(Message msg) has one parameter, the message received by the aglet, which can be used to define the aglet message handling behavior.
The message type is its classification. 44
![Page 45: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/45.jpg)
MESSAGE HANDLING
45
![Page 46: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/46.jpg)
THE AGLET MODEL
Agent Design PatternsTravelingTaskInteraction
46
![Page 47: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/47.jpg)
AGENT DESIGN PATTERN (CONT.) Traveling
Itinerary: routes among destinations. Forwarding: a host forwards an arrived agent to
another host. Ticket: objectifies a destination address and
encapsulates the quality of service and permissions needed to dispatch an agent to a host address and to execute it there.
47
![Page 48: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/48.jpg)
AGENT DESIGN PATTERN (CONT.)
Task Master-Slave: an agent delegate a task to another Plan: organize multiple tasks to be performed in
sequence or in parallel by multiple agents.
48
![Page 49: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/49.jpg)
AGENT DESIGN PATTERN (CONT.)
Interaction Meeting: two or more agents initiate local
interaction at a given host. Locker: defines a storage and come back for data
later. Messenger: an agent carries a remote message
from one agent to another. Facilitator: an agent provides services for naming
and locating agents. Organized Group: travel together.
49
![Page 50: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/50.jpg)
Aglet Class & API
50
![Page 51: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/51.jpg)
AGLETS
Mobile Agents with Java Aglet Package (Classes)
Aglet Class Message Class AgletID Class AgletInfo Class AgletStub Class FutureReply Class QoC Class ReplySet Class
51
![Page 52: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/52.jpg)
AGLETS
Mobile Agents with JavaAglet Package (Interfaces)
AgletProxy InterfaceAgletContext InterfaceMessageManager Interface
52
![Page 53: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/53.jpg)
AGLET API: CLASSES
Aglet ClassContains All Methods Needed to Perform
the Basic Aglet OperationsBasis for Building All AgletsContains All the Elements of the Aglet
53
![Page 54: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/54.jpg)
AGLET CLASS
Aglet Creation Create a Customized Aglet
import com.ibm.aglet.*;public class MyFirstAglet extends Aglet{
//Put aglet’s methods here}
The Dispatch Method Dispatches an Aglet to a Remote Context The Method Call Contains the URL of the Remote
Contextdispatch(new URL(atp://remote.host.com/context”));
54
![Page 55: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/55.jpg)
AGLET CLASS
Overridden methods:public void onCreation(Object init){
//do some initialization here…
}
public void run() { //do something here;
} //main entry point e.g. call dispatch(new URL(“atp://some.host.com//context”));
55
![Page 56: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/56.jpg)
AGLET API :AGLET CLASS
What happens when “dispatch”?
StateByte Code
Host Host
Sending Receiving
StateByte Code
HostHost
Object Serialization
Transfer
Deserialization and re-create state
56
![Page 57: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/57.jpg)
MESSAGE CLASS
Message Objects are Sent Using the AgletProxy Class MethodsObject sendMessage(Message msg)void sendOnewayMessage(Message msg)
Code Exampleproxy.sendMessage(myName);
String name = (String)proxy.sendMessage(yourName);
57
![Page 58: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/58.jpg)
MESSAGE CLASS
Public boolean handleMessage(Message msg){ if(msg.samekind(“my name”)){ String name=(String)msg.getArg(); return true; //Yes, I handled this message } else if(msg.samekind(“your name?”)) { msg.sendReply(“Yina”); //Return its name return true; //Yes, I handled this message } else return false; //No, I did not handle this message}
handleMessage method:
58
![Page 59: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/59.jpg)
AGLET API : AGLETPROXYHow to get a proxy?
Get proxy from a newly created aglet: AgletContext.createAglet() AgletProxy.clone()
Get proxy from existing aglets Aglet.getProxy() – get its own proxy AgletContext.getAgletProxies() – retrieve an enum. of
proxies in a context AgletContext.getAgletProxy() – get an aglet proxy for a
given aglet ID AgletContext.setProperty – put proxy into context property
and share it.
59
![Page 60: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/60.jpg)
AGLET API : AGLETCONTEXT An aglet context is the equivalent of a
place. An aglet uses AgletContext interface
to:Get information about its environmentSend message to the environment,
including other aglets currently active in that environment
How it works:context=getAgletContext();context.createAglet();context.retractAglet(remoteContextURL,agletID);
60
![Page 61: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/61.jpg)
EXAMPLE
• Aglet Example: Remote File Update• Premise: Large Multiple Remote Files that Must be
Updated by Word Replacement• One Solution: Move Files to Central Server, Perform
Update, and Move Files Back• Another Solution: An Aglet that Updates Files by
Replacing All Occurrences of One Specified Word in the Files With Another Specified Word
• Distributes the Load of Updates to Multiple Servers
• We’re Moving “Code” Rather Than Files
61
![Page 62: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/62.jpg)
MULTIPLE AGLETS UPDATING FILES IN PARALLEL
Aglet AgletAglet
Aglet
Host (Updating)
Host HostHostF FF FF F
62
![Page 63: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/63.jpg)
UPDATE FILE AGLET
import com.ibm.aglet.*;import com.ibm.aglet.event.*;import java.net.*;import java.io.*;public class UpdateFile extends Aglet{
URL destination = null;File dir = null;String from = null;String to = null;public void onCreation(Object args){
destination = (URL)((Object[])args)[0];dir = (File)((Object[])args)[1];from = (String)((Object[])args)[2];to = (String)((Object[])args)[3];addMobilityListener(){
new MobilityAdapter(){63
![Page 64: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/64.jpg)
UPDATE FILE AGLET
Public void onArrival(MobilityEvent e){replace(args.file,args.from,args.to);dispose(); }
}}try{
dispatch(args.destination);}catch (Exception e){
System.out.println(“Failed to dispatch.”);
}}void replace(File, file, String, from, Sting
to){//Open ‘file’ and replace ‘from’ with ‘to’
}
64
![Page 65: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/65.jpg)
APPLICATION OF AGLETS Marketplace Architecture
Shop agents go to a market from a shop owner’s terminal Customer agents travel around various markets to get more
information Market advertisers go to other markets to invite customer
agents
65
![Page 66: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/66.jpg)
ANATOMY OF AN AGLET
Creation & Disposal Clone Mobility
– Dispatch and Retract Persistence
– Activate and Deactive
66
![Page 67: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/67.jpg)
CREATION
public final AgletContext Aglet.getAgletContext()//Example: getAgletContext().createAglet(getCodeBase(),”SomeAglet”,nul
l);Methods that can be overridden
protected Aglet.Aglet()Public void Aglet.onCreation(Object init)Public void Aglet.run()
createAglet()Aglet()onCreationrun()
67
![Page 68: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/68.jpg)
CLONINGpublic final Object Aglet.clone()public final void Aglet.addCloneListener(CloneListener
listener)public final void
Aglet.removeCloneListener(CloneListener listener)
public CloneAdapter.CloneAdapter()public void CloneAdapter.onCloning(CloneEvent
event)public void CloneAdapter.onClone(CloneEvent event)public void CloneAdapter.onCloned(CloneEvent event)
68
![Page 69: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/69.jpg)
public class CloningExample extends Aglet{
boolean _theClone=false;
public void onCreation(Object o) {
addCloneListener(new CloneAdapter(){
public void onCloning(CloneEvent e){
// print to the console }
public void onClone(CloneEvent e){
// print to the console }
public void onCloned(CloneEvent e){
// print to the console }
} );
}
public void run() { if (! _theClone) { //the original runs here… try{ clone(); } catch (Exception e) { System.out.println(e.getMessage());
}
else {//the clone runs here…}
}
run()
onCloning()
onCloned()
onClone()
run()
original
clone
CLONING
69
![Page 70: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/70.jpg)
MOBILITY
-- Dispatching
run( )dispatch( )onDispatching( )
onArrival( )run( )
Origin
Destination
retractAglet( )onArrival( )run( )
run( )onReverting( )
Local
Remote
-- Retracting
70
![Page 71: 移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2](https://reader030.vdocuments.site/reader030/viewer/2022033006/56649cdf5503460f949a90da/html5/thumbnails/71.jpg)
PERSISTENCE
Persistence
run( )deactivate( )onDeactivating( )
onActivation( )run( )
Before
After
Aglet Context
Deactivate
Activate
71