Presentation is loading. Please wait.

Presentation is loading. Please wait.

移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2.

Similar presentations


Presentation on theme: "移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2."— Presentation transcript:

1 移动 A GENT 系统 ——Aglets

2 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2

3 A GLETS Aglets IBM http://www.trl.ibm.com/aglets/ http://aglets.sourceforge.net/ Latest version 2.5-alpha Stable version: 2.0.2 3

4 A GLETS 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

5 A GLETS 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

6 A GLETS 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

7 A GLETS 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

8 AGLETS 迁移机制 通信机制 安全保障 8

9 M OBILITY Strong Mobility vs. Weak Mobility Example for (int i = 0; i<10; i++){ migrate ( remoteHosts[i] ); } 9

10 M OBILITY 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

11 M OBILITY 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

12 C OMMUNICATION 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

13 C OMMUNICATION Proxy Pattern A proxy is an object that masquerades another object (its owner) and that forwarders method calls to its owner. 13

14 C OMMUNICATION 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

15 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

16 S ECURITY 16

17 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

18 S ECURITY P OLICIES 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. 18

19 A GLET 体系结构 Interagent Communication Manager Agent Application Gateway Agent Manager Reliability Manager Directory Manager Security Manager External Application Generic Mobile Agent Server Network Generic Mobile Agent Server 19

20 A GLET 模型 What is java aglet? Lightweight agent Java object that can move from one host to another A 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

21 A GLET M ODEL (1) Basic Elements: Aglet – a mobile Java object Proxy – a representative of an aglet Context – an aglet ’ s workplace Identifier – bound to each aglet 21

22 R ELATIONSHIP BETWEEN A GLET AND P ROXY 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

23 Interaction Clients Proxy Aglet Interaction Clients Proxy Aglet H1 H2 23

24 C ONTEXT A context is an uniform execution environment for aglet. a stationary object provides 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

25 C ONTEXT 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

26 R ELATIONSHIP BETWEEN H OST, S ERVER P ROCESS (E NGINE ), AND C ONTEXTS Context Host Server Process (Engine) Network 26

27 C ONTEXT, PROXY, AGLET Context Proxy aglet 27

28 A GLET M ODEL (2) Basic Elements Aglet : a mobile java object Proxy : a representative of an aglet Context : an aglet ’ s workplace Identifier : bound to each aglet Message : an object exchanged between aglets Future reply : an asynchronous message-sending 28

29 A GLET M ODEL (2) Message an object exchanged between aglets. It allows for synchronous as well as asynchronous message passing between aglets. Future reply A future reply is used in asynchronous message- sending as a handler to receive a result later asynchronously 29

30 A GLET : C OMMUNICATION M ODEL 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 Reply ProxyAglet 30

31 A GLET M ODEL (2) Context Proxy aglet Proxy aglet Message 31

32 A GLET : O PERATIONS Six Basic Operations 1. Creation 2. Cloning 3. Dispatching 4. Retraction 5. Activation and Deactivation 6. Disposal 32

33 A GLET : O PERATIONS 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

34 A GLET : O PERATIONS Dispatching Aglet 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

35 A GLET : O PERATIONS 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

36 B ASIC O PERATIONS Classification of Six Basic Aglet Operations Classified as the Life Cycle of an Aglet Observation of Six Basic Aglet Operations Context Functions Just Like a Place 36

37 A GENT L IFE -C YCLE M ODEL Aglet Class File Disk Storage Create Deactivate Activate Dispose Clone Context AContext B Retract Dispatch 37

38 A GENT L IFE -C YCLE M ODEL 38

39 A GLET E VENT M ODEL 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

40 R ELATIONSHIP BETWEEN A GLET AND ITS L ISTENERS Aglet Clone Events Mobility Events Persistence Events CloneListener MobilityListener PersistenceListener 40

41 E VENT M ODEL L ISTENERS 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

42 E XAMPLE Agent dispatch 42

43 T HE A GLET M ODEL 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

44 M ESSAGE H ANDLING 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

45 M ESSAGE H ANDLING 45

46 T HE A GLET M ODEL Agent Design Patterns Traveling Task Interaction 46

47 A GENT D ESIGN P ATTERN ( 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

48 A GENT D ESIGN P ATTERN ( 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

49 A GENT D ESIGN P ATTERN ( 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

50 Aglet Class & API 50

51 A GLETS Mobile Agents with Java Aglet Package (Classes) Aglet Class Message Class AgletID Class AgletInfo Class AgletStub Class FutureReply Class QoC Class ReplySet Class 51

52 A GLETS Mobile Agents with Java Aglet Package (Interfaces) AgletProxy Interface AgletContext Interface MessageManager Interface 52

53 A GLET API: C LASSES Aglet Class Contains All Methods Needed to Perform the Basic Aglet Operations Basis for Building All Aglets Contains All the Elements of the Aglet 53

54 A GLET C LASS 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 Context dispatch(new URL(atp://remote.host.com/context”)); 54

55 A GLET C LASS 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

56 A GLET API : A GLET C LASS What happens when “ dispatch ” ? State Byte Code Host Sending Receiving State Byte Code Host Object Serialization Transfer Deserialization and re-create state 56

57 M ESSAGE C LASS Message Objects are Sent Using the AgletProxy Class Methods Object sendMessage(Message msg) void sendOnewayMessage(Message msg) Code Example proxy.sendMessage(myName); String name = (String)proxy.sendMessage(yourName); 57

58 M ESSAGE C LASS 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

59 A GLET API : A GLET P ROXY How 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

60 A GLET API : A GLET C ONTEXT An aglet context is the equivalent of a place. An aglet uses AgletContext interface to: Get information about its environment Send message to the environment, including other aglets currently active in that environment How it works: context=getAgletContext(); context.createAglet(); context.retractAglet(remoteContextURL,agletID); 60

61 E XAMPLE 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

62 M ULTIPLE A GLETS U PDATING F ILES IN P ARALLEL Aglet Host (Updating) Host FFFFFF 62

63 U PDATE F ILE A GLET 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

64 U PDATE F ILE A GLET 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

65 A PPLICATION OF A GLETS 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

66 A NATOMY OF AN A GLET Creation & Disposal Clone Mobility – Dispatch and Retract Persistence – Activate and Deactive 66

67 C REATION public final AgletContext Aglet.getAgletContext() //Example: getAgletContext().createAglet(getCodeBase(), ” SomeAglet ”,null); Methods that can be overridden protected Aglet.Aglet() Public void Aglet.onCreation(Object init) Public void Aglet.run() createAglet() Aglet() onCreation run() 67

68 C LONING public 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

69 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 C LONING 69

70 M OBILITY -- Dispatching run( ) dispatch( ) onDispatching( ) onArrival( ) run( ) Origin Destination retractAglet( ) onArrival( ) run( ) onReverting( ) Local Remote -- Retracting 70

71 P ERSISTENCE Persistence run( ) deactivate( ) onDeactivating( ) onActivation( ) run( ) Before After Aglet Context Deactivate Activate 71


Download ppt "移动 A GENT 系统 ——Aglets. 提纲 Aglets 简介 Aglets 模型 Aglets API Aglets 样例 2."

Similar presentations


Ads by Google