Java%20RMI%20(more) - PowerPoint PPT Presentation

About This Presentation
Title:

Java%20RMI%20(more)

Description:

This really the interface for the servers methods. Must be public. must extend Remote ... import java.rmi.*; import java.rmi.server.UnicastRemoteObject; ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 10
Provided by: dickst
Category:
Tags: 20rmi | java | more | reimport

less

Transcript and Presenter's Notes

Title: Java%20RMI%20(more)


1
Java RMI (more)
  • CS-328
  • Internet Programming

2
Remote Interface
  • This really the interface for the servers methods
  • Must be public
  • must extend Remote
  • each method in the interface must throw
    RemoteException in addition to any application
    specific exceptions

3
Example
package rmi.hello public interface Hello extends
java.rmi.Remote String sayHello() throws
java.rmi.RemoteException
4
Remote Object Implememtation
  • Must specify the remote interfaces being
    implemented
  • optionally extend a remote server
  • extending UnicastRemoteObject indicates a single,
    non-replicated remote object
  • define the default constructor
  • must throw RemoteException
  • provide an implementation for each remote method
    defined in the interface
  • create and install a security manager either
    RMISecurityManager or one you have defined
  • create one or more instances of remote object
  • register at least one object with the RMI
    Registry

5
Example
package rmi.hello import java.rmi. import
java.rmi.server.UnicastRemoteObject public class
HelloImpl extends UnicastRemoteObject implements
Hello private String name public
HelloImpl(String s) throws java.rmi.RemoteExceptio
n super() name s public
String sayHello() throws RemoteException
return Hello World public static void
main (String args)
System.setSecurityManager(new RMISecurityManager()
) try HelloImpl obj
new HelloImpl(HELLOSERVER)
Naming.rebind(HELLOSERVER,obj)
System.out.println( HelloImpl created and bound
to registry as HELLOSERVER) catch
(Exception e) System.out.println
(Exception e.toString)
6
UnicastRemoteObject
  • A form of a remote server
  • the server cannot be started remotely, must
    already exist and the reference exists only as
    long as the process
  • Uses TCP/IP ( the RMI specification is written
    for network protocol independence)
  • An object stream is used to parameters and methos
    invocations between client and server
  • Other types of servers will be made available as
    they are developed
  • JDK 1.3 also provides Multicast

7
Local Client
  • look-up the remote object and get a reference to
    its local stub
  • invoke one or more remote methods
  • just like invoking a method on a local object

8
Example
package rmi.hello import java.rmi. import
java.awt. public class HelloApplet extends
java.applet.Applet String message
public void init() try
Hello obj (Hello)Naming.lookup(//
getCodeBase().getHost()
/HELLOSERVER) message
obj.sayHello() catch (Exception e)
System.out.println(Exception
e.toString()) public void
paint(Graphics g) g.drawString(message, 25,
50)
9
HTML
lthtmlgt ltheadgt lttitlegtHello Worldlt/titlegt lt/headgt lt
bodygt ltpgtThe message from the Hello Server
is ltapplet codebase../..
codermi.hello.HelloApplet
width500 height120gt lt/appletgt lt/htmlgt
Write a Comment
User Comments (0)
About PowerShow.com