your source for information about Java..

News

Code Snippets

Events

 

> Snippets > Rmi pass-by-value example

This is a small example to demonstrate the pass-by-value concept in RMI. Real state is passed by over the wire instead of references like in CORBA e.g. More important it also demonstrates that stubs are transmitted over the wire so objects can really move from one server to another ( agent-like behaviour ).

The idea of this example is very simple :

A baby cries and needs help. The mother receives the getHelp from the baby but instead of help it returns a reference to the Nanny which can provides help to the Baby. The baby then calls the getHelp to the Nanny and gets help.

Normal scenario :

  1. Startup rmi-registry. Make sure the registry has access to the class-files !!
  2. Startup NannyImpl :
  3. NannyImpl registers itself to the registry ( Naming.rebind() )
  4. Startup MotherImpl
  5. MotherImpl registers itself to the registry
  6. Looks for Nanny and saves it in local var ("nanny")
  7. Startup Baby
  8. Baby looks for help and gets reference to Nanny from Mother
  9. Asks help from nanny and does so ( String )

The whole point of this exercise is : Does Baby use Mother to communicate to Nanny, since it does not look for a reference to Nanny in the registry, or does it get the stub of Nanny through the mother and after that Baby does not longer need the Mother. One scenario to test/demonstrate this is killing the mother after the baby gots the reference of the Nanny :

  1. Startup rmi-registry. Make sure the registry has access to the class-files !!
  2. Startup NannyImpl :
  3. NannyImpl registers itself to the registry ( Naming.rebind() )
  4. Startup MotherImpl
  5. MotherImpl registers itself to the registry
  6. Looks for Nanny and saves it in local var ("nanny")
  7. Startup Baby
  8. Baby looks for help and gets reference to Nanny from Mother
  9. Kill Mother
  10. Asks help from nanny and does so ( String )

Source-code :


© 2000 Sun Microsystems - Dieter Deramoudt

Feedback, comments : [email protected]