java rmi l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Java RMI PowerPoint Presentation
Download Presentation
Java RMI

Loading in 2 Seconds...

play fullscreen
1 / 21

Java RMI - PowerPoint PPT Presentation


  • 307 Views
  • Uploaded on

Java RMI. Alcides Calsavara. Objetivos.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Java RMI' - paul


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
java rmi

Java RMI

Alcides Calsavara

objetivos
Objetivos
  • Permitir que um método de uma classe Java em execução em uma máquina virtual JVM chame um método de um objeto (instância de uma classe Java) situado em outra máquina virtual JVM, usando a mesma sintaxe e com a mesma facilidade de se chamar um método local.
  • Transparência de acesso e de localização.
esquema geral
Esquema geral

JVM servidor

objeto da

classe S

JVM cliente

método f

da classe C

em execução

método g

chamada

remota

remote method invocation
Remote Method Invocation
  • Facility to call methods remotely
      • Similar to RPC - Remote Procedure Call
      • High-level communication abstraction
  • The RMI mechanism provides:
      • control transfer between caller and called
      • parameters cans be exchanged
      • class definitions can be exchanged
  • RMI support in Java provides:
      • A specific API
      • compilation support tools
      • runtime support
general scenario

2

1

3

Client

Stub

Skeleton

Server

Registry

General scenario

naming service

get an object reference

object reference is published

perceived

actual

communication

componentes em execu o
Componentes em execução

cliente

servidor

cria

f de C

g de S

chamda remota de g

main

S_Stub

S_Skel

bind

lookup

Socket

Servidor

Socket

Cliente

Naming

Naming

Socket

Cliente

Socket

Servidor

Registry

hierarquia de classes e interfaces
Hierarquia de classes e interfaces

Classe UnicastRemoteObject

Interface Remote

extends

extends

Interface R

assinatura de g

Classe S

implementação de g

implements

compila o
Compilação

S.java

C.java

javac

javac

S.class

C.class

rmic

S_Skel.class

S_Stub.class

comandos
Comandos

Compilação:

javac S.java

rmic S

javac C.java

Execução (3 processos):

rmiregistry

java S

java C

a java rmi example
A Java RMI example

// file iCalendar.java

// specifies a date server interface

import java.rmi.* ;

public interface iCalendar

extends Remote

{

java.util.Date getDate ()

throws RemoteException ;

}

the rmi date server
The RMI date server

// file CalendarImpl.java

// the date server implementation

import java.util.Date;

import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

// ...

the rmi date server12
The RMI date server

public class CalendarImpl

extends UnicastRemoteObject

implements iCalendar {

public CalendarImpl()

throws RemoteException {}

public Date getDate ()

throws RemoteException {

return new Date ();

}

the rmi date server13
The RMI date server

public static void main(String args[]) {

CalendarImpl cal;

try {

cal = new CalendarImpl();

LocateRegistry.createRegistry(1099);

Naming.bind("rmi:///CalendarImpl",

cal);

System.out.println("Ready !");

}

catch (Exception e) {

e.printStackTrace();

}

}

the rmi date client
The RMI date client

// file CalendarUser.java

import java.util.Date;

import java.rmi.*;

public class CalendarUser

{

// constructor

public CalendarUser() {}

the rmi date client15
The RMI date client

public static void main(String args[])

{

long t1=0,t2=0;

Date date;

iCalendar remoteCal;

try {

remoteCal = (iCalendar) Naming.lookup

("rmi://some.host.com/CalendarImpl");

t1 = remoteCal.getDate().getTime();

t2 = remoteCal.getDate().getTime();

}

the rmi date client16
The RMI date client

catch (Exception e) {

e.printStackTrace();

}

System.out.println

("This RMI call took ”

+ (t2-t1) + " milliseconds");

} // main

} // class CalendarUser

rmi naming service
RMI naming service
  • Very simple
      • Manages pairs [name, object reference]
      • names are keys to get references
      • there is no “domain” notion
  • Implementation
      • Only one registry per process
      • Defaults to TCP/IP port 1099
      • Applications can register names onlyin a registry running on its host
      • Registry server can be launched manuallyor inside the program
naming service method calls
Naming service method calls
  • To create a registry at port 1099:

LocateRegistry.createRegistry (1099);

  • To bind a name to a reference:

Naming.bind ("rmi:///someobj", objRef);

  • To resolve a name:

obj = (objClass) Naming.lookup

("rmi://some.host/someobj");

dynamic class loaders
Dynamic class loaders
  • To dynamic load classes usedby a running program or applet
      • from the local disks or the network
  • Three kinds of class loaders:
      • Default class loader: to load the classesneeded by the JVM (CLASSPATH variable).
      • Applet class loader: to download appletsand additional classes from the applet server.
      • RMI class loader: to download from the remote server host all the classes (stubs, skeletons, parameters) to allow the RMI calls.
setting the rmi class loader
Setting the RMI class loader
  • On the client side:

// launch the RMI security manager

System.setSecurityManager (

new RMISecurityManager () );

// set a system property

System.getProperties ().put (

"java.rmi.server.codebase",

"http://some.where/java/classes/” );

  • On the server side:
      • Put stubs and classes at the indicated place
building apps with rmi

Client bytecode

rmic compiler

javac compiler

javac compiler

rmic compiler

Stub

Skeleton

Server bytecode

Building apps with RMI

Interface source code

server source code

client source code