🗊Презентация Java RMI

Нажмите для полного просмотра!
Java RMI, слайд №1Java RMI, слайд №2Java RMI, слайд №3Java RMI, слайд №4Java RMI, слайд №5Java RMI, слайд №6Java RMI, слайд №7Java RMI, слайд №8Java RMI, слайд №9Java RMI, слайд №10Java RMI, слайд №11Java RMI, слайд №12Java RMI, слайд №13Java RMI, слайд №14Java RMI, слайд №15Java RMI, слайд №16

Вы можете ознакомиться и скачать презентацию на тему Java RMI. Доклад-сообщение содержит 16 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Java RMI
RMI = Remote Method Invocation.
Allows Java programs to invoke methods of remote objects.
Only between Java programs.
Several versions (JDK-1.1, JDK-1.2)
Описание слайда:
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1, JDK-1.2)

Слайд 2





Remote Method Invocation
Описание слайда:
Remote Method Invocation

Слайд 3





Interfaces (Transparency)
To client, remote object looks exactly like a local object (except that you must bind to it first).
Using interfaces:
you write interface for remote object
you write implementation for remote object
RMI creates stub class (implementing the remote object interface)
client accesses stub exactly same way it would access a local copy of the remote object
Описание слайда:
Interfaces (Transparency) To client, remote object looks exactly like a local object (except that you must bind to it first). Using interfaces: you write interface for remote object you write implementation for remote object RMI creates stub class (implementing the remote object interface) client accesses stub exactly same way it would access a local copy of the remote object

Слайд 4





RMI Registry
RMI needs a port mapper too:
servers can register contact address information
clients can locate servers
Called RMI registry
You must start it yourself (unlike RPC):
needs to be started on every machine that hosts server objects
program called rmiregistry
runs on port 1099 by default (but you can use ‘rmiregistry <port_nb>’)
Programs can access the registry thanks to java.rmi.Naming class.
Описание слайда:
RMI Registry RMI needs a port mapper too: servers can register contact address information clients can locate servers Called RMI registry You must start it yourself (unlike RPC): needs to be started on every machine that hosts server objects program called rmiregistry runs on port 1099 by default (but you can use ‘rmiregistry <port_nb>’) Programs can access the registry thanks to java.rmi.Naming class.

Слайд 5





Example
Simple program:
write interface for remote object: Remote.java
implementation of object: RemoteImpl.java
server to run object: RemoteServer.java
client to access object: Client.java
RMI compiler ‘rmic’ generates:
client stub: RemoteImpl_Stub.class (already compiled)
server skeleton: RemoteImpl_Skel.class (already compiled)
Описание слайда:
Example Simple program: write interface for remote object: Remote.java implementation of object: RemoteImpl.java server to run object: RemoteServer.java client to access object: Client.java RMI compiler ‘rmic’ generates: client stub: RemoteImpl_Stub.class (already compiled) server skeleton: RemoteImpl_Skel.class (already compiled)

Слайд 6





Example
Step 1: write interface Calculator.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Calculator extends Remote {
	public long add(long a, long b) throws RemoteException;
	public long sub(long a, long b) throws RemoteException;
	public long mul(long a, long b) throws RemoteException;
	public long div(long a, long b) throws RemoteException;
}

Few rules:
interface must extend java.rmi.Remote interface
methods must throw java.rmi.RemoteException exception
Compile:
$ javac Calculator.java
Описание слайда:
Example Step 1: write interface Calculator.java import java.rmi.Remote; import java.rmi.RemoteException; public interface Calculator extends Remote { public long add(long a, long b) throws RemoteException; public long sub(long a, long b) throws RemoteException; public long mul(long a, long b) throws RemoteException; public long div(long a, long b) throws RemoteException; } Few rules: interface must extend java.rmi.Remote interface methods must throw java.rmi.RemoteException exception Compile: $ javac Calculator.java

Слайд 7





Example
Step 2: write remote object CalculatorImpl.java
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class CalculatorImpl extends UnicastRemoteObject
	implements Calculator {
	// Implementations must have an explicit constructor
	public CalculatorImpl() throws RemoteException {
		super();
	}
	public long add(long a, long b) throws RemoteException {
		return a + b;
	}
	public long sub(long a, long b) throws RemoteException {
		return a - b;
	}
	public long mul(long a, long b) throws RemoteException {
		return a * b;
	}
	public long div(long a, long b) throws RemoteException {
		return a / b;
	}
}
Описание слайда:
Example Step 2: write remote object CalculatorImpl.java import java.rmi.server.UnicastRemoteObject; import java.rmi.RemoteException; public class CalculatorImpl extends UnicastRemoteObject implements Calculator { // Implementations must have an explicit constructor public CalculatorImpl() throws RemoteException { super(); } public long add(long a, long b) throws RemoteException { return a + b; } public long sub(long a, long b) throws RemoteException { return a - b; } public long mul(long a, long b) throws RemoteException { return a * b; } public long div(long a, long b) throws RemoteException { return a / b; } }

Слайд 8





Example
Implementation class must respect a few constraints:
must implement the interface (of course)
must inherit from the java.rmi.server.UnicastRemoteObject class
must have explicit constructor which throws the java.rmi.RemoteException exception
Compile:
$ javac CalculatorImpl.java
Описание слайда:
Example Implementation class must respect a few constraints: must implement the interface (of course) must inherit from the java.rmi.server.UnicastRemoteObject class must have explicit constructor which throws the java.rmi.RemoteException exception Compile: $ javac CalculatorImpl.java

Слайд 9





Example
Step 3: generate stub and skeleton
RMI compiler:
$ rmic CalculatorImpl
Generates CalculatorImpl_Stub.class and CalculatorImpl_Skel.class files.
Already compiled.
Описание слайда:
Example Step 3: generate stub and skeleton RMI compiler: $ rmic CalculatorImpl Generates CalculatorImpl_Stub.class and CalculatorImpl_Skel.class files. Already compiled.

Слайд 10





Example
Step 4: write server CalculatorServer.java
import java.rmi.Naming;
public class CalculatorServer {
	public CalculatorServer() {
		try {
			Calculator c = new CalculatorImpl();
			Naming.rebind(“rmi://localhost:1099/CalculatorService”, c);
		} catch (Exception e) {
			System.out.println(“Trouble: “ + e);
		}
	}
	public static void main(String args[]) {
		new CalculatorServer();
	}
}
Описание слайда:
Example Step 4: write server CalculatorServer.java import java.rmi.Naming; public class CalculatorServer { public CalculatorServer() { try { Calculator c = new CalculatorImpl(); Naming.rebind(“rmi://localhost:1099/CalculatorService”, c); } catch (Exception e) { System.out.println(“Trouble: “ + e); } } public static void main(String args[]) { new CalculatorServer(); } }

Слайд 11





Example
Server program creates CalculatorImpl object.
Registers object to local RMI registry (‘rebind()’):
rebind(String name, Remote obj) associates a name to an object
names are in the form of a URL:
rmi://<host_name>[:port]/<service_name>
Server waits for incoming requests
$ javac CalculatorServer.java
Описание слайда:
Example Server program creates CalculatorImpl object. Registers object to local RMI registry (‘rebind()’): rebind(String name, Remote obj) associates a name to an object names are in the form of a URL: rmi://<host_name>[:port]/<service_name> Server waits for incoming requests $ javac CalculatorServer.java

Слайд 12





Example
Step 5: write CalculatorClient.java
import java.net.MalformedURLException;
public class CalculatorClient {
	public static void main(String[] args) {
		try {
			Calculator c = (Calculator)
			       Naming.lookup(“rmi://wizard.cse.nd.edu/CalculatorService”);
			System.out.println(c.add(4,5));
			System.out.println(c.sub(4,3));
		}
		catch (Exception e) {
			System.out.println(“Received Exception:”);
			System.out.println(e);
		}
	}
}
Описание слайда:
Example Step 5: write CalculatorClient.java import java.net.MalformedURLException; public class CalculatorClient { public static void main(String[] args) { try { Calculator c = (Calculator) Naming.lookup(“rmi://wizard.cse.nd.edu/CalculatorService”); System.out.println(c.add(4,5)); System.out.println(c.sub(4,3)); } catch (Exception e) { System.out.println(“Received Exception:”); System.out.println(e); } } }

Слайд 13





Example
Before invoking the server, the client must ‘lookup’ the registry:
must provide the URL for remote service
gets back a stub which has exactly the same interface as the server
can use it as a local object: long x = c.add(4,5);
Compile:
$ javac CalculatorClient.java
Описание слайда:
Example Before invoking the server, the client must ‘lookup’ the registry: must provide the URL for remote service gets back a stub which has exactly the same interface as the server can use it as a local object: long x = c.add(4,5); Compile: $ javac CalculatorClient.java

Слайд 14





Example
Step 6: test it!
Start the RMI registry: rmiregistry
registry must have access to your classes
either start the registry in the same directory as the classes or make sure directory is listed in $CLASSPATH variable
Start server: java CalculatorServer
Start client:
$ java CalculatorClient
9
1
$
Описание слайда:
Example Step 6: test it! Start the RMI registry: rmiregistry registry must have access to your classes either start the registry in the same directory as the classes or make sure directory is listed in $CLASSPATH variable Start server: java CalculatorServer Start client: $ java CalculatorClient 9 1 $

Слайд 15





Using RMI in a Distributed Context
First, test your program on a single host.
To use it on 2 machines:
server and rmiregistry need the following files:
Calculator.class (server object interface)
CalculatorImpl.class (server object implementation)
CalculatorImpl_Stub.class (stub)
CalculatorServer.class (server program)
client needs:
Calculator.class (server object interface)
CalculatorImpl_Stub.class (stub)
CalculatorClient.class (client program)
nobody needs the skeleton file CalculatorImpl_Skel.class
generated only for compatibility with JDK-1.1
Описание слайда:
Using RMI in a Distributed Context First, test your program on a single host. To use it on 2 machines: server and rmiregistry need the following files: Calculator.class (server object interface) CalculatorImpl.class (server object implementation) CalculatorImpl_Stub.class (stub) CalculatorServer.class (server program) client needs: Calculator.class (server object interface) CalculatorImpl_Stub.class (stub) CalculatorClient.class (client program) nobody needs the skeleton file CalculatorImpl_Skel.class generated only for compatibility with JDK-1.1

Слайд 16





Method Parameters Transfer
Base types (int, float, char) are transferred directly.
Remote objects (inheriting from java.rmi.Remote) are not transferred:
instead, a distributed reference to object is shipped
any invocation to this object will result in a RMI request
Non-remote objects are serialized and shipped:
the object itself plus every other object that it refers to (recursively)
remote invocations pass objects by value (local by reference)
very easy to transfer huge quantities of data without noticing (you have database in memory and you transfer an object which contains a reference to database)
Описание слайда:
Method Parameters Transfer Base types (int, float, char) are transferred directly. Remote objects (inheriting from java.rmi.Remote) are not transferred: instead, a distributed reference to object is shipped any invocation to this object will result in a RMI request Non-remote objects are serialized and shipped: the object itself plus every other object that it refers to (recursively) remote invocations pass objects by value (local by reference) very easy to transfer huge quantities of data without noticing (you have database in memory and you transfer an object which contains a reference to database)



Теги Java RMI
Похожие презентации
Mypresentation.ru
Загрузить презентацию