190 likes | 330 Views
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
E N D
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
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
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
Distributed Objects Client Implementation Object Remote Interface Remote Interface Stub Skeleton Network
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
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)
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
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
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
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
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
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; }
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
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
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; }
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.
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
Home Interfaces Local Interfaces Enterprise Bean Classes Remote Interfaces Deployment Descriptor Vendor-specific files Ejb-jar File • compressed file that follows the .zip compression format Jar File Creator EJB Jar File