SlideShare a Scribd company logo
Enterprise JavaBeans
Santhosh SG
(Plain Old Java Object)
What Are EJB’s?
Enterprise Java Beans
EJB: special kind of Java Bean for performing server-side business
logic, More powerful version of the regular beans that we’ve used in
class
EJB stands for Enterprise Java Beans. EJB is an essential
part of a J2EE platform. J2EE platform has component based
architecture to provide multi-tiered, distributed and highly
transactional features to enterprise level applications.
EJB provides an architecture to develop and deploy component based
enterprise applications considering robustness, high scalability, and
high performance. An EJB application can be deployed on any of the
application server compliant with the J2EE 1.3 standard specification.
Overview of EJB
• EJB is a server-side component architecture that simplifies the
process of building enterprise-level, distributed applications in
Java.
• EJB components are deployed in EJB containers of J2EE-
compliant application servers, such as J2EE 1.4, Weblogic, and
JBoss.
Characteristics of EJB:
• Hides server-side system level issues from developers.
• Defines a standard component architecture that enables you to
build distributed object-oriented business applications.
• Facilitates creating enterprise-level applications by allowing easy
integrating with other EJB components as well as with other
components, such as servlets, Java Server Pages (JSP), and Java
Beans.
• The server-side components deployed on the application servers can
be implemented using various technologies, such as EJB and
Microsoft’s COM/DCOM.
• Enterprise JavaBeans are different from JavaBeans, another
similarly named Sun Microsystems component based technology.
• Examples of real-life applications where you can use the EJB
component architecture are:
1. Online share trading application,
2. Online reservation application
3. Online catalog application,
4. Online library application
The Problem Domain
• Application development can be a deceivingly complex
undertaking. There’s a list of characteristics that Good
Software implies:
• Secure
• Sound/maintains integrity
• Scalable
• Interoperable
• Robust/resilient
• Correct/functions as specified
• Above are all prerequisites to a finished product, not a single one is
specific to any business.
Breaking Up Responsibilities
• For the sake of simplicity, we may categorize all code in a system
into one of three flavors:
• Core concerns
• Cross-cutting concerns
• Plumbing
Core concerns
• The primary purpose of an application is to satisfy business logic,
the set of rules that dictate its expected behavior.
• For ex. an email client must be able to let its users read, compose,
send, and organize email.
• All functions related to the fulfillment of business logic fall into the
category of core concerns.
• The core is typically going to contain rules unique to your
application.
Cross-cutting concerns
• While the core of an application defines its primary function, there
is a host of secondary operations necessary to keep things running
correctly and efficiently.
• Security assertions, transactional boundaries, concurrency
policies—all are helpful in ensuring the integrity of the system is in
check. We define these as aspects.
• Banking software must allow users to withdraw money from their
accounts, but it would make for an interesting solution if we could
withdraw from any account we wanted; we need a security assertion
at some point to ensure the requesting user has permission.
Plumbing
• Once modules have been built to address the core, there’s still the
matter of getting data and invocations from point A to point B.
Plumbing provides this routing, and may take several forms:
• Forwarding control from an HTTP request to some action handler
• Obtaining a JDBC connection or JavaMail session
• Mapping a nonnative request (JSON, ActionScript, RDBMS SQL)
into a Java object.
• Plumbing is a means to an end, and therefore of little value in and of
itself.
• It will benefit us to take an approach that minimizes the time we
spend getting data from one endpoint to another.
The Container
A Container is a host that provides services to guest applications.
IT is provide generic services upon which applications may
rely. The service support desired is usually defined by some
combination of user code and metadata that together follow a
contract for interaction between the application and container.
The Enterprise JavaBeans™ 3.1 Specification
• The Enterprise JavaBeans architecture is a architecture for the
development and deployment of component-based business
applications.
• Applications written using the Enterprise JavaBeans architecture
are scalable, transactional, and multi-user secure.
• These applications may be written once, and then deployed on any
server platform that supports the Enterprise JavaBeans
specification.
• This means that EJB defines a model for piecing together a full
system by integrating modules. Each component may represent a
collection of business processes, and these will run centralized on the
server.
• Additionally, the “distributed” nature will provide a mechanism to
spread modules across different processes, physical machines, or
even entire networks.
• Applications that take advantage of EJB architecture are portable
across any compliant Container implementation.
Component Types
• EJB imposes no API coupling or restrictions upon the classes that
will define our business objects.
• Commonly known as POJO (Plain Old Java Object) development,
this means that an application developer is under no obligation to
extend, implement, or have any references tying the application to
EJB.
• Now we can create class hierarchies however we see fit, and reuse
our objects in some non-EJB environment.
• Because a POJO class is just like any other class, it does not become
an EJB until it’s:
1. Assembled/packaged
2. Deployed
3. Accessed via the Container
• EJB are primarily of three types which are briefly
described below:
Server-Side Component Types
Type Description
1 Session Bean Session bean stores data of a particular user for a single
session. It can be stateful or stateless. It is less resource
intensive as compared to entity beans. Session bean
gets destroyed as soon as user session terminates.
2 Entity Bean Entity beans represents persistent data storage. User
data can be saved to database via entity beans and later
on can be retrived from the database in the entity bean.
3 Message Driven
Bean
Message driven beans are used in context of JMS (Java
Messaging Service). Message Driven Beans can
consumes JMS messages from external entities and act
accordingly.
1. Session Beans
• Also called business logic process objects. …
• They represent the business logic of the system. …
• Their lifetime is usually an entire session „
When a session
is done, the session bean expires
•„i.e. Session bean instances exist as long as a specific
user is using the system
2. EJB - Stateful Bean
Subtypes of Session Beans
1. EJB – Stateless Bean
EJB - Stateless Bean
A stateless session bean is a type of enterprise bean
which is normally used to do independent operations.
A stateless session bean as per its name does not
have any associated client state, but it may preserve its
instance state. EJB Container normally creates a pool of
few stateless bean's objects and use these objects to
process client's request.
Because of pool, instance variable values are not
guaranteed to be same across lookups/method calls.
Following are the steps required to create a stateless EJB.
• Create a remote/local interface exposing the business
methods.
• This interface will be used by the EJB client application.
• Use @Local annotation if EJB client is in same
environment where EJB session bean is to be deployed.
Use @Remote annotation if EJB client is in different
environment where EJB session bean is to be deployed.
• Create a stateless session bean implementing the above
interface.
EJB - Stateful Bean
A stateful session bean is a type of enterprise bean
which preserve the conversational state with client.
A stateful session bean as per its name keeps
associated client state in its instance variables.
EJB Container creates a separate stateful session
bean to process client's each request. As soon as request
scope is over, statelful session bean is destroyed.
Following are the steps required to create a stateful EJB.
• Create a remote/local interface exposing the business
methods.
• This interface will be used by the EJB client application.
• Use @Local annotation if EJB client is in same
environment where EJB session bean is to be deployed.
• Use @Remote annotation if EJB client is in different
environment where EJB session bean is to be deployed.
• Create a stateful session bean implementing the above
interface.
2. EJB - Message Driven Beans ( MDB )
A message driven bean is a type of enterprise bean
which is invoked by EJB container, when it receives a
message from queue or topic. Message driven bean is a
stateless bean and is used to do task asynchronously
(Asynchronous means that you can execute multiple things at a time
and we don't have to finish executing the current thing in order to move on
to next one).
To demonstrate use of message driven bean, we'll make
use of EJB-persistence & to do the following tasks.
Step1. Create table in database
Step2. Create Entity class corresponding to table
Step3. Create Data Source and Persistence Unit
Step4. Create a stateless ejb having Entity Manager
instance
Step5. Update stateless ejb.Add methods to add records
and get records from database via entity manager.
Step 6. Create a Queue named BookQueue in
JBoss default application directory.
Step 7. A console based application client will send
message to this queue.
Step 8. Create a Message driven bean which will use the
stateless bean to persist the client data.
Step 9. EJB Container of JBoss will call the above
message driven bean and pass it the message that client
will be sending to.
3. Entity beans:
Also called business data objects. They represent
persistent data „often the data persistence is managed
through a database, using JDBC.
Entity beans represent data in the system. …
• In addition, entity beans are used to search for, modify,
create and delete data. …
 Usually, this data resides in a relational database. …
 Each entity bean typically represents a single row in
some database table „
An entity bean instance exists as long as the data is being
used …
• When the EJB client is done with the instance, the entity
bean instance usually returns to a bean pool „
•The client for an entity bean is typically a session bean,
since behavior usually involves the manipulation of data.
EJB – The JAVA Persistence Model
EJB 3.0, entity bean used in EJB 2.0 is largely replaced by
persistence mechanism. Now entity bean is a simple POJO
having mapping with table.
Following are the key actors in persistence API
Entity - A persistent object representing the data-store
record. It is good to be serializable.
EntityManager - Persistence interface to do data
operations like add/delete/update/find on persistent
object(entity). It also helps to execute queries
using Query interface.
Persistence unit (persistence.xml) - Persistence unit
describes the properties of persistence mechanism.
Data Source (*ds.xml) - Data Source describes the data-
store related properties like connection url. user-name,
password etc.
To demonstrate EJB persistence mechanism, we're going to do
the following tasks.
Step 1. Create table in database.
Step 2. Create Entity class corresponding to table.
Step 3. Create Data Source and Persistence Unit
Step 4. Create a stateless EJB having Entity Manager
instance.
Step 5. Update stateless EJB. Add methods to add records
and get records from database via entity manager.
Step 6. A console based application client will access the
stateless EJB to persist data in database.
While server-side component types handle business
logic and entities address state,
the EJB Container can continue to make our jobs
easier by providing a wide range of generic and
configurable services.
Enterprise applications generally handle a large
number of concurrent users, and each request might need to
be handled carefully so it does not violate the security or
integrity of the application. Additionally, we shouldn’t
waste our time wiring our modules together; the container
can do this for us.
Container servers
The EJB container is a container that deploys EJB
automatically when Web Server is started. All of the entity
objects live in container during its creation to removal.
We can deploy more than one entity beans in a
container. When the entity bean is deployed in the
container the work of the container is to provide a home
interface for the entity bean.
This home interface allows a client in removing,
creating and finding entity objects. It also helps in
executing home interface business methods that are not
specific to a particular entity bean object. JNDI(Java
Naming and Directory Interface) is the standard
interface by which the client can look up the entity bean's
home interface.
Services Description
Life Cycle
Management
JRun is an application server that works for building and
deploying server-side Java applications. The role of JRun
in the container service is to automatically increase and
reduce the number of available bean instances so that
there is not much load on the current server.
Security
Security is one of the most important feature of EJB.
Since EJB support authentication and role-driven access
control.
Transaction
transaction mean a unit of work that must be executed
in one piece.
Container-managed transactions:-These type of
transaction are the transaction in which the container
begins and commits transactions on behalf of the bean.
Bean-managed transactions:-In this type of transaction
we have complete control over transactions. This control
can be achieved either from the client or from the bean
itself.
The table given below illustrates the EJB container services:-
Dependency injection
EJB 3.0 specification provides annotations which
can be applied on fields or setter methods to inject
dependencies. EJB Container uses the global JNDI
registry to locate the dependency.
Following annotations are used in EJB 3.0 for
dependency injection.
@EJB - used to inject other EJB reference.
@Resource - used to inject data source or singleton
services like session Context, timer Service etc.
Concurrency
Assuming each Service is represented by one
instance, dependency injection alone is a fine solution for a
single-threaded application; only one client may be
accessing a resource at a given time.
However, this quickly becomes a problem in
situations where a centralized server is fit to serve many
simultaneous requests.
So that there are a series of effects upon performance to
consider, so the specification allows for configuration in
some cases. Otherwise, it’s important to be aware how each
component type views concurrency concerns.
Instance Pooling/Caching
Because of the strict concurrency rules enforced by
the Container, an intentional bottleneck is often introduced
where a service instance may not be available for
processing until some other request has completed. If the
service was restricted to a singular instance, all subsequent
requests would have to queue up until their turn was
reached
Transactions
A transaction is a single unit of work items which
follows the ACID properties. ACID stands for Atomic,
Consistent, Isolated and Durable.
Atomic - If any of work item fails, the complete unit is
considered failed. Success meant all items executes
successfully.
Consistent - A transaction must keep the system in
consistent state.
Isolated - Each transaction executes independent of any
other transaction.
Durable - Transaction should survive system failure if it
has been executed or committed.
Security
Security is a major concern of any enterprise level
application. It includes identification of user(s) or system
accessing the application and allowing or denying the
access to resources within the application.
In EJB, security can be declared in declarative way
called declarative security in which EJB container
manages the security concerns or Custom code can be
done in EJB to handle security concern by self
Timers
Timer Service is a mechanism using which
scheduled application can be build.
For example, salary slip generation on 1st of every
month. EJB 3.0 specification has specified @Timeout
annotation which helps in programming the ejb service in a
stateless or message driven bean. EJB Container calls the
method which is annotated by @Timeout.
Naming and Object Stores
All naming services essentially do the same
thing: they provide clients with a mechanism for locating
distributed objects or resources.
To accomplish this, a naming service must fulfill
two requirements:
1. object binding and
2. A lookup API.
• Object binding is the association of a distributed
object with a natural language name or identifier.
• A lookup API provides the client with an interface to
the naming system.
Interoperability
It’s nice that the dependency injection facilities allow
components within EJB to play nicely, so our application
may want to consume data from or provide services to
other programs,
Interoperability is a vital part of EJB. The
specification includes the required support for Java RMI-
IIOP for remote method invocation and provides for
transaction, naming, and security interoperability.
Lifecycle Callbacks
Some services require some initialization or
cleanup to be used properly.
For example, a file transfer module may want to
open a connection to a remote server before processing
requests to transfer files and should safely release all
resources before being brought out of service.
For component types that have a lifecycle, EJB
allows for callback notifications, which act as a hook for the
bean provider to receive these events. In the case of our file
transfer bean, this may look like:
EJB 3.0 provides specification to intercept
business methods calls using methods annotated with
@AroundInvoke annotation. An interceptor method is
called by ejb Container before business method call it is
intercepting. Following is the example signature of an
interceptor method.
Interceptors
Platform Integration
As a key technology within the Java Enterprise
Edition (JEE) 6, EJB aggregates many of the other
platform frameworks and APIs:
• Java Transaction Service
• Java Persistence API
• Java Naming and Directory Interface (JNDI)
• Security Services
• Web Services

More Related Content

Similar to Unite5-EJB-2019.ppt

Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
tayab4687
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
Simon Ritter
 
J2 ee container & components
J2 ee container & componentsJ2 ee container & components
J2 ee container & components
Keshab Nath
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with mule
Ruman Khan
 
J2ee web services(overview)
J2ee web services(overview)J2ee web services(overview)
J2ee web services(overview)
Prafull Jain
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
guest346cb1
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
rani marri
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbai
vibrantuser
 
Introduction to Java EE EJB Component
Introduction to Java EE EJB ComponentIntroduction to Java EE EJB Component
Introduction to Java EE EJB Component
Ganesh P
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
Niraj Bharambe
 
EJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfEJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdf
SPAMVEDANT
 
The java enterprise edition (Servlet Basic)
The java enterprise edition (Servlet Basic)The java enterprise edition (Servlet Basic)
The java enterprise edition (Servlet Basic)
Atul Saurabh
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2
phanleson
 
Ejb training institute in navi-mumbai
Ejb training institute in navi-mumbaiEjb training institute in navi-mumbai
Ejb training institute in navi-mumbai
vibrantuser
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
Anup72
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
Kongu Engineering College, Perundurai, Erode
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
Emprovise
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
Niit Care
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
s4al_com
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
sandeep54552
 

Similar to Unite5-EJB-2019.ppt (20)

Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
J2 ee container & components
J2 ee container & componentsJ2 ee container & components
J2 ee container & components
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with mule
 
J2ee web services(overview)
J2ee web services(overview)J2ee web services(overview)
J2ee web services(overview)
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbai
 
Introduction to Java EE EJB Component
Introduction to Java EE EJB ComponentIntroduction to Java EE EJB Component
Introduction to Java EE EJB Component
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
EJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfEJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdf
 
The java enterprise edition (Servlet Basic)
The java enterprise edition (Servlet Basic)The java enterprise edition (Servlet Basic)
The java enterprise edition (Servlet Basic)
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2
 
Ejb training institute in navi-mumbai
Ejb training institute in navi-mumbaiEjb training institute in navi-mumbai
Ejb training institute in navi-mumbai
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
 

Recently uploaded

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 

Recently uploaded (20)

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 

Unite5-EJB-2019.ppt

  • 2. What Are EJB’s? Enterprise Java Beans EJB: special kind of Java Bean for performing server-side business logic, More powerful version of the regular beans that we’ve used in class EJB stands for Enterprise Java Beans. EJB is an essential part of a J2EE platform. J2EE platform has component based architecture to provide multi-tiered, distributed and highly transactional features to enterprise level applications. EJB provides an architecture to develop and deploy component based enterprise applications considering robustness, high scalability, and high performance. An EJB application can be deployed on any of the application server compliant with the J2EE 1.3 standard specification.
  • 3. Overview of EJB • EJB is a server-side component architecture that simplifies the process of building enterprise-level, distributed applications in Java. • EJB components are deployed in EJB containers of J2EE- compliant application servers, such as J2EE 1.4, Weblogic, and JBoss. Characteristics of EJB: • Hides server-side system level issues from developers. • Defines a standard component architecture that enables you to build distributed object-oriented business applications. • Facilitates creating enterprise-level applications by allowing easy integrating with other EJB components as well as with other components, such as servlets, Java Server Pages (JSP), and Java Beans.
  • 4. • The server-side components deployed on the application servers can be implemented using various technologies, such as EJB and Microsoft’s COM/DCOM. • Enterprise JavaBeans are different from JavaBeans, another similarly named Sun Microsystems component based technology. • Examples of real-life applications where you can use the EJB component architecture are: 1. Online share trading application, 2. Online reservation application 3. Online catalog application, 4. Online library application
  • 5. The Problem Domain • Application development can be a deceivingly complex undertaking. There’s a list of characteristics that Good Software implies: • Secure • Sound/maintains integrity • Scalable • Interoperable • Robust/resilient • Correct/functions as specified • Above are all prerequisites to a finished product, not a single one is specific to any business.
  • 6. Breaking Up Responsibilities • For the sake of simplicity, we may categorize all code in a system into one of three flavors: • Core concerns • Cross-cutting concerns • Plumbing
  • 7. Core concerns • The primary purpose of an application is to satisfy business logic, the set of rules that dictate its expected behavior. • For ex. an email client must be able to let its users read, compose, send, and organize email. • All functions related to the fulfillment of business logic fall into the category of core concerns. • The core is typically going to contain rules unique to your application.
  • 8. Cross-cutting concerns • While the core of an application defines its primary function, there is a host of secondary operations necessary to keep things running correctly and efficiently. • Security assertions, transactional boundaries, concurrency policies—all are helpful in ensuring the integrity of the system is in check. We define these as aspects.
  • 9. • Banking software must allow users to withdraw money from their accounts, but it would make for an interesting solution if we could withdraw from any account we wanted; we need a security assertion at some point to ensure the requesting user has permission.
  • 10. Plumbing • Once modules have been built to address the core, there’s still the matter of getting data and invocations from point A to point B. Plumbing provides this routing, and may take several forms: • Forwarding control from an HTTP request to some action handler • Obtaining a JDBC connection or JavaMail session • Mapping a nonnative request (JSON, ActionScript, RDBMS SQL) into a Java object.
  • 11. • Plumbing is a means to an end, and therefore of little value in and of itself. • It will benefit us to take an approach that minimizes the time we spend getting data from one endpoint to another.
  • 12. The Container A Container is a host that provides services to guest applications. IT is provide generic services upon which applications may rely. The service support desired is usually defined by some combination of user code and metadata that together follow a contract for interaction between the application and container.
  • 13. The Enterprise JavaBeans™ 3.1 Specification • The Enterprise JavaBeans architecture is a architecture for the development and deployment of component-based business applications. • Applications written using the Enterprise JavaBeans architecture are scalable, transactional, and multi-user secure. • These applications may be written once, and then deployed on any server platform that supports the Enterprise JavaBeans specification. • This means that EJB defines a model for piecing together a full system by integrating modules. Each component may represent a collection of business processes, and these will run centralized on the server.
  • 14. • Additionally, the “distributed” nature will provide a mechanism to spread modules across different processes, physical machines, or even entire networks.
  • 15. • Applications that take advantage of EJB architecture are portable across any compliant Container implementation.
  • 16. Component Types • EJB imposes no API coupling or restrictions upon the classes that will define our business objects. • Commonly known as POJO (Plain Old Java Object) development, this means that an application developer is under no obligation to extend, implement, or have any references tying the application to EJB. • Now we can create class hierarchies however we see fit, and reuse our objects in some non-EJB environment. • Because a POJO class is just like any other class, it does not become an EJB until it’s: 1. Assembled/packaged 2. Deployed 3. Accessed via the Container
  • 17. • EJB are primarily of three types which are briefly described below: Server-Side Component Types Type Description 1 Session Bean Session bean stores data of a particular user for a single session. It can be stateful or stateless. It is less resource intensive as compared to entity beans. Session bean gets destroyed as soon as user session terminates. 2 Entity Bean Entity beans represents persistent data storage. User data can be saved to database via entity beans and later on can be retrived from the database in the entity bean. 3 Message Driven Bean Message driven beans are used in context of JMS (Java Messaging Service). Message Driven Beans can consumes JMS messages from external entities and act accordingly.
  • 18. 1. Session Beans • Also called business logic process objects. … • They represent the business logic of the system. … • Their lifetime is usually an entire session „ When a session is done, the session bean expires •„i.e. Session bean instances exist as long as a specific user is using the system 2. EJB - Stateful Bean Subtypes of Session Beans 1. EJB – Stateless Bean
  • 19. EJB - Stateless Bean A stateless session bean is a type of enterprise bean which is normally used to do independent operations. A stateless session bean as per its name does not have any associated client state, but it may preserve its instance state. EJB Container normally creates a pool of few stateless bean's objects and use these objects to process client's request. Because of pool, instance variable values are not guaranteed to be same across lookups/method calls.
  • 20. Following are the steps required to create a stateless EJB. • Create a remote/local interface exposing the business methods. • This interface will be used by the EJB client application. • Use @Local annotation if EJB client is in same environment where EJB session bean is to be deployed. Use @Remote annotation if EJB client is in different environment where EJB session bean is to be deployed. • Create a stateless session bean implementing the above interface.
  • 21. EJB - Stateful Bean A stateful session bean is a type of enterprise bean which preserve the conversational state with client. A stateful session bean as per its name keeps associated client state in its instance variables. EJB Container creates a separate stateful session bean to process client's each request. As soon as request scope is over, statelful session bean is destroyed. Following are the steps required to create a stateful EJB. • Create a remote/local interface exposing the business methods. • This interface will be used by the EJB client application.
  • 22. • Use @Local annotation if EJB client is in same environment where EJB session bean is to be deployed. • Use @Remote annotation if EJB client is in different environment where EJB session bean is to be deployed. • Create a stateful session bean implementing the above interface.
  • 23. 2. EJB - Message Driven Beans ( MDB ) A message driven bean is a type of enterprise bean which is invoked by EJB container, when it receives a message from queue or topic. Message driven bean is a stateless bean and is used to do task asynchronously (Asynchronous means that you can execute multiple things at a time and we don't have to finish executing the current thing in order to move on to next one). To demonstrate use of message driven bean, we'll make use of EJB-persistence & to do the following tasks. Step1. Create table in database Step2. Create Entity class corresponding to table Step3. Create Data Source and Persistence Unit Step4. Create a stateless ejb having Entity Manager instance
  • 24. Step5. Update stateless ejb.Add methods to add records and get records from database via entity manager. Step 6. Create a Queue named BookQueue in JBoss default application directory. Step 7. A console based application client will send message to this queue. Step 8. Create a Message driven bean which will use the stateless bean to persist the client data. Step 9. EJB Container of JBoss will call the above message driven bean and pass it the message that client will be sending to.
  • 25. 3. Entity beans: Also called business data objects. They represent persistent data „often the data persistence is managed through a database, using JDBC. Entity beans represent data in the system. … • In addition, entity beans are used to search for, modify, create and delete data. …  Usually, this data resides in a relational database. …  Each entity bean typically represents a single row in some database table „ An entity bean instance exists as long as the data is being used … • When the EJB client is done with the instance, the entity bean instance usually returns to a bean pool „
  • 26. •The client for an entity bean is typically a session bean, since behavior usually involves the manipulation of data.
  • 27. EJB – The JAVA Persistence Model EJB 3.0, entity bean used in EJB 2.0 is largely replaced by persistence mechanism. Now entity bean is a simple POJO having mapping with table. Following are the key actors in persistence API Entity - A persistent object representing the data-store record. It is good to be serializable. EntityManager - Persistence interface to do data operations like add/delete/update/find on persistent object(entity). It also helps to execute queries using Query interface. Persistence unit (persistence.xml) - Persistence unit describes the properties of persistence mechanism.
  • 28. Data Source (*ds.xml) - Data Source describes the data- store related properties like connection url. user-name, password etc. To demonstrate EJB persistence mechanism, we're going to do the following tasks. Step 1. Create table in database. Step 2. Create Entity class corresponding to table. Step 3. Create Data Source and Persistence Unit Step 4. Create a stateless EJB having Entity Manager instance. Step 5. Update stateless EJB. Add methods to add records and get records from database via entity manager. Step 6. A console based application client will access the stateless EJB to persist data in database.
  • 29. While server-side component types handle business logic and entities address state, the EJB Container can continue to make our jobs easier by providing a wide range of generic and configurable services. Enterprise applications generally handle a large number of concurrent users, and each request might need to be handled carefully so it does not violate the security or integrity of the application. Additionally, we shouldn’t waste our time wiring our modules together; the container can do this for us. Container servers
  • 30. The EJB container is a container that deploys EJB automatically when Web Server is started. All of the entity objects live in container during its creation to removal. We can deploy more than one entity beans in a container. When the entity bean is deployed in the container the work of the container is to provide a home interface for the entity bean. This home interface allows a client in removing, creating and finding entity objects. It also helps in executing home interface business methods that are not specific to a particular entity bean object. JNDI(Java Naming and Directory Interface) is the standard interface by which the client can look up the entity bean's home interface.
  • 31. Services Description Life Cycle Management JRun is an application server that works for building and deploying server-side Java applications. The role of JRun in the container service is to automatically increase and reduce the number of available bean instances so that there is not much load on the current server. Security Security is one of the most important feature of EJB. Since EJB support authentication and role-driven access control. Transaction transaction mean a unit of work that must be executed in one piece. Container-managed transactions:-These type of transaction are the transaction in which the container begins and commits transactions on behalf of the bean. Bean-managed transactions:-In this type of transaction we have complete control over transactions. This control can be achieved either from the client or from the bean itself. The table given below illustrates the EJB container services:-
  • 32. Dependency injection EJB 3.0 specification provides annotations which can be applied on fields or setter methods to inject dependencies. EJB Container uses the global JNDI registry to locate the dependency. Following annotations are used in EJB 3.0 for dependency injection. @EJB - used to inject other EJB reference. @Resource - used to inject data source or singleton services like session Context, timer Service etc.
  • 33. Concurrency Assuming each Service is represented by one instance, dependency injection alone is a fine solution for a single-threaded application; only one client may be accessing a resource at a given time. However, this quickly becomes a problem in situations where a centralized server is fit to serve many simultaneous requests. So that there are a series of effects upon performance to consider, so the specification allows for configuration in some cases. Otherwise, it’s important to be aware how each component type views concurrency concerns.
  • 34. Instance Pooling/Caching Because of the strict concurrency rules enforced by the Container, an intentional bottleneck is often introduced where a service instance may not be available for processing until some other request has completed. If the service was restricted to a singular instance, all subsequent requests would have to queue up until their turn was reached
  • 35. Transactions A transaction is a single unit of work items which follows the ACID properties. ACID stands for Atomic, Consistent, Isolated and Durable. Atomic - If any of work item fails, the complete unit is considered failed. Success meant all items executes successfully. Consistent - A transaction must keep the system in consistent state. Isolated - Each transaction executes independent of any other transaction. Durable - Transaction should survive system failure if it has been executed or committed.
  • 36. Security Security is a major concern of any enterprise level application. It includes identification of user(s) or system accessing the application and allowing or denying the access to resources within the application. In EJB, security can be declared in declarative way called declarative security in which EJB container manages the security concerns or Custom code can be done in EJB to handle security concern by self
  • 37. Timers Timer Service is a mechanism using which scheduled application can be build. For example, salary slip generation on 1st of every month. EJB 3.0 specification has specified @Timeout annotation which helps in programming the ejb service in a stateless or message driven bean. EJB Container calls the method which is annotated by @Timeout.
  • 38. Naming and Object Stores All naming services essentially do the same thing: they provide clients with a mechanism for locating distributed objects or resources. To accomplish this, a naming service must fulfill two requirements: 1. object binding and 2. A lookup API. • Object binding is the association of a distributed object with a natural language name or identifier. • A lookup API provides the client with an interface to the naming system.
  • 39. Interoperability It’s nice that the dependency injection facilities allow components within EJB to play nicely, so our application may want to consume data from or provide services to other programs, Interoperability is a vital part of EJB. The specification includes the required support for Java RMI- IIOP for remote method invocation and provides for transaction, naming, and security interoperability.
  • 40. Lifecycle Callbacks Some services require some initialization or cleanup to be used properly. For example, a file transfer module may want to open a connection to a remote server before processing requests to transfer files and should safely release all resources before being brought out of service. For component types that have a lifecycle, EJB allows for callback notifications, which act as a hook for the bean provider to receive these events. In the case of our file transfer bean, this may look like:
  • 41. EJB 3.0 provides specification to intercept business methods calls using methods annotated with @AroundInvoke annotation. An interceptor method is called by ejb Container before business method call it is intercepting. Following is the example signature of an interceptor method. Interceptors
  • 42. Platform Integration As a key technology within the Java Enterprise Edition (JEE) 6, EJB aggregates many of the other platform frameworks and APIs: • Java Transaction Service • Java Persistence API • Java Naming and Directory Interface (JNDI) • Security Services • Web Services