Given by Nancy McCracken at Basic Information Track Computational Science Course CPS616 on Spring Semester 1999. Foils prepared May 19 99
Outside Index
Summary of Material
Overview of Enterprise Javabeans with discussion of goals, architecture |
Interaction with databases |
EJB Containers, Servers, Components, Session Beans,Entity Beans |
Users of EJB's and how to write them |
Shopping Cart Examples |
Outside Index Summary of Material
Nancy McCracken |
Northeast Parallel Architectures Center |
Syracuse University |
111 College Place |
Syracuse, NY 13244-4100 |
April 1999 |
Enterprise JavaBeans is the architecture for a server-side platform that provides distributed components.
|
Resources:
|
Allow application developer to concentrate on business logic, instead of systems details of distributed systems, transaction logic, database access, security, scalability and integration with existing systems. |
Cross-platform capability - using Java means "write once run anywhere". |
Logical extension of JavaBeans component programming. |
Existing non-Java enterprise applications can be used as components. |
Certain behaviors such as security and transactions should be set as properties of the component, instead of hand-programmed. |
The EJB 1.0 specification was publicly released during the JavaOne `98 conference. |
Partners with Sun in developing the specification:
|
The EJB architecture consists of a server which may run instances of JavaBeans inside of a container, clients of any kind, connected via any protocol.
|
The EJB specification is for the collection of services that the server should provide.
|
Container |
EJB Server |
EJB Object |
(bean id) |
Database |
Or |
TP Monitor |
business |
methods |
create, find, remove |
A container is the "EJBHome" for EJB components. |
The container provides the secure, transactional environment. |
It manages the object life cycle of the bean (component), and the state management. |
The container provides the implementation of the bean's EJBHome interface and Remote interface. |
It is responsible for making the Bean's EJBHome interface available in JNDI, the Java Naming and Directory Interface. |
An EJB Server provider must provide an implementation of a container. Many vendors simply adapt existing application servers. |
Vendors of EJB Servers:
|
Database is source of potential objects |
EJB technology takes these objects to a multi-tier environment |
Two models for building enterprise applications:
|
Session Beans:
|
Entity Beans:
|
Many behaviors can be specified in the Deployment Descriptor object of each container. |
Transaction management properties: no longer write transaction demarcation in the code - container will implicitly use one of six transaction rules.
|
Security: security rules for each bean are defined in a set of AccessControlEntry objects within the deployment descriptor.
|
A bean may be moved to any EJB server (for example, for performance reasons). |
Server provider - typically a database or TP vendor, transaction processing, distributed objects. |
Container provider - also typically a DB or TP vendor, systems programming and interfaces to existing applications. |
Enterprise bean provider - domain experts who provide business logic in building block beans. |
Application assemblers: domain experts who assemble beans and provide user interface |
Deployers: DBAs, or other persons familiar with application environment. |
0. Design code |
1. Write business methods (can use an IDE like Sun's Java Workshop, Symantec's Café, or Inprise's Jbuilder). |
2. Write* remote interface -- EJBObject |
3. Write* home interface -- EJBHome |
4. Create and Install EJB-JAR in container |
5. Debug & Test |
Business |
Model |
Class |
Design |
EJB-JAR |
file |
EJB-JAR, |
Factory, |
Environment & |
Deployment descriptors |
Design Time |
Run Time |
Clients |
Web Server |
Java Mid-Tier |
Server |
Shopping |
Cart |
Credit Card |
Order Entry |
EJB Server |
DBMS |
EJB Container |
Clients |
Web Server |
Existing |
Enterprise |
Middleware |
Standard |
Container |
Shopping |
Cart |
Credit Card |
CICS Container |
SAP Container |
Order Entry |
CICS Programs |
SAP Modules |
EJB Server |
public interface ShoppingCart extends |
javax.ejb.EJBObject |
{ |
boolean addItem(int itemNumber) |
throws java.rmi.RemoteException; |
boolean purchase() |
throws java.rmi.RemoteException; |
} |
Define the interface to the methods that the clients can call. Note that methods must conform to RMI standards in that parameters must be Serializable and methods must throw rmi.RemoteException. But RMI is being extended to support IIOP protocol, and hence COM. |
public class ShoppingCartEJB |
implements SessionBean |
{ |
public boolean addItem(int itemNumber) { |
// the code for adding items to the cart |
// may include JDBC™ code. |
} |
public boolean purchase () { |
// the code for purchases |
} |
public void ejbCreate(String accountName, |
String account) { |
// object initialization code |
} |
} |
public interface CartHome extends |
javax.ejb.EJBHome |
{
|
} |
Note that on previous slide, server bean did not implement the Remote interface. The server creates this EJBObject and also the EJBHome, corresponding to the following interface. Note that this create will call the EJBcreate method of the bean. |
Class SessionDescriptor |
public class javax.ejb.deployment.SessionDescriptor |
extends javax.ejb.deployment.DeploymentDescriptor |
{ |
public final static int STATEFUL_SESSION; |
public final static int |
STATELESS_SESSION; |
public SessionDescriptor(); |
public int getSessionTimeout(); |
public int getStateManagementType(); |
public void setSessionTimeout(int value); |
public void setStateManagementType(int value); |
} |
To deploy an Enterprise JavaBean, make a .jar file with the code and the deployment descriptor. |
The deployment person (aka dba) will put the code in a place known to the server and do other housekeeping details depending on the server, such as editing a properties file of all the EJBeans on the server. |
Context initialContext = new InitialContext(); |
CartHome cartHome = (CartHome) |
initialContext.lookup |
("applications/mall/shopping-carts"); |
Client-side code may be written in Java in an applet, application or servlet, or in a C++ application using CORBA. |
Getting the home of the remote bean:
|
The variable cart contains a reference to the remote EJBObject, which is created by create. This example creates a new session bean. The reference to the EJBObject is used to call the remote methods. |
ShoppingCartEJB cart = |
cartHome.create("Emma", "0507"); |
cart.addItem(100); |
cart.addItem(251); |
cart.purchase(); |
Bill Roth suggests that we view this 1.0 specification as the first iteration in a process of developing EJB. |
Some of the areas that need to be refined:
|
Wide industry participation - but need to make sure that EJB servers from different vendors can interoperate. |
Most notable holdout: Microsoft. Microsoft supports the Microsoft Transaction Server (MTS) and is not likely to make it interoperable with EJB's. |
complexity |
capability |
EJB |
MTS |
CORBA |
2 days |
2 weeks |
transactions |
threading |
security |
persistence |
platform independence |
scalability |
ease of use |
safety |
Detailed tutorial using free downloadable BEA WebLogic Tengah server:
|
"A beginner's guide to Enterprise JavaBeans" by Mark Johnson of JavaWorld has many more references at the bottom of the article: |