ejb fundamentals celsina bignoli [email protected]

19
EJB Fundamentals Celsina Bignoli [email protected]

Upload: morgan-bryan

Post on 27-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

EJB Fundamentals

Celsina [email protected]

Page 2: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Enterprise Bean

• Server-side software component that can be deployed in a distributed multi-tier environment

• Must conform to the EJB specification– Must expose specific methods

– Methods are used by the EJB container (Application Server) to manage the bean

Page 3: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Types of Beans

• Session Beans– Model business processes– Ex: pricing engine, catalog engine, credit card

authorizer• Entity Beans

– Model business data– Ex: product, order, employee

• Message-driven Beans– Similar to session beans– Can only be called implicitly via messages– Ex: beans that receive credit card authorization

messages

Page 4: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Distributed Objects

• EJB components are based on distributed objects

• A distributed object is an object that is callable from a remote system– In-process client– Out-process client– Client located elsewhere on the network

Page 5: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Distributed Objects

Client

Stub Skeleton

ImplementationObject

Network

Remote Interface

Remote Interface

Page 6: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Distributed Objects(2)

• Stub: client-side proxy object– Masks network communications from the client– Knows how to call over the network using

sockets– Knows how to convert parameters into their

network representation• Skeleton: server-side proxy object

– Masks network communication from the distributed object

– Understands how to receive calls on a socket– Knows how to convert parameters from their

network representation to their Java representation

Page 7: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Distribution Transparency

• The stub, skeleton and implementation object together constitute the abstraction known as distributed object

• The client has the impression it is calling the object directly – instead, it calls an empty stub which knows how to go over the network

• The stub clones the implementation object signatures (both implement same interface)

• Can be achieved using several technologies (CORBA, DCOM, RMI-IIOP)

Page 8: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Middleware

• Distributed objects allow to distribute an application across a network.

• They require middleware services

• Explicit Middleware– Difficult to write

• Requires unnecessary large amounts of code– Difficult to maintain

• Need to write new code to accomplish changes– Difficult to support

• Code is not distributed to clients• Clients cannot make changes

Page 9: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Middleware(2)

• Implicit Middleware– Easy to write

• No middleware code• Declare things in a text file (descriptor file)

– Easy to maintain• Separation between business logic and middleware• Changes to middleware do not require changes to

code– Easy to support

• Changes can be accomplished by tweaking descriptor file

Page 10: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Enterprise Bean Class

• Contains implementation details of the component (i.e. the logic)

• It is a Java class that conforms to a well-defined interface and obeys certain rules

• All beans implement the javax.ejb.EnterpriseBean

java.io.Serializable

javax.ejb.EnterpriseBean

javax.ejb.SessionBean javax.ejb.MessageDrivenBean javax.ejb.EntityBean

Page 11: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

The EJB Object

• Surrogate object that knows about networking, transactions, security etc…

• It is request interceptor, or glue between the client and the bean

• Replicates and exposes every method that the bean itself exposes

• Delegates client requests to beans• Each container generates automatically a

vendor specific EJB class object

Page 12: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

The Remote Interface

• Special interface created by the Bean Provider

• Must comply with special rules defined by the EJB specification– Must derive from javax.ejb.EJBObject– Must duplicate the bean’s business methods

• Client code does not call the bean object directly but the EJBObject methods.

• When the client invokes a business object method the EJB object delegates the method to the bean, where the actual implementation of the method resides

Page 13: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

The Remote Interface

public interface javax.ejb.EJBObject extends java.rmi.Remote{

public javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException;

public java.jang.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;}

Page 14: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

The Home Object

• Create EJB objects– Clients cannot instantiate EJB objects directly

because EJB objects might reside on a different machine

• Finds existing EJB objects• Remove EJB objects

• Home objects are specific to the container therefore they are automatically generated by the container

Page 15: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

The Home Interface

• Define methods for creating, finding and destroying EJB objects

• The container’s home Object implement the (user-defined) Home Interface

• javax.ejb.EJBHome define required methods all Home Interfaces must support

Page 16: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Home Interface

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;}

Page 17: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

The Local Interfaces

• Used to improve performance.

• Similar to the remote interfaces and objects except they are local, therefore eliminate some tasks

• only work when calling beans in the same process.

Page 18: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Deployment Descriptor File

• key to implicit middleware• used by the container to determine what

services to provide for the bean• Used to specify bean requirements

– bean management and lifecycle– persistence– transaction– security

Page 19: EJB Fundamentals Celsina Bignoli bignolic@smccd.net

Ejb-jar File

• compressed file that follows the .zip compression format

Home Interfaces Local Interfaces

Enterprise Bean Classes

Remote Interfaces

Deployment Descriptor

Vendor-specificfiles

Jar File Creator EJB Jar File