分布式调用

1. Explain the RMI architecture?

Java Remote Method Invocation(RMI) provides a way for a java program on one JVM to communicate with objects residing in different JVMs. The important parts of the RMI architecture are the stub class, object serialization and the skeleton class. RMI has the following layers:

n          Application Layer: The client and server program.

n          Stub & Skeleton Layer: Intercepts method calls made by the client. Redirects these class to a remote RMI service.

n          Remote Reference Layer: Sets up connections to remote address spaces, manages connections, and understands how to interpret and manage references made from clients to the remote service objects.

n          Transport Layer: Based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies.

Design Pattern: RMI stub class provide a reference to a skeleton object located

in another JVM. It is a typical example of a Proxy Design Pattern(remote proxy).   

RMI runtime steps:

n          Step 1: Start RMI registry and then the RMI server. Bind the remote objects to the RMI registry.

n          Step 2: The client process will look up the remote object from the RMI registry.

n          Step 3: The lookup will return the stub to the client process from the server process.

n          Step 4: The client process will invoke method calls on the stub. The stub calls the skeleton on the server process through the RMI reference manager.

n          Step 5: The skeleton will execute the actual method call on the remote object and return the results to the client process via the RMI reference manager and the stub.

 

2What is a remote object? Why should we extend UnicastRemoteObject   

A remote object is one whose methods can be invoked from another JVM. A remote object class must implement the Remote interface. A RMI Server is an application that creates a number of remote objects.

A RMI Server is responsible for:

n          Creating an instance of the remote object.

n          Exporting the remote object.

n          Binding the instance of the remote object to the RMI registry.

You make it available to accept incoming calls from the client by exporting a remote object in the two way:

l          extends java.rmi.server.UnicastRemoteObject

l          UnicastRemoteObject.exportObject (this); then the implementation class is responsible for the correct implementations of the hashCode(), equals() and toString() methods.

A remote object is registered in the RMI registry using:

    Naming.rebind(String serviceName, Remote remoteObj);

Use rmic to generate stubs & skeleton. For example, rmic –d /classes CarImpl

 

3. What are the services provided by the RMI Object?

n          Object naming/registry service: RMI servers can provide services to clients by registering one or more remote objects with its local RMI registry.

n          Object activation service: It provides a way for server (i.e. remote) objects to be started on an s-needed basis. Without the remote activation service, a server object has to be registered with the RMI registry service.

n          Distributed garbage collection: It is an automatic process where an object, which has no further remote references, becomes a candidate for garbage collection.

 

4. How will you pass parameters in RMI?

n          Primitive types are passed by value (e.g. int, char, boolean etc).

n          References to remote objects (i.e. objects which implement the Remote interface) are passed as remote references that allow the client process to invoke methods on the remote objects.

n          Non-remote objects are passed by value using object serialization. These objects should allow them to be serialized by implementing the java.io.Serializable interface.

 

5. What is HTTP tunneling or how do you make RMI calls across firewalls?

RMI transport layer generally opens direct sockets to the server. Many Intranets have firewalls that do not allow this. To get through the firewall an RMI call can be embedded within the firewall-trusted HTTP protocol. To get across firewalls, RMI makes use of HTTP tunneling by encapsulating RMI calls within an HTTP POST request.

 

6. What are the differences among Socket, RMI,EJB, CORBA?

Socket

A socket is a transport mechanism. Sockets are like applying procedural networking to object oriented environment. Sockets-based network programming can be laborious.

RMI

RMI uses sockets. RMI is object oriented. Methods can be invoked on the remote objects running on a separate JVM. RMI provides a convenient abstraction over raw sockets. Can send and receive any valid Java object utilizing underlying object serialization without having to worry about using data streams. Java only solution. RMI allows dynamic loading of classes at runtime.

EJB

EJBs are distributed components, which use the RMI framework for object distribution. An EJB application server provides more services like transaction management, object pooling, database connection-pooling etc, which RMI does not provide. These extra services that are provided by the EJB server simplify the programming effort at the cost of performance overhead compared to plain RMI. So if performance is important then pure RMI may be a better solution (or under extreme situations Sockets can offer better performance than RMI).

CORBA

CORBA was made specifically for interoperability among various languages. For example the server could be written in C++ and the business logic can be in Java and the client can be written in COBOL.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值