G53ACC Advanced Computer Communications - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

G53ACC Advanced Computer Communications

Description:

Naming.rebind('//hamming/CityServer', obj); System.out.println ... { obj = (CallCity)Naming.lookup('//hamming/CityServer'); pop = obj.getPopulation('Toronto' ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 14
Provided by: Brai155
Category:

less

Transcript and Presenter's Notes

Title: G53ACC Advanced Computer Communications


1
G53ACC Advanced Computer Communications
  • Remote Method Invocation
  • Dr. Chris Greenhalgh

2
Contents
  • Parameter Passing in RMI
  • Real RMI Dynamic Loading
  • RMI Callback
  • RMI Summary

3
Argument Passing in Java RMI
  • All arguments must be either
  • Primitive data types (passed by value)
  • Objects that implement java.io.Serializable
    interface
  • an identical copy of the object is made, i.e. all
    fields are copied class can be remotely
    downloaded (e.g. HTTP) if java.rmi.server.codeba
    se property is set properly
  • any change to this objects state at the receiver
    is reflected only in the receivers copy, not in
    the original instance
  • Remote objects that implement the Remote
    interface
  • A remote object reference, a stub is passed
  • operations on the object will themselves be
    remote, e.g. callbacks

4
Dynamic Class Downloading
  • Stubs can be made available to the clients
    dynamically, normally via a web server using HTTP
    protocol
  • Doing so allows changes to be made in the remote
    methods without affecting the client programs
  • Security measures are needed to protect both the
    client and server if dynamic class downloading is
    required
  • A Java Security Manager should be instantiated
    with the proper security rules set in a java
    security policy file
  • java
  • -Djava.rmi.server.codebasehttp//sepang.nottingha
    m.edu.my/hsooihock/
  • -Djava.security.policyjava.policy TicketServer

5
RMI Callbacks
  • A client will have to poll a passive server
    repeatedly if it needs to keep abreast of any
    current changes and updates
  • Some applications require the server to actively
    initiate communication to the clients upon
    occurrence of certain events
  • Monitoring, Games, Auctioning, Voting/Polling,
    Message/Bulletin Board
  • RMI Callbacks can be implemented where registered
    clients can get server notifications (callbacks)
    when needed

6
RMI Callback Requirements
  • A remote method for clients registrations for
    callbacks
  • A remote interface specifying methods for
    accepting callbacks in addition to the server
    side interface.
  • The client must be a subclass of
    UnicastRemoteObject and implements the callback
    interface with the callback methods
  • The client registers itself for callback in its
    main method
  • The server invokes the clients remote method
    upon the occurrence of the anticipated events

7
RMI Callback Example (i)
  • import java.rmi.
  • /
  • _at_()CallCity.java
  • _at_author Qusay H. Mahmoud
  • /
  • public interface CallCity extends Remote
  • int getPopulation(String cityName) throws
    RemoteException
  • int getTemperature(String cityName) throws
    RemoteException
  • void register(Callback cb) throws
    RemoteException

8
RMI Callback Example (ii)
  • /
  • _at_()Callback.java
  • _at_author Qusay H. Mahmoud
  • /
  • public interface Callback
  • void tempChanged(String cityName, int
    temp)throws RemoteException

9
RMI Callback Example (iii)
  • import java.util.
  • import java.rmi.
  • import java.rmi.server.UnicastRemoteObject
  • /
  • _at_()CallCityImpl.java
  • _at_author Qusay H. Mahmoud
  • /
  • public class CallCityImpl extends
    UnicastRemoteObject implements CallCity
  • private String name
  • Vector list new Vector()
  • public CallCityImpl() throws RemoteException
  • super()
  • public CallCityImpl(String str) throws
    RemoteException

10
  • public int getPopulation(String cityName)
    throws RemoteException
  • if (cityName.equals("Toronto"))
  • return 10
  • else if (cityName.equals("Ottawa"))
  • return 2
  • else
  • return 100
  • public int getTemperature(String cityName)
    throws RemoteException
  • return 1
  • public void register(Callback cb) throws
    RemoteException
  • list.addElement(cb)
  • public void setTemp(String cityName, int tmp)

11
  • public static void main(String argv)
  • System.setSecurityManager(new
    RMISecurityManager())
  • try
  • CallCityImpl obj new CallCityImpl("CityS
    erver")
  • Naming.rebind("//hamming/CityServer",
    obj)
  • System.out.println("CityServer bound in
    registry")
  • catch (Exception e)
  • e.printStackTrace()

12
RMI Callback Example (iii)
  • import java.rmi.
  • import java.net.
  • /
  • _at_()CallCityApp.java
  • _at_author Qusay H. Mahmoud
  • /
  • public class CallCityApp implements Callback
  • public static void main(String argv)
  • int pop 0
  • Callback c (Callback) new
    CallCityApp()
  • CallCity obj null
  • try
  • obj (CallCity)Naming.lookup("//hamming/CityS
    erver")
  • pop obj.getPopulation("Toronto")
  • catch (Exception e)

13
  • // register the callback
  • try
  • obj.register(c)
  • catch(RemoteException e)
  • System.out.println("Error ")
  • e.printStackTrace()
  • //implement Callback interface
  • public void tempChanged(String cityName, int
    temp) throws RemoteException
  • System.out.println("Dynamic Update ")
  • System.out.println("CityName "cityName)
  • System.out.println("Temp "temp)
Write a Comment
User Comments (0)
About PowerShow.com