310 likes | 723 Views
Enterprise Java Beans (EJB). Enterprise Java Beans EJB Architecture Types of EJB. Where they fit in a system. Using EJB’s. Clients. Enterprise JavaBeans Architecture. The EJB architecture specifies the responsibilities and interactions among EJB entities. EJB Servers. EJB Containers.
E N D
Enterprise Java Beans • EJB Architecture • Types of EJB.
Clients Enterprise JavaBeans Architecture The EJB architecture specifies the responsibilities and interactions among EJB entities • EJB Servers • EJB Containers • Enterprise Beans • EJB Clients Enterprise Bean Enterprise Bean EJB Container EJB Server
EJB Server EJB Server Provides a Runtime Environment • The EJB Server provides system services and manages resources • Process and thread management • System resources management • Database connection pooling • Management API
EJB Container EJB Server EJB Container Provides a Run-time Environment for an Enterprise Bean • Hosts the Enterprise JavaBeans • Provides services to Enterprise JavaBeans • Naming • Life cycle management • Persistence (state management) • Transaction Management • Security
Enterprise Bean Enterprise Bean EJB Container EJB Server Enterprise Beans • A specialized Java class where the real business logic lives • May be developer-written or tool-generated • Distributed over a network • Transactional • Secure • Server vendors provide tools that automatically generate distribution, transaction and security behavior
Enterprise Bean Enterprise Bean EJB Container EJB Server Clients EJB Clients • Client access is controlled by the container in which the enterprise Bean is deployed • Clients locates an Enterprise JavaBean through Java Naming and Directory Interface (JNDI) • RMI is the standard method for accessing a bean over a network
JavaBeans vs EJB • Enterprise JavaBeans is a framework for building and deploying server-side Java components • JavaBeans is a framework for client-side Java components • Conceptually related because both are components • The specifications do not build on each other.
Three kinds of EJB’s • Session • associate client information with a specific client • both stateless and stateful versions • Entity • groups associated information in an abstraction that provides transaction support • Message Bean - rarely used, hardly supported
What is a Session Bean? • Represents a single Client inside the J2EE server • one client at a time/ not persistent • when the client terminates, the session bean is disassociated from the client • There are two types: Stateful and Stateless...
Stateful • These represent a set of interactions between client and server. • Example: shopping cart • Saves information over several method invocations. • There is a lot of overhead associated with using stateful beans
Stateless • A stateless bean does not save information between method calls. • Limited application • Little overhead • multiple clients can use the same bean instance without alteration • Example: fetch from a read-only database or send a confirmation email for an order
Entity Beans • Associates pieces of information in a group • Accessed by multiple clients at a time • Persistent and Serializable • The container loads and stores the entity beans in the database • These are more similar to regular beans
Persistence in Entity Beans • Container Managed Persistence (CMP) • the container controls when the bean is read from or written to the database • Bean Managed Persistence (BMP) • the bean’s implementation performs all of the SQL operations that loads, stores, and updates the bean’s data to or from the database. • Bean is responsible for connection allocation to the database
Mandatory for EJB 1.0 Represents a specific client(1 instance per client) Short-lived Transient Can be any Java class May be transactional Business Logic Beans Optional for EJB 1.0 Represents underlying data object or context(clients share instance) Long-lived Persistent Can be a class that maps to persistent data (e.g., database) Always transactional Beans which represent data Comparing Session and Entity Beans Session Beans Entity Beans
Message Beans • A message bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS(Java Messaging Services) message listener, which is similar to an event listener except that it receives messages instead of events. • Many systems do not yet support JMS, message bean use is currently not widespread