Presentation is loading. Please wait.

Presentation is loading. Please wait.

Middleware Technology (J2EE/EJB) EJB Fundamentals.

Similar presentations


Presentation on theme: "Middleware Technology (J2EE/EJB) EJB Fundamentals."— Presentation transcript:

1 Middleware Technology (J2EE/EJB) EJB Fundamentals

2 2 Enterprise Bean A server-side software component which can be deployed in a distributed multi- tier environment. EJB specification requires that your beans expose a few required methods that allow the EJB container to manage beans uniformly, regardless of which container your beans is running in.

3 3 Types of Enterprise Bean Session Bean business process, actions such as adding numbers 、 calling other enterprise beans (CMP 、 BMP).  Stateless  StatefulejbActivate ejbPassivate Entity Bean business data , session beans harness entity beans to achieve business goals.  BMP (Bean Management Persistence) ejbLoad ejbStore  CMP (Container Management Persistence) Message-Driven Bean Asynchronous communication, JMS

4 4 Table 2.1 Session Beans Calling Entity Beans Session BeansEntity Beans Bank tellerBank account Credit card authorizerCredit card DNA sequencerDNA strand Order entry systemOrder, Line item Catalog engineProduct Auction brokerBid, Item Purchase order approval routerPurchase order

5 5 Figure 2.1 EJB Clients

6 6 Distributed Objects EJB components are based on distributed objects. A distributed object can be called from an in-process client, an out-of-process client, or a client located elsewhere on the network. Three different technologies  OMG’s CORBA (Common Object Request Broker Architecture)  Microsoft’s DCOM  Sun’s Java RMI-IIOP

7 7 Figure 2.2 Distributed Object

8 8 Client Object Reference Stub Servant Skeleton Server network Client and server are collocated in different address space.

9 9 Client and Server Object Reference Proxy Servant Client and server are collocated in the same address space. Location Transparency No changes to the source code are necessary in either client or server.

10 10 Distributed Objects and Middleware Explicit Middleware (transaction, security, etc.)  Difficult to write  Difficult to maintain  Difficult to support

11 11 Explicit Middleware (gained through API)

12 12 Distributed Objects and Middleware Implicit Middleware (Recommended)JTS Instead of writing any code to middleware APIs, you declare what you need in a simple text file. The request interceptor provide the middleware logic for you transparently

13 13 Implicit Middleware (gained through declaration)

14 14 Enterprise Bean Constitution Enterprise Bean Class An enterprise bean class contains implementation details of your component and conforms to a well-defined interface and certain rules which are necessary for your beans to run in any EJB container.  Session Beans: business-process-related logic javax.ejb.SessionBean  Entity Beans: data-related logic javax.ejb.EntityBean  message-oriented logic javax.ejb.MessageDrivenBean public interface javax.ejb.EnterpriseBean extends java.io.Serializable {... }

15 15 Enterprise Bean Constitution The EJB Object The client never invokes the methods directly on an actual bean instance. Rather, the invocation is intercepted by the EJB container, and then delegated to the bean instance. The EJB container automatically performs the implicit middleware. Services (See also : page 39)

16 16 Enterprise Bean Constitution EJB objects clone and expose every business method that the bean itself expose, and it acts as a surrogate object between the client and the bean. We could think of EJB objects as physical parts of the container, all EJB objects have container-specific code inside of them. So container vendor generates the class file for your EJB Object automatically.  The Remote Interface This interface duplicate all the business methods that the corresponding bean class expose.

17 17 Enterprise Bean Constitution  Java RMI-IIOP and EJB Objects Every javax.ejb.EJBObject extends java.rmi.Remote which is part of Java Remote Method Invocation over Internet Inter- ORB Protocol (RMI-IIOP). (1) Any object that implements javax.rmi.Remote interface is a remote object and is callable from a different JVM. (2) Any method that is part of a remote object must throw a special remote exception. The parameters you pass in method must be valid types for RMI-IIOP, such as primitives, serializable objects and RMI-IIOP remote objects

18 18 Figure 2.5 EJB Objects

19 19 public interface javax.ejb.EJBObject extends java.rmi.Remote { public javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException; public java.lang.Object getPrimaryKey() throws java.rmi.RemoteException; public void remove() throws java.rmi.RemoteException, javax.ejb.RemoveException; public javax.ejb.Handle getHandle() throws java.rmi.RemoteException; public boolean isIdentical(javax.ejb.EJBObject) throws java.rmi.RemoteException; } EJBObject interface source

20 20 Enterprise Bean Constitution The Home Object EJB promotes location transparency, so clients should never be aware of exactly where an EJB object resides. To acquire a reference to an EJB object, your client code asks for an EJB object from an EJB object factory which is called a home object. Chief responsibilities of home objects:  create EJB objects  find existing EJB objects  remove EJB objects Home objects are physically part of the container and are automatically generated by the container vendor’s tool.

21 21  The Home Interface The container’s home object implements your home interface. Home interface simply defines methods for creating, destroying, and finding EJB objects. Your home interface must extend javax.ejb.EJBHome interface. Enterprise Bean Constitution

22 22 Figure 2.6 Home Object

23 23 public interface javax.ejb.EJBHome extends java.rmi.Remote { public EJBMetaData getEJBMetaData() throws java.rmi.RemoteException; public javax.ejb.HomeHandle getHomeHandle() throws java.rmi.RemoteException; public void remove(javax.ejb.Handle handle) throws java.rmi.RemoteException, javax.ejb.RemoveException; public void remove(Object primaryKey) throws java.rmi.RemoteException, javax.ejb.RemoveException; } EJBHome interface source

24 24 7 steps in remote invocation (1) The client calls a local stub. (2) The stub marshals parameters into a form suitable for the network. (3) The stub goes over a network connection to the skeleton. (4) The skeleton demarshals parameters into a form suitable for Java. (5) The skeleton calls the EJB object. (6) The EJB object performs needed middleware, such as connection pooling, transactions, security, and lifecycle services. (7 )Once the EJB object calls the enterprise bean instance, and the bean does its work, each of the preceding steps must be repeated for the return trip home.

25 25 Enterprise Bean Constitution The Local Interfaces EJB 2.0 specification provides a local interface rather than a remote interface, and local home interface rather than home interface to avoid the steps of the stub, skeleton, network and marshaling/unmarshaling of parameters. You can use the local interface when you call beans in the same process.

26 26 local object ---- local interface ---- javax.ejb.EJBLocalObject local home object ---- local home interface ---- javax.ejb.EJBLocalHome pass-by-reference EJB object ---- remote interface ---- javax.ejb.EJBObject Home object ---- home interface ---- javax.ejb.EJBHome pass-by-value Enterprise Bean Constitution

27 27 Deployment Descriptors Deployment descriptors declare how your beans should use middleware, rather than you writing code to use middleware (implicit middleware). In EJB 2.0, a deployment descriptor is an XML file.  Bean management and lifecycle requirements  Persistence requirements (Entity beans only)  Transaction requirements  Security requirements Enterprise Bean Constitution

28 28 Three key components of an EJB bean EJBHome (extends javax.ejb.EJBHome) using the factory design pattern, defining the create, find and remove methods. EJBObject (extends javax.ejb.EJBObject) using the proxy design pattern, defining the business logic implemented in bean. Bean Implementation Class (implements javax.ejb.EntityBean/SessionBean/MessageDrivenBean) implementing the business logic


Download ppt "Middleware Technology (J2EE/EJB) EJB Fundamentals."

Similar presentations


Ads by Google