Enterprise Java Beans EJB Enterprise Java Beans EJB
Enterprise Java Beans (EJB)
• Enterprise Java Beans • EJB Architecture • Types of EJB.
Where they fit in a system
Using EJB’s
Enterprise Java. Beans Architecture The EJB architecture specifies the responsibilities and interactions among EJB entities u EJB Servers u EJB Containers u Enterprise Beans u EJB Clients Enterpris e Bean EJB Container Clients EJB Server
EJB Server Provides a Runtime Environment l The EJB Server provides system services and manages resources – Process and thread management – System resources management – Database connection pooling – Management API EJB Server
EJB Container Provides a Run-time Environment for an Enterprise Bean l Hosts the Enterprise Java. Beans l Provides services to Enterprise Java. Beans – Naming – Life cycle management – Persistence (state management) – Transaction Management – Security EJB Container EJB Server
Enterprise Beans l A specialized Java class where the real business logic lives – May be developer-written or tool-generated l Distributed over a network l Transactional l Secure l Server vendors provide tools that automatically generate distribution, transaction and security behavior Enterpris e Bean EJB Container EJB Server
EJB Clients l Client access is controlled by the container in which the enterprise Bean is deployed l Clients locates an Enterprise Java. Bean through Java Naming and Directory Interface (JNDI) l RMI is the standard method for accessing a bean over a network Enterpris e Bean EJB Container Clients EJB Server
Java. Beans vs EJB l Enterprise Java. Beans is a framework for building and deploying server-side Java components l Java. Beans is a framework for client-side Java components l Conceptually related because both are components l 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 J 2 EE 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
Comparing Session and Entity Beans Session Beans l Mandatory for EJB 1. 0 l Represents a specific client (1 instance per client) l l l Short-lived Transient Can be any Java class May be transactional Business Logic Beans Entity Beans l Optional for EJB 1. 0 l Represents underlying data object or context (clients share instance) l Long-lived l Persistent l Can be a class that maps to persistent data (e. g. , database) l Always transactional l Beans which represent data
Message Beans • A message bean is an enterprise bean that allows J 2 EE 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
THANKS
- Slides: 19