Shonali Krishnaswamy - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Shonali Krishnaswamy

Description:

Proxy is a shield that protects Aglets from malicious Aglets ... Aglet that travels to a remote server and lists all the proxies of Aglets in the remote context ... – PowerPoint PPT presentation

Number of Views:100
Avg rating:3.0/5.0
Slides: 32
Provided by: scie192
Category:

less

Transcript and Presenter's Notes

Title: Shonali Krishnaswamy


1
Aglet Programming Part II
  • This presentation will probably involve audience
    discussion, which will create action items. Use
    PowerPoint to keep track of these action items
    during your presentation
  • In Slide Show, click on the right mouse button
  • Select Meeting Minder
  • Select the Action Items tab
  • Type in action items as they come up
  • Click OK to dismiss this box
  • This will automatically create an Action Item
    slide at the end of your presentation with your
    points entered.
  • Shonali Krishnaswamy Leni Lim

2
Lecture Outline
  • Proxy Interface - Revisited
  • Proxy Retrieval
  • Proxy Iterator, Getting a local proxy, Getting a
    Remote proxy
  • Aglet Communication
  • Simple Messaging
  • The Message Class Creating Messages, Receiving
    Messages, Replying to Messages
  • Getting the Reply Synchronous Messaging,
    Asynchronous Messaging
  • NEXT WEEK
  • Message Management Serialised Message Handling,
    Message Priorities, Parallel Message Handling,
    Synchronised Message Handling
  • Remote Messaging, Multicasting, Receiving
    Multiple Replies

3
AgletProxy Interface
  • Acts as the handle of an aglet
  • Provides a common way of accessing the aglet
  • Aglet class
  • several public methods
  • should not be accessed directly from other aglets
  • security reasons
  • For Aglet A to communicate with Aglet B-
  • The proxy of Aglet B must be obtained
  • Interact with Aglet B through the Interface
  • Proxy is a shield that protects Aglets from
    malicious Aglets
  • The AgletProxy object consults the Security
    Manager
  • Check whether current execution context is
    allowed to perform the method
  • AgletProxy Interface also provides Location
    Transparency
  • If the Aglet is on a remote host, then the proxy
    forwards a request to the Aglet and returns the
    results

4
Aglet Proxycont...
Aglet
Aglet
Proxy
Proxy
Aglet Context
Aglet Server/Viewer
5
AgletProxy Interface
Proxy 1
dispatched
handleMessage() sendReply()
Proxy1.sendMessage()
Proxy 2
Proxy 3
Local Context
Remote Context
6
AgletProxy Interface
  • Creating an Aglet is a way of getting a Proxy
  • AgletContext.createAglet() returns the proxy of
    the newly created Aglet
  • Other methods
  • AgletContext.retractAglet()
  • AgletProxy.clone()
  • AgletProxy.dispatch()

7
Proxy Retrieval
  • Focus in methods that retrieve aglet proxies.
  • play an important role as convenient handles for
    aglets.
  • use to gain access to and communicate with its
    corresponding(possible remotely located) aglet.
  • there are number of ways in which you can
    retrieve proxies from local as well as remotely
    located aglets.

8
Proxy Retrieval By Creating
  • Method 1
  • public abstract AgletProxy AgletContext.createAgl
    et(URL codebase, String code, Object init)
  • Retrieves the proxy of a child aglet that has
    been created.
  • Example
  • AgletProxy CPLAgletProxy1 getAgletContext().crea
    teAglet(null,"examples.cpe5010.ChildProxyLister1",
    null)

9
Proxy Retrieval Using AgletID
  • Method 2
  • public abstract AgletProxy AgletContext.getAgletP
    roxy(AgletID identity)
  • Retrieves the proxy of an aglet in the current
    context. The identity of the aglet must be known.

10
Proxy Retrieval - Enumeration
Method 3
  • Public abstract Enumeration AgletContext.getAgletP
    roxies()
  • Get the proxies of all aglets in the current
    context.
  • Returns an Enumeration of proxies. Which may
    include currently deactivated aglets.
  • Enumeration has two methods that support
    iteration hasMoreElements() and nextElement().

11
Example 1 A Local Proxy Lister
  • Use the getAgletProxies method to list the
    current set of aglets in the following format
  • Four Aglets in the Current Context
  • JustAnAglet
  • ProxyLister parent that creates 2 other Aglets
  • ChildProxyLister1
  • ChildProxyLister2
  • This does the listing of all the Aglets that are
    current in the Context
  • To run this example
  • First create JustAnAglet in Tahiti
  • Then create ProxyLister in Tahiti
  • You will see the displayed list of Aglets on the
    console

12
Example 2 A Mobile Proxy Lister
  • Similar to previous example
  • MobileProxyLister
  • Aglet that travels to a remote server and lists
    all the proxies of Aglets in the remote context
  • Four Aglets in the Current Context
  • JustAnAglet
  • ProxyLister parent that creates 2 other Aglets
  • ChildProxyLister1
  • ChildProxyLister2
  • This does the listing of all the Aglets that are
    current in the Context
  • To run this example
  • Instantiate one Tahiti Server
  • First create JustAnAglet in Tahiti
  • Then create ProxyLister in Tahiti
  • You will see the displayed list of Aglets on the
    console
  • Instantiate another Tahiti Server on a different
    port
  • Create MobileProxyLister
  • NOTE Modify the MobileproxyListers destimnation
    URL to one in which you are running JustAnAglet
    and ProxyLister

13
Getting a Remote Proxy
  • public abstract AgletProxy AgletContext.getAgletPr
    oxy(URL contextAddress, AgletID identity)
  • Retrieve the proxy of an aglet hosted in a
    remote context. The remote context is identified
    by its URL and the identitty indicates the aglet.
    Both must be known
  • (the following example creates two aglets. One of
    these aglets is dispatched to a remote context.

14
Example 3 Getting a Remote Proxy
  • ParentProxy, ChildProxy1 ChildProxy2
  • ParentProxy creates a ChildProxy1
  • Gets its ID
  • Dispatches it to a destination
  • Creates ChildProxy2
  • Passes it the destination URL and ID of
    ChildProxy1
  • ChildProxy2 can now find the name of ChildProxy1
    since it knows its destination and URL
  • It can also send Messages etc.

15
Aglet Communication
  • Agent Communication
  • Speech Act Theory
  • Agent Communication Languages
  • Knowledge Query Manipulation Language (KQML)
  • FIPA Agent Communication Language (ACL)
  • Messaging very important for Agent Interaction,
    Coordination, Collaboration etc.
  • Remember Difference between Objects Agents?
  • Object invoke method
  • Agent request a service

16
Aglet Communication
  • Aglets supports an object-based messaging
    framework
  • Location independent
  • Extensible
  • Rich
  • Synchronous Asynchronous

17
Simple Messaging
  • Principal means of Aglet Communication
  • Message Passing
  • InterAglet Messaging is based on a simple event
    model
  • Requires an aglet to implement handlers only
    for the messages that it is supposed to
    understand
  • The main message handling method is
  • public boolean Aglet.handleMessage(Message
    myMessage)
  • To send a message
  • Invoke the sendMessage() method on the Aglets
    proxy not directly on the Aglet
  • public Object AgletProxy.sendMessage(Message
    myMessage)
  • Aglet Proxy acts as a message gateway

18
Aglet Communication
Proxy 1
dispatched
handleMessage() sendReply()
Proxy1.sendMessage()
Proxy 2
Proxy 3
Local Context
Remote Context
19
Example Send Message
  • You need the Proxy of the Aglet you wish to send
    a message to
  • The following example creates an Aglet called
    SimpleMessageChild and uses the proxy that it
    gets while creating it to send messages to it.
  • Trivial example
  • Typical applications will require you to
    communicate with Aglets that you dont really know

20
Example Send Message
public class SimpleMessageExample extends Aglet
public void run() AgletProxy proxy
getAgletContext().createAglet(getCodeBase(),
SimpleMessageChild, null) try
proxy.sendMessage( new Message
(Hello)) catch (NotHandledException e)
System.out.println(Message Not
Handled!)
21
Example Handle Message
public class SimpleMessageChild extends Aglet
public boolean handleMessage (Message msg)
if (msg.sameKind(Hello))
System.out.println(I got a Hello Message)
return true else return false
22
Example Handle Message
  • SimpleMessageChild knows to respond to messages
    that say Hello
  • What happenes if you send it a message Hi ?
  • proxy.sendMessage(new Message(Hi!)
  • Return false
  • In the SimpleMessageExample, you will get
    Message Not Handled

23
Message Class
  • Messages are objects
  • A Message Object is characterised by its kind
  • This string property is used to distinguish
    messages from each other
  • The Message class supports a range of
    constructors with different mandatory arguments
  • Message objects can also contain an optional
    argument field for data associated with a
    particular message
  • The argument field can be either
  • Atomic String, int etc.
  • Tabular - Hashtable

24
Message Creation
  • public Message(String kind)
  • Constructs a message of a specific kind
  • Creates a default argument table that can hold a
    set of key-value pairs
  • setArg method can be used to initialise the
    argument table
  • public Message (String kind, Object arg)
  • Constructs a message of the specified kind with
    an Object as its initial bonding

25
Message Creation
  • public Message (String kind, int arg)
  • Constructs a message of the specified kind with
    an int as its initial argument
  • public Message (String kind, float arg)
  • Constructs a message of the specified kind with
    an float as its initial argument

26
Message Creation
  • public Message (String kind, long arg)
  • Constructs a message of the specified kind with
    an long as its initial argument
  • public Message (String kind, double arg)
  • Constructs a message of the specified kind with
    an double as its initial argument

27
Message Creation
  • public Message (String kind, char arg)
  • Constructs a message of the specified kind with
    an char as its initial argument
  • public Message (String kind, boolean arg)
  • Constructs a message of the specified kind with
    an boolean as its initial argument

28
Message Creation - Examples
  • Message msg new Message(Greeting , Happy
    Birthday)
  • Message msg new Message(Price, 200)

29
Receiving Messages
  • public String Message.getKind()
  • Gets the kind of the message
  • public boolean Message.sameKind(String)
  • Compares the kind of the message with the
    String Argument
  • public Object Message.getArg()
  • Gets the argument of the message

30
Non-atomic Messages
  • Nonatomic arguments have more than one argument
    to the receiver
  • Such Arguments are most effectively handled as
    key-value pairs
  • setArg and getArg methods are useful for
    organising multiple arguments into a table
  • public void Message.setArg(String key, Object
    value)
  • Maps the specified key to the specified value in
    the argument table
  • public Object Message.getArg(String key)
  • Gets the value to which the key is mapped in the
    argument table, null is there is no mapped value
    for the key

31
References
Lange, D.,B.(1998). Programming and Deploying
Java mobile agents with Aglets / Danny B. Lange,
Mitsuru Oshima. Reading, Mass Addison-Wesley,
c1998. http//www.vistabonita.com/papers/DCAglets/
http//www.trl.ibm.com/aglets/ http//www.geociti
es.com/SiliconValley/Lakes/8849/simple.htm http//
www.geocities.com/SiliconValley/Lakes/8849/roaming
.htm
Write a Comment
User Comments (0)
About PowerShow.com