Class PingPong

java.lang.Object
  |
  +--org.objectweb.mobilitools.smi.goodies.BasicMobileObject
        |
        +--PingPong
All Implemented Interfaces:
MobileObject, java.io.Serializable

public class PingPong
extends BasicMobileObject

MobiliTools $Name: $, $Id: PingPong.java,v 1.1.1.1 2003/03/28 14:47:58 dillense Exp $

This agent example class shows the visibility rules between classes of agents loaded with different classloaders and, more important, with different codebases. These rules typically depends on the class loader adapter (factory) used. By default, SMI uses the SMIClassLoader which comes with the following principles:

As a result, agents with the same codebase may use/invoke each other's classes/instances, while agents of different codebases will get an exception trying to do so.

The easiest way to use this example is to use GUI-enabled agencies. Create, suspend/resume or move PingPong agents with a variety of codebases, to see how they can interact with each other in an agency (have a look at the messages printed in the associated terminal).

See Also:
Serialized Form

Field Summary
(package private)  java.lang.String my_name
           
 
Fields inherited from class org.objectweb.mobilitools.smi.goodies.BasicMobileObject
my_agency
 
Constructor Summary
PingPong()
           
 
Method Summary
 void afterBirth(AgentSystem agency, AgentInfo info, java.lang.Object arg)
          Set an appropriate property for the PingPong agent to be found by other PingPong agents.
 void afterMove(AgentSystem agency, Location location, java.lang.String place)
          Lookup PingPong agents in current agency and try to invoke their ping() method
 void beforeResume()
          Lookup PingPong agents in current agency and try to invoke their ping() method
 java.lang.String ping(PingPong agent)
          This method is invoked on each other by PingPong agents.
 
Methods inherited from class org.objectweb.mobilitools.smi.goodies.BasicMobileObject
afterMoveFailed, beforeDeath, beforeMove, beforeShutdown, beforeSuspend
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

my_name

java.lang.String my_name
Constructor Detail

PingPong

public PingPong()
Method Detail

ping

public java.lang.String ping(PingPong agent)
This method is invoked on each other by PingPong agents.

afterBirth

public void afterBirth(AgentSystem agency,
                       AgentInfo info,
                       java.lang.Object arg)
                throws BadOperation
Set an appropriate property for the PingPong agent to be found by other PingPong agents.
Overrides:
afterBirth in class BasicMobileObject

beforeResume

public void beforeResume()
Lookup PingPong agents in current agency and try to invoke their ping() method
Overrides:
beforeResume in class BasicMobileObject

afterMove

public void afterMove(AgentSystem agency,
                      Location location,
                      java.lang.String place)
               throws BadOperation
Lookup PingPong agents in current agency and try to invoke their ping() method
Overrides:
afterMove in class BasicMobileObject