Amazon

Wednesday, May 12, 2010

EJB 2.0 Chapter 01 EJB Architecture

Client <-> Stub(Local to client, knows network communication) <-> Skeleton (knows network communication)<->Remote Object

Stub -> Remote object proxy at client side.
Skeleton -> Its optional, but its work must be done by something on server.

RMI promotes network transparency.

Skeleton
Accepts network (socket) connection from stub.
Figures out which method to call on which object.
Calls method on Remote Object.

java.rmi.RemoteException
Checked Exception.
Client has to handle or declare the exception.

Network Shippable Values must be one of these
Primitives.
Serializable objects.
An array or collection of primitives or serializable objects.
A Remote Object.

Method Call
Local means same heap/jvm. Java passes an object reference by value in case of local method call. And for Remote method call serializable copy of the actual object is passed.

When a Remote object is passed to/from a remote method, Java actually sends Remote object's stub.

Being Serializable
Collection implementation in J2Se are Serializable. Its a good practice to explicitly declare a class serializable.

Business Interface has business methods the client wants to call. Business method of a Remote object must follow three Rules
Must extend java.rmi.Remote.
Each method must declare a java.rmi.RemoteException.
Arguments and return values must be shippable on network.

Client -> Remote Business Interface -> Stub.

The Stub and the Remote Object, both implement Remote Business Interface.

EjbObject
The Remote object is the bean's bodyguard.
Implements the Remote Interface and takes Remote Calls.
When calls get to EjbObject the server jumps in with all the services like
Security - is client authorized to call the method
Transactions - is the call part of existing txn or new txn.
Persistence - does bean need to load info from DB before running the client's method.

RMI interface extends java.rmi.Remote.
EJB business interface extends javax.ejb.EJBObject.

What happens when EJB is deployed

Remote Interface
Bean does not implement the Remote Interface because the bean is never supposed to be a Remote Object i.e. we don't want stub of an actual bean i.e. client can't talk directly to EJB so that server will come between client and EJB to apply services.

Component Interface
Container writes the class which implement component interface. It also extends EjbObject. This can pretend as Ejb and respond to client calls i.e. calls from Stub. Its only job is to capture the request from client to bean. Its implementation is totally vendor dependent.

Bean
When a Bean is deployed, the container looks at DD, it generates classes implementing the Remote Component (EJBObject) and Remote Home Interface. And because they are Remote the container also creates Stubs, that know how to communicate back to the Remote Objects.

RMI - IIOP
Stubs should be RMI-IIOP compliant. Remote objects also follow same. Plain old RMI uses JRMP as its wire protocol. But IIOP lets Remote Objects interoperate through CORBA, this gives objects a chance to be accessed, for example by non-java client.

MDBs don't have homes because they don't have client view i.e. clients can't get reference to a MDB.

Home's main job is to hand out references to a bean's component interface. Each deployed bean has its own home, and that home is responsible for all bean instances of that type. e.g. if 2000 clients each want their own shopping cart bean references the one and only shopping cart Home will hand out all 2000 references.

Clients share the same home, may share the bean. If all the clients trying to access 'Fred Smith #420', they will each have their own stub, but all stubs will communicate with the same Remote Ejb Object. EJBObject is the body guard of actual bean.

Stateless Session beans are more scalable, because unlike stateful session beans every client get their own EJBObject, i.e. they don't share EJBObject i.e. same bean can serve multiple EJBObjects, just not at the same time. The bean comes out of the pool only when a client invokes a business method on the EJBObject stub.
But different pool for different stateless session beans.

No comments:

Post a Comment

Amazon Best Sellors

TOGAF 9.2 - STUDY [ The Open Group Architecture Framework ] - Chap 01 - Introduction

100 Feet View of TOGAF  What is Enterprise? Collection of Organization that has common set of Goals. Enterprise has People - organized by co...