enterprise javabeans. what is ejb? l an ejb is a specialized, non-visual javabean that runs on a...

19
Enterprise JavaBeans Enterprise JavaBeans

Upload: sybil-joseph

Post on 29-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Enterprise JavaBeansEnterprise JavaBeans

Page 2: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

What is EJB?What is EJB? An EJB is a specialized, non-visual An EJB is a specialized, non-visual

JavaBean that runs on a server.JavaBean that runs on a server.

EJB technology supports EJB technology supports application development based on application development based on a multi tier, distributed object a multi tier, distributed object architecture in which most of architecture in which most of application’s logic is moved from application’s logic is moved from the client to the server. the client to the server.

Page 3: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Server ComponentsServer Components

Server components are application Server components are application components that run in an components that run in an application server.application server.

Page 4: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Overview of EJB Overview of EJB TechnologyTechnology

Enterprise JavaBeans component model logically extends the JavaBeans component model to support server component.

Server components are reusable, prepackaged pieces of application functionality that are designed to run in an application server.

EJB can be assembled and customized at deployment time using tools provided by an EJB-compliant Java application server.

EJB Component Model

Page 5: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Simplifying Development.Simplifying Development.

The EJB architecture provides an integrated application framework.

An EJB server automatically manages a number of tricky middleware services on behalf of the application components.

EJB component-builders can concentrate on writing business logic rather than complex middleware

Page 6: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Simplifying Development Simplifying Development (cont’d)(cont’d)

RESULT:

•Application get developed more quickly

•Code is of better quality.

Page 7: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

What EJB Means to UsWhat EJB Means to Us

Developers can Developers can focus on writing business logicfocus on writing business logic rather than writing low-level infrastructure like data rather than writing low-level infrastructure like data access, concurrency, transactions, threading, etc. access, concurrency, transactions, threading, etc. – Reduces development timeReduces development time– Reduces complexityReduces complexity– Increases quality and reliabilityIncreases quality and reliability

The knowledge about EJB is portableThe knowledge about EJB is portable among among many different products because EJB products are many different products because EJB products are based on a common standardbased on a common standard

Greater Greater reusereuse because code is located in shareable, because code is located in shareable, server objectsserver objects

Page 8: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

So....let’s take a look at So....let’s take a look at Enterprise JavaBeansEnterprise JavaBeans

Enterprise JavaBeans defines a server Enterprise JavaBeans defines a server component model for the development and component model for the development and deployment of Java applications based on a deployment of Java applications based on a multi-tier, distributed object architecturemulti-tier, distributed object architecture

The Enterprise JavaBeans specification defines:The Enterprise JavaBeans specification defines:– A container modelA container model– A definition of the services the container A definition of the services the container

needs to provide to an Enterprise JavaBean, needs to provide to an Enterprise JavaBean, and vice versaand vice versa

– How a container should manage Enterprise How a container should manage Enterprise JavaBeansJavaBeans

Page 9: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Enterprise JavaBeans Enterprise JavaBeans ArchitectureArchitecture

The EJB architecture specifies the responsibilities and interactions among EJB entities

EJB Servers

Enterprise Beans EJB Clients

EJB ServerEJB Server

EJB Container

Enterprise Bean

Enterprise Bean

EJB Containers

Clients

Page 10: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

EJB ServerEJB Server

EJB ServerEJB Server

The EJB Server provides system services and The EJB Server provides system services and manages resourcesmanages resources– Process and thread managementProcess and thread management– System resources managementSystem resources management– Database connection pooling and cachingDatabase connection pooling and caching– Management APIManagement API

Provides a Runtime EnvironmentProvides a Runtime Environment

Page 11: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

EJB ServerEJB Server

EJB Container

EJB ContainerEJB Container

Hosts the Enterprise JavaBeansHosts the Enterprise JavaBeans Provides services to Enterprise JavaBeansProvides services to Enterprise JavaBeans

– NamingNaming– Life cycle managementLife cycle management– Persistence (state management)Persistence (state management)– Transaction ManagementTransaction Management– SecuritySecurity

Likely provided by server vendorLikely provided by server vendor

Provides a Run-time Environment for an Enterprise Bean

Provides a Run-time Environment for an Enterprise Bean

Page 12: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Enterprise JavaBeansEnterprise JavaBeans A specialized Java class where the real business logic A specialized Java class where the real business logic

liveslives– May be developer-written or tool-generatedMay be developer-written or tool-generated

Distributed over a networkDistributed over a network TransactionalTransactional SecureSecure Server vendors provide tools that automatically generate Server vendors provide tools that automatically generate

distribution, transaction and security behaviordistribution, transaction and security behavior

EJB ServerEJB Server

EJB Container

Enterprise Bean

Enterprise Bean

Page 13: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

EJB ClientsEJB Clients

Client access is controlled by the container Client access is controlled by the container in which the enterprise Bean is deployedin which the enterprise Bean is deployed

Clients locates an Enterprise JavaBean Clients locates an Enterprise JavaBean through Java Naming and Directory through Java Naming and Directory Interface (JNDI)Interface (JNDI)

RMI is the standard method for accessing a RMI is the standard method for accessing a bean over a networkbean over a network

EJB ServerEJB Server

EJB Container

Enterprise Bean

Enterprise Bean

Clients

Page 14: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Enterprise Beans: Enterprise Beans: Session Beans & Entity Session Beans & Entity

BeansBeans

Page 15: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Session BeansSession BeansRepresents Represents ProcessProcess

A transient agent for an individual client that A transient agent for an individual client that executes on a server (e.g., ShoppingCart)executes on a server (e.g., ShoppingCart)

Session beans are often a client of multiple Session beans are often a client of multiple entity beansentity beans

ImplementsImplements javax.ejb.SessionBeanjavax.ejb.SessionBean interfaceinterface

Page 16: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Session Beans – Session Beans – Stateful or StatelessStateful or Stateless

A Stateful Session Bean maintains a one-to-one A Stateful Session Bean maintains a one-to-one relationship with a Client. It maintains a user “session”. relationship with a Client. It maintains a user “session”. Most common example is an e-commerce application Most common example is an e-commerce application with a “shopping cart” unique for each user.with a “shopping cart” unique for each user.– Container will automatically “swap out” the Session bean if it is Container will automatically “swap out” the Session bean if it is

inactive. inactive.

A Stateless Session Bean can be accessed by multiple A Stateless Session Bean can be accessed by multiple incoming clients and keeps no private data. It does not incoming clients and keeps no private data. It does not maintain a unique session with a client.maintain a unique session with a client.– Keeps no persistent data. If it crashes, container simply starts another Keeps no persistent data. If it crashes, container simply starts another

one and the client transparently connects.one and the client transparently connects.– All access to the Bean is serialized.All access to the Bean is serialized.

Page 17: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Entity BeanEntity Bean

Represents Represents DataData Implements Implements javax.ejb.EntityBean javax.ejb.EntityBean interfaceinterface Maps a data source to a Java classMaps a data source to a Java class

– table, view, join or stored procedure in a relational table, view, join or stored procedure in a relational databasedatabase

– a set of related records in a databasea set of related records in a database Each instance of an entity bean is one row of dataEach instance of an entity bean is one row of data Each instance of an entity bean is uniquely Each instance of an entity bean is uniquely

identified by a primary keyidentified by a primary key An Entity Bean can also have additional methods An Entity Bean can also have additional methods

for business logic, etc.for business logic, etc.

Page 18: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Since Entity Beans represent Since Entity Beans represent Data...Data...

Each instance of an Entity Bean is Each instance of an Entity Bean is uniquely identified by a primary uniquely identified by a primary key objectkey object

Primary key can be saved and Primary key can be saved and used later to regain access to the used later to regain access to the same EJB object identitysame EJB object identity

Page 19: Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development

Comparing Comparing Session and Entity BeansSession and Entity Beans

Represents a specific Represents a specific clientclient(1 instance per client)(1 instance per client)

Short-livedShort-lived TransientTransient Can be any Java classCan be any Java class

May be transactionalMay be transactional Business Logic BeansBusiness Logic Beans

Represents underlying Represents underlying data object or contextdata object or context

(clients share instance)(clients share instance) Long-livedLong-lived PersistentPersistent Can be a class that Can be a class that

maps to persistent data maps to persistent data (e.g., database)(e.g., database)

Always transactionalAlways transactional Beans which represent Beans which represent

datadata

Session BeansSession Beans Entity BeansEntity Beans