Download - 04-分布式对象和远程调用
-
4
-
4:Remote procedure callJava RMI
-
/ N/
-
---ORB(Object Request Broker)
-
RPC--Remote Procedure Call ) RMI--Remote Method Invocation ) Event-based model
-
bigendianlitterendianmashellAPI CORBAIDL
-
---Location transparencyCommunication protocols
-
Interfaces
-
RPCs Service interface RMIs Remote interface,
-
IDLsInterface Definition Languages Java RMI javaIDLs. e.g. CORBA IDL (n1), DCE IDL and DCOM IDL
-
4:Remote procedure callEvents and notificationsJava RMI
-
The object modelDistributed objectsThe distributed object model
-
object reference interfaceActions ExceptionsGarbage collection
-
/server, client. server client.
-
. E.g. B & FE.g. C E E.g., B
-
Invocation semantics RRP RRP Retry Request message: Duplicate filtering: Retransmission of result:
-
Invocation semanticsexactly onceexactly once RRPMaybe maybe
-
Invocation semanticsAt-least-once Sun RPC ,
-
Invocation semanticsAt-most-once JavaRMI
-
failure modelTCP/IP exactly once.at most once.at least once
-
Invocation semantics
-
12 serverB, clientBRRMRRM RMI RRMRRM
-
RMI software proxy, skeleton dispatcher
-
proxy
-
proxyserverskeletondispatcher dispatcher ProxydispatchermethodId skeleton Skeletonserver
-
5:Remote Procedure CallEvents and notificationsJava RMI
-
Sun RPC case studyRPC RPC /(server)server(client) clientserver
-
Sun RPC case study continued
-
Sun RPC case study continuedRPCStub
-
Sun RPC case study continuedfn() stubstubc_fn()stubs_fn() fn() fn()c_fn() fn(), fn()s_fn()
-
Sun RPC case study continuedStub marshal() unmarshal( )Marshal DCE RPC Network Data RepresentationNDRunmarshalNDR
-
Sun RPC case study continuedClient stubmarshal (network data representation , NDR) Client runtime systemunmarshal
-
Sun RPC case study continuedServer stubunmarshal marshal
-
Sun RPC case study continuedIDL compilerIDL Header IDL headerClient stubstubServer stubstub
-
Sun RPC case study continuedClient codeServer code stub
-
Sun RPC case study continuedstub serverTCP/UDP Server socketServer Stub
-
Service interface: the procedures that are available for remote callingInvocation semantics choice: at-least-once or at-most-onceGenerally implemented over request-reply protocolBuilding blocksCommunication moduleClient stub procedure (as proxy in RMI): marshalling, sending, unmarshallingDispatcher: select one of the server stub proceduresServer stub procedure (as skeleton in RMI): unmarshalling, calling, marshalling
-
Sun RPC case studyNFSat-least-once semanticsXDR - Interface definition languageInterface name: Program number, version numberProcedure identifier: procedure numberRpcgen generator of RPC componentsclient stub procedureserver main procedureDispatcherserver stub proceduremarshalling and unmarshalling procedure
-
Sun RPC case study continuedBinding portmapperServer: register ((program number, version number), port number)Client: request port number by (program number, version number)AuthenticationEach request contains the credentials of the user, e.g. uid and gid of the userAccess control according to the credential information
-
//RPC struct call_body {unsigned int rpcvers; unsigned int prog; unsigned int vers; unsigned int proc;opaque_auth cred; opaque_auth verf; parameter 1 parameter 2. . .}; Sun Microsystems Open Network Computing. The ONCuses XDR as the external data representation standard
-
Sun RPC case study RPC Stub DCE RPCIDL stubRPC
-
5:Remote procedure callEvents and notificationsJava RMI
-
Publish/subscribe paradigm
-
Information provider
-
.
-
IP
-
RSS Web "Push" (Protocol)RSSReally Simple Syndication RDF (Resource Description Framework) Site SummaryRich Site Summary SyndicationRSS blog wiki RSS
-
Jini Jini?JiniSunJini --- ---JiniJiniJini
-
JiniDiscovery and Join Lookup () LookupNetwork Services ---Other Services ---Leasing ---Transactions ---Distributed Event---Other OS ---Other CPU ---CPU
-
JiniDiscovery and Join 512 Discovery
-
JiniJini Lookup DiscoveryLookup Lookup Jini Lookup Discovery and JoinJoinDiscovery LookupLookup ()LookupLookup /
-
JiniLookup Lookup Lookup Lookup ( postscript) LookupPeer Lookup (Lookup ) LookupPeer Lookup Lookup Discovery and Join
-
Jini Jini Discovery and Join Lookup
-
JiniJava Jini Java APIAPI rool back JiniJini JavaSpace
-
Jini JavaJini Java API () ()
-
5:
Remote procedure callEvents and notificationsJava RMI
-
Java RMI remote method invocation(RMI)Jdk1.1(1997.02)Jdk1.2Access to Remote ObjectsClient-Server ProtocolHigh-level APIJava-to-Java onlyTransparentLightweight
-
Java RMI RPCRMI->->
-
Java RMI RMI(Remote Interface)(Remote Service)StubSkeletonRMI
-
Java RMI RMIJavaJavaRMICStubSkeleton (host)Java RMIJava
-
Java RMI RMIserver, client .RMIserverclientRMI
-
Java RMI ---import java.rmi.*;public interface compute extends Remote {public int add(int x, int y)throws RemoteException;}
-
Java RMI ---import java.rmi.*;import java.rmi.server.*;public class AdderImpl extends UnicastRemoteObjectimplements Compute {public AdderImpl() throws RemoteException {}public int add(int x, int y)throws RemoteException {return x + y;}
-
Java RMI ---
-
Java RMI ---stubsskeletonStubsskeletons rmicStubskeleton
-
Java RMI ---Object Serialization( Stream)
-
Java RMI ---
-
Java RMI ---RMI RMI Registry, 1099.(object servers will bedynamically assigned ports by theRMI runtime)stub
-
Java RMI ---Server-sideRMI ( ). RMI Registry
-
Java RMI ---Client-sidejava.rmi.Naming RMI Registrylookup() URL:rmi://[:]/
-
Java RMI ---
-
Java RMI ---
-
Java RMI ---
-
Java RMI ---
-
RMI:
-
RMIRMI, 1. RMI 2. RMI JavaRMI RMI
-
RMI:Engin,,task.engin ..:,, engin.server CPU .:RMI.
-
RMI:,,: engintask,Task ,engin.,
-
RMICompute engin:1. compute engine ComputeEngine , Compute, executeTask, .2. Client engin.client server.3. ,, .4. execute.
-
RMI
-
RMI, :1. 2. 3. 4. enginmain:
-
package engine;import java.rmi.*; import java.rmi.server.*; import compute.*;public class ComputeEngine extends UnicastRemoteObject implements Compute{ public ComputeEngine() throws RemoteException{ super(); }public Object executeTask(Task t){ return t.execute(); }public static void main(String[] args){ if (System.getSecurityManager() == null){ System.setSecurityManager(new RMISecurityManager()); } String name = "//host/Compute";try { Compute engine = new ComputeEngine(); Naming.rebind(name, engine); System.out.println("ComputeEngine bound");} catch (Exception e) { System.err.println("ComputeEngine exception: " + e.getMessage()); e.printStackTrace(); }}
-
RMI,super(), a UnicastRemoteObject ,, .engin, , . .
-
RMI:1. . stub,. 2. . ,.
-
RMI RMImain computer engincomputer engin
-
RMI
task
-
RMIcomputePi1. ,2. 3.
-
package client;mport java.rmi.*; import java.math.*; import compute.*;public class ComputePi {public static void main(String args[]) {if (System.getSecurityManager() == null){ System.setSecurityManager(new RMISecurityManager()); }try { String name = "//" + args[0] + "/Compute";Compute comp = (Compute) Naming.lookup(name);Pi task = new Pi(Integer.parseInt(args[1]));BigDecimal pi = (BigDecimal) (comp.executeTask(task));System.out.println(pi);} catch (Exception e) {System.err.println("ComputePi exception: " + e.getMessage());e.printStackTrace(); }}
-
RMI
-
package client;import compute.*; import java.math.*;public class Pi implements Task {private static final BigDecimal ZERO = BigDecimal.valueOf(0);private static final BigDecimal ONE = BigDecimal.valueOf(1);private static final BigDecimal FOUR = BigDecimal.valueOf(4);private static final int roundingMode = BigDecimal.ROUND_HALF_EVEN;public Pi(int digits){ this.digits = digits; }
-
public Object execute(){ return computePi(digits); }*************************************************** pi/4 = 4*arctan(1/5) - arctan(1/239)**************************************************public static BigDecimal computePi(int digits) {int scale = digits + 5;BigDecimal arctan1_5 = arctan(5, scale);BigDecimal arctan1_239 = arctan(239, scale);BigDecimal piarctan1_5.multiply(FOUR).subtract(arctan1_239).multiply(FOUR);return pi.setScale(digits, BigDecimal.ROUND_HALF_UP); }
-
/*** Compute the value, in radians, of the arctangent of* the inverse of the supplied integer to the speficied* number of digits after the decimal point. The value* is computed using the power series expansion for the* arctangent:* arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 +*(x^9)/9 ...*/
-
public static BigDecimal arctan(int inverseX, int scale){ BigDecimal result, numer, term;BigDecimal invX = BigDecimal.valueOf(inverseX);BigDecimal invX2 =BigDecimal.valueOf(inverseX * inverseX);numer = ONE.divide(invX, scale, roundingMode);result = numer;int i = 1;do { numer =numer.divide(invX2, scale, roundingMode);int denom = 2 * i + 1;term = numer.divide(BigDecimal.valueOf(denom),scale, roundingMode);if ((i % 2) != 0) { result = result.subtract(term); }else { result = result.add(term); }i++;} while (term.compareTo(ZERO) != 0);return result;
-
RMI engin Rmi1. 2. 3. 4.
-
RMI 1. compute ( Compute and Task interfaces)2. engine ( ComputeEngine implementation class and its stub)3. client ( ComputePi client code and Pi task implementation)
-
RMI
-
5:Remote procedure callEvents and notificationsJava RMI
-
RMISun RPC
-
project1 atleast-onceatleast-once