SlideShare a Scribd company logo
1 of 30
1 | P a g e
E-commerce Systems
Instructor: Dr. Zainab Khallouf
Enterprise JavaBeans (EJB 3.1)
Acknowledgements:
Lecture notes adapted from:
The Java EE 7 Tutorial.
http://docs.oracle.com/javaee/7/tutorial/doc/javaeetutorial7.pdf
Lecture References:
[1]. docs.oracle.com/javaee/7/tutorial/doc/
[2]. http://netbeans.org/kb/docs/javaee/ecommerce
[3]. Enterprise JavaBeans 3.1, sixth edition, by Andrew Lee Rubinger, Bill Burke,
O'Reilly Media.
[4]. Chapter 4 from Distributed Systems Principles and Paradigms, by A. Tanenbaum
and M. Van Steen.
‫تذكري‬...‫السابقة‬ ‫احملاضرة‬ ‫من‬
‫القسم‬‫املقرر‬ ‫من‬ ‫األول‬:‫حت‬‫ق‬‫ي‬‫متعدد‬ ‫الكرتونية‬ ‫جتارة‬ ‫تطبيق‬ ‫ق‬‫املكوانت‬ ّ‫يضم‬ ‫الطبقات‬ّ‫املوضح‬‫الشكل‬ ‫يف‬ ‫ة‬
:‫التايل‬
‫عن‬ ‫اليوم‬ ‫حماضرة‬Session Beans...
2 | P a g e
‫يف‬‫ر‬‫تع‬Enterprise JavaBeans (EJBs):
 Enterprise JavaBeans (EJBs) are server-side Java EE components
run in the EJB container and encapsulate the business logic of an
application.
‫بسيطة‬ ‫بكلمات‬:EJBs‫تتضمن‬ ‫جافا‬ ‫صفوف‬ ‫هي‬( ‫حقول‬fields‫و‬ )‫طرق‬‫العمل‬ ‫منطق‬ ‫لتحقق‬‫يف‬
‫التطبيق‬،‫اإلضافية‬ ‫ات‬‫ز‬‫الرتمي‬ ‫بعض‬ ‫الصفوف‬ ‫هذه‬ ‫إىل‬ ‫يضاف‬annotations‫حاوي‬ ‫يتمكن‬ ‫حىت‬
‫مكوانت‬EJBs‫أو‬EJBs container‫املكوانت‬ ‫هذه‬ ‫إدارة‬ ‫من‬‫هلا‬ ‫خدمات‬ ‫وتقدمي‬.
Benefits of Enterprise Beans (Enterprise Beans ‫استخدام‬ ‫ائد‬‫و‬‫)ف‬
Enterprise beans can simplify the development of large, distributed
applications.
1. Because the EJBs container provides system-level services
such as security, transaction management, Java Naming and
Directory Interface (JNDI) API lookups, and remote
connectivity to enterprise beans, the bean developer can
concentrate on solving business problems.
2. The enterprise beans are reusable components, and the
application assembler can build new applications from existing
beans.
3. Scalability can be achieved by distributing an application’s
components across multiple machines. The enterprise beans
of an application can run on different machines, and their
location will remain transparent to the clients.
Types of Java Enterprise Beans (EJBs):
1. Session beans.
2. Message-driven beans.
Session Beans
3 | P a g e
What is a Session Bean?
 A session bean is a component that encapsulates business
logic and include methods that can be invoked by a client.
 Session beans are of three types:
1. stateless,
2. stateful,
3. singleton.
Developing Enterprise Application with Session Beans Using
Netbeans:
Step 1:
Creating new enterprise application in Netbeans.
Step 2:
Name and Location.
4 | P a g e
Step 3:
Server and Settings.
Step 4:
5 | P a g e
The new project.
Step 5:
Adding Libraries to CounterBeanFall16-ejb.
Step 6:
Add session beans.
6 | P a g e
7 | P a g e
Step 7:
Clean and Build.
8 | P a g e
The generated .ear (Enterprise Archive) file.
We can explore the content of .ear files using (e.g. WinRAR).
9 | P a g e
Step 8:
Deploy.
10 | P a g e
Server log.
...
INFO: EJB5181:Portable JNDI namesfor EJB CounterSession:
[java:global/CounterBeanFall16/CounterBeanFall16-ejb/CounterSession,
java:global/CounterBeanFall16/CounterBeanFall16-
ejb/CounterSession!ejb.CounterSessionRemote]
INFO: EJB5182:Glassfish-specific(Non-portable) JNDInamesforEJB CounterSession:
[ejb.CounterSessionRemote,ejb.CounterSessionRemote#ejb.CounterSessionRemote]
INFO: CounterBeanFall16was successfullydeployedin1,738 milliseconds.
...
Accessing Session Beans
‫ـ‬‫ل‬ ‫ميكن‬(Session Bean)‫أ‬‫يعرض‬ ‫ن‬‫الطرق‬(Methods)‫تستدعى‬ ‫أن‬ ‫ميكن‬ ‫اليت‬ّ‫إم‬‫من‬ ‫ا‬
‫اجهة‬‫و‬ ‫خالل‬(Business Interface)‫اجهة‬‫و‬ ‫استخدام‬ ‫بدون‬ ‫أو‬(No-interface
view)( ‫صف‬ ‫من‬ ‫فقط‬ ‫العامة‬ ‫الطرق‬ ‫استدعاء‬ ‫ميكن‬ ‫الثانية‬ ‫احلالة‬ ‫ويف‬Session Bean).
‫يكون‬ ‫أن‬ ‫ميكن‬( ‫إىل‬ ‫الوصول‬Session Bean):‫(عن‬)‫بعد‬remote،)‫(حملي‬local،‫أو‬
)‫وب‬ ‫(كخدمة‬web service(ّ‫ن‬‫أ‬ ً‫ا‬‫علم‬‫سي‬ ‫الوب‬ ‫خدمات‬ ‫ع‬‫موضو‬‫ع‬‫موضو‬ ‫كون‬‫حماضرة‬
‫مستقلة‬.)
11 | P a g e
‫لتوضيح‬‫احمللي‬ ‫الوصول‬ ‫و‬ ‫بعد‬ ‫عن‬ ‫الوصول‬ ‫بني‬ ‫الفرق‬‫نرى‬ ‫دعنا‬‫بني‬ ‫الفرق‬‫املستدعني‬‫و‬ ‫احملليني‬
‫املستدعني‬‫البعيدين‬( ‫ـ‬‫ل‬Session Bean.)
Local Clients
A local client has these characteristics.
 It must run in the same application as the enterprise bean it
accesses.
 It can be a web component or another enterprise bean.
To build an enterprise bean that allows only local access, you may
do one of the following:
 Create an enterprise bean implementation class that does not
implement a business interface.
For example:
@Stateless
public class MyBean { ... }
 Annotate the business interface of the enterprise bean as a
@Local interface.
For example:
@Local
public interface InterfaceName { ... }
 Specify the interface by decorating the bean class with @Local
and specify the interface name.
For example:
@Local(InterfaceName.class)
public class BeanName implements InterfaceName { ... }
Remote Clients
A remote client of an enterprise bean has the following traits:
12 | P a g e
 It can run on a different machine and a different JVM from
the enterprise bean it accesses. (It is not required to run on a
different JVM.)
 It can be a web component, an application client, or another
enterprise bean.
 In this case, the session bean must implement a business
interface.
To create an enterprise bean that allows remote access, you must
either
 Decorate the business interface of the enterprise bean with
the @Remote annotation:
@Remote
public interface InterfaceName { ... }
 Decorate the bean class with @Remote, specifying the
business interface or interfaces:
@Remote(InterfaceName.class)
public class BeanName implements InterfaceName { ... }
Using Enterprise Beans in Clients
 The client of an enterprise bean obtains a reference to an
instance of an enterprise bean through either:
1. Dependency injection
o Dependency injection uses the @EJB annotation from
javax.ejb.EJB
o And specify the enterprise bean's implementation class
or enterprise bean's local business interface name (local
or remote)
13 | P a g e
o Can be used by local clients (i.e. must run in the same
application as the enterprise bean it accesses) or remote
clients that run within a Java EE server-managed
environment. Examples:
 Web tier components.
 Business tier compononts.
2. JNDI Syntax
‫عرض‬ ‫قبل‬‫كيفية‬‫استخدام‬JNDI‫توضيب‬ ‫كيفية‬‫عن‬ ‫فكرة‬ ‫أنخذ‬ ‫دعنا‬(Packaging)‫تطبيق‬JAVA
EE
Note About Packaging:
 A Java EE application is delivered in a Java Archive (JAR) file, a
Web Archive (WAR) file, or an Enterprise Archive (EAR) file.
o A WAR or EAR file is a standard JAR (.jar) file with a .war
or .ear extension.
 An EAR file can contain Java EE modules of the following
types:
o EJB modules, which contain class files for enterprise
beans and, optionally, an EJB deployment descriptor (A
deployment descriptor, an XML document with an .xml
extension, describes the deployment settings of an
application, a module, or a component. ). EJB modules
are packaged as JAR files with a .jar extension.
o Web modules, which contain servlet class files, web files,
supporting class files, GIF and HTML files, and, optionally,
a web application deployment descriptor. Web modules
are packaged as JAR files with a .war (web archive)
extension.
o Application client modules, which contain class files and,
optionally, an application client deployment descriptor.
14 | P a g e
Application client modules are packaged as JAR files
with a .jar extension.
o Resource adapter modules, (A resource adapter is a Java
EE component that implements the Java EE Connector
Architecture for a specific EIS-like enterprise resource
planning). Resource adapter modules are packaged as
JAR files with an .rar (resource adapter archive)
extension.
 Packaging Enterprise Beans in WAR Modules:
o Enterprise beans often provide the business logic of a web
application. In these cases, packaging the enterprise bean
within the web application's WAR module simplifies
deployment and application organization.
o Web Module Structure
15 | P a g e
 classes: A directory that contains server-side classes:
servlets, enterprise bean class files, utility classes, and
JavaBeans components.
 lib: A directory that contains JAR files that contain
enterprise beans, and JAR archives of libraries called
by server-side classes.
 Deployment descriptors, such as web.xml (the web
application deployment descriptor) and ejb-jar.xml
(an EJB deployment descriptor).
Example 1:
Example 2:
16 | P a g e
 Three JNDI namespaces are used for portable JNDI lookups:
o java:global:
 JNDI global addresses are of the following form:
java:global[/application name]/module name
/enterprise bean name[/interface name ]
 Application name is required only if the application
is packaged within an Enterprise Archive.
 The interface name is required only if the
enterprise bean implements more than one
business interface.
o java:module JNDI namespace used to look up local
enterprise beans within the same module. JNDI
addresses using the java:module namespace are of the
following form:
java:module/enterprise bean name/[interface name]
 The interface name is required only if the
enterprise bean implements more than one
business interface.
o java:app JNDI namespace used to look up local
enterprise beans packaged within the same application.
17 | P a g e
JNDI addresses using the java:app namespace are of the
following form:
java:app[/module name]/enterprise bean name
[/interface name]
 The module name is optional. The interface name is
required only if the enterprise bean implements
more than one business interface.
o Example:
If an enterprise bean, CounterSession.java, from an
application CounterBean (EAR archive)is packaged
within the module CounterBean-ejb.jar.
The JNDI name using the java:global namespace is:
We can verify this name from the server log.
INFO: EJB5181:Portable JNDI names for EJB CounterSession:
[java:global/CounterBean/CounterBean-
ejb/CounterSession!ejb.CounterSessionRemote,
java:global/CounterBean/CounterBean-ejb/CounterSession]
INFO: EJB5182:Glassfish-specific (Non-portable) JNDI names for EJB
CounterSession: [ejb.CounterSessionRemote,
ejb.CounterSessionRemote#ejb.CounterSessionRemote]
18 | P a g e
INFO: CounterBean a été déployé en 875 ms.
INFO: set()
INFO: count()
Return to page 454 from the JEE 7 Tutorial for further details.
Stateless Session Bean (SLSB)
 The SLSB class is annotated with: @Stateless
 A stateless session bean does not maintain a conversational
state with the client. When a client invokes the methods of a
stateless bean, the bean's instance variables may contain a
state specific to that client but only for the duration of the
invocation.
 Stateless session bean can be easily pooled. Except during
method invocation, all instances of a stateless bean are
equivalent, allowing the EJB container to assign an instance
to any client.
 Clients may, however, change the state of instance variables
in pooled stateless beans, and this state is held over to the
next invocation of the pooled stateless bean.
Stateless Session Bean Example Application:
-This application includes a counter SLSB CounterSession, this
bean exposes two methods in a remote interface
CounterSessionRemote: set(int val): set the initial value of the
counter and count() increases by one the value of the counter.
-The client is a JAVA SE application.
19 | P a g e
The CounterSession SLSB and its remote interface
CounterSessionRemote:
The client:
20 | P a g e
The output:
Note 1: in netbeans, every time you change in the code of the bean
you need to “clean and build” then “deploy”
Note 2: About integrating EJB project in the client application.
21 | P a g e
Example 2
Stateful Session Bean (SFSB)
 The SFSB class is annotated with: @Stateful
 Stateful session beans maintain conversational state, which
means that the instance variables of the bean class can
maintain data specific to a unique client between method
invocations. When the client terminates, its session bean
appears to terminate and is no longer associated with the
client.
 Stateful session beans are managed using cache; the size of
the cache specifies the maximum number of session beans
that are held in cache.
22 | P a g e
 If the cache overflows (when the number of beans exceeds
max-cache-size), the container then passivate some beans or
writes out the serialized state of the bean into a file.
 Stateful Session Bean Example Application:
o This application includes a counter SFSB CounterSession,
this bean exposes three methods in a remote interface
CounterSessionRemote, these methods are: set(int val):
set the initial value of the counter and count() increases
by one the value of the counter, and remove() remove
the SFSB instance.
o The client is a JAVA SE application.
The CounterSession SFSB:
23 | P a g e
package ejb;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.ejb.Remove;
import javax.ejb.Stateful;
@Stateful
public class CounterSession implements CounterSessionRemote {
private int val;
@Override
public int count() {
System.out.println("count()");
val = val + 1;
return val;
}
@Remove
@Override
public void remove() {
System.out.println("remove()");
}
@Override
public void set(int val) {
this.val = val;
System.out.println("set()");
}
@PostConstruct
public void construct() {
System.out.println("construct()");
}
24 | P a g e
@PostActivate
public void activate() {
System.out.println("activate()");
}
@PrePassivate
public void passivate() {
System.out.println("passivate()");
}
@PreDestroy
public void destroy() {
System.out.println("destroy()");
}
}
 The callbacks of the Lifecycles of Enterprise Beans:
The callbacks:‫حياة‬ ‫من‬ ‫خمتلفة‬ ‫احل‬‫ر‬‫م‬ ‫يف‬ ‫معينة‬ ‫مهام‬ ‫بتنفيذ‬ ‫تسمح‬ ‫طرق‬Enterprise Beans.
o @PostConstruct: Methods annotated with
@PostConstruct are invoked by the container on newly
constructed bean instances (used for stateless , stateful
session bean, and message driven bean)
o @PreDestroy: Methods annotated with @PreDestroy are
invoked after any method annotated @Remove has
completed and before the container removes the
enterprise bean instance. (used for stateless , stateful
session bean, and message driven bean)
o @PostActivate: denote method to be invoked after the
stateful session activation.
o @PrePassivate: denote method to be invoked before the
stateful session passivation.
25 | P a g e
o @Remove: remove the bean after calling the method
annotated by @Remove (Used with stateful session
bean).
The client:
Output
And the server log
26 | P a g e
Singleton Session Beans
 A singleton session bean is instantiated once per application and
exists for the lifecycle of the application.
 Singleton session bean is shared and concurrently accessed by
clients.
Creating a Singleton Session Bean
 The javax.ejb.Singleton annotation is used to specify that the
enterprise bean implementation class is a singleton session bean:
@Singleton
public class SingletonBean { ... }
Initializing Singleton Session Beans
 The EJB container is responsible for determining when to
initialize a singleton session bean instance unless the singleton
session bean implementation class is annotated with the
javax.ejb.Startup annotation.
 The @javax.ejb.Startup annotation marks that the container
must start the bean instance alongside application startup.
@Startup
27 | P a g e
@Singleton
public class StatusBean {
...
}
Managing Concurrent Access in a Singleton Session Bean
 Singleton session beans are designed for concurrent access.
 Concurrent access to the singleton’s business methods can be
controlled in two ways:
1. Container-managed concurrency.
2. Bean-managed concurrency.
 The javax.ejb.ConcurrencyManagement annotation is used to
specify container-managed or bean-managed concurrency for
the singleton like this:
-avax.ejb.ConcurrencyManagementType.CONTAINER
-javax.ejb.ConcurrencyManagementType.BEAN
 By default the container-managed concurrency is used.
Container-Managed Concurrency
1. Annotate a singleton’s business method with:
o @Lock(READ) if the method can be concurrently
accessed with many clients.
o Annotate the business method with @Lock(WRITE) if
the singleton session bean should be locked to other
clients while a client is calling that method.
o If no @Lock annotation is present on the singleton
class, the default lock type, @Lock(WRITE), is applied
to all business methods.
Bean-Managed Concurrency
28 | P a g e
2. Developers who create singletons with bean-managed
concurrency are allowed to use the Java programming
language synchronization primitives.
Singleton Session Bean Example Application
o A simple singleton with one method, getHits, that increments a
counter representing the number of times the method has been
accessed.
o The client is a standalone java client application.
The singleton bean CounterBean
The following version of CounterBean is equivalent to the preceding
version:
package counter.ejb;
29 | P a g e
import javax.ejb.Singleton;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType.CONTAINER;
import javax.ejb.Lock;
import javax.ejb.LockType.WRITE;
@Singleton
@ConcurrencyManagement(CONTAINER)
public class CounterBean {
private int hits = 1;
// Increment and return the number of hits
@Lock(WRITE)
public int getHits() {
return hits++;
}
}
The client:
Output:
30 | P a g e

More Related Content

What's hot

EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJBPeter R. Egli
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance FeaturesEmprovise
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
Lab 5b) create a java server faces application
Lab 5b) create a java server faces applicationLab 5b) create a java server faces application
Lab 5b) create a java server faces applicationtechbed
 
Part 7 packaging and deployment
Part 7 packaging and deploymentPart 7 packaging and deployment
Part 7 packaging and deploymenttechbed
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0sukace
 
7) packaging and deployment
7) packaging and deployment7) packaging and deployment
7) packaging and deploymenttechbed
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformBozhidar Bozhanov
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformArun Gupta
 

What's hot (20)

Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 
EJB 2
EJB 2EJB 2
EJB 2
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Java bean
Java beanJava bean
Java bean
 
Hibernate notes
Hibernate notesHibernate notes
Hibernate notes
 
Spring notes
Spring notesSpring notes
Spring notes
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 
Lab 5b) create a java server faces application
Lab 5b) create a java server faces applicationLab 5b) create a java server faces application
Lab 5b) create a java server faces application
 
Part 7 packaging and deployment
Part 7 packaging and deploymentPart 7 packaging and deployment
Part 7 packaging and deployment
 
15 jpa
15 jpa15 jpa
15 jpa
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0
 
7) packaging and deployment
7) packaging and deployment7) packaging and deployment
7) packaging and deployment
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platform
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 Platform
 
Jsf+ejb 50
Jsf+ejb 50Jsf+ejb 50
Jsf+ejb 50
 

Viewers also liked

Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...Cavitehousesrushforsale Inhouse
 
Currículo_Resumido_Luiz_Facioli_21_09_15
Currículo_Resumido_Luiz_Facioli_21_09_15Currículo_Resumido_Luiz_Facioli_21_09_15
Currículo_Resumido_Luiz_Facioli_21_09_15Luiz Facioli Neto
 
Early Childhood Education For BOS revised 1
Early Childhood Education For BOS revised 1Early Childhood Education For BOS revised 1
Early Childhood Education For BOS revised 1Alfredo Perez
 
алгебра 3
алгебра 3алгебра 3
алгебра 3pogromskaya
 
การใส่รูปภาพ
 การใส่รูปภาพ การใส่รูปภาพ
การใส่รูปภาพsoysudajibb
 
алгебра 2
алгебра 2алгебра 2
алгебра 2pogromskaya
 
Grad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje Rusanda
Grad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje RusandaGrad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje Rusanda
Grad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje RusandaNALED Serbia
 
IMPORTANCIA DEL PLAN DE MANEJO DE AGUAS
IMPORTANCIA DEL PLAN DE MANEJO DE AGUASIMPORTANCIA DEL PLAN DE MANEJO DE AGUAS
IMPORTANCIA DEL PLAN DE MANEJO DE AGUASwilly mosquera
 
Lecture15
Lecture15Lecture15
Lecture15Muuluu
 
Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...Cavitehousesrushforsale Inhouse
 
Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...
Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...
Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...Cavitehousesrushforsale Inhouse
 
Creative leadership the value design brigns to business
Creative leadership the value design brigns to businessCreative leadership the value design brigns to business
Creative leadership the value design brigns to businessNathan Shedroff
 
Institutional Opportunities for Early Childhood Education (ECE) in the South ...
Institutional Opportunities for Early Childhood Education (ECE) in the South ...Institutional Opportunities for Early Childhood Education (ECE) in the South ...
Institutional Opportunities for Early Childhood Education (ECE) in the South ...Mirza Md Hasan
 

Viewers also liked (17)

Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...
 
Currículo_Resumido_Luiz_Facioli_21_09_15
Currículo_Resumido_Luiz_Facioli_21_09_15Currículo_Resumido_Luiz_Facioli_21_09_15
Currículo_Resumido_Luiz_Facioli_21_09_15
 
Early Childhood Education For BOS revised 1
Early Childhood Education For BOS revised 1Early Childhood Education For BOS revised 1
Early Childhood Education For BOS revised 1
 
алгебра 3
алгебра 3алгебра 3
алгебра 3
 
การใส่รูปภาพ
 การใส่รูปภาพ การใส่รูปภาพ
การใส่รูปภาพ
 
алгебра 2
алгебра 2алгебра 2
алгебра 2
 
Grad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje Rusanda
Grad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje RusandaGrad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje Rusanda
Grad Zrenjanin - Javno privatno partnerstvo: rekonstrukcija Banje Rusanda
 
IMPORTANCIA DEL PLAN DE MANEJO DE AGUAS
IMPORTANCIA DEL PLAN DE MANEJO DE AGUASIMPORTANCIA DEL PLAN DE MANEJO DE AGUAS
IMPORTANCIA DEL PLAN DE MANEJO DE AGUAS
 
Lecture15
Lecture15Lecture15
Lecture15
 
Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...Single detached houses rush rush for sale/brand new houses rush for sale in c...
Single detached houses rush rush for sale/brand new houses rush for sale in c...
 
AfterADisasterGuide
AfterADisasterGuideAfterADisasterGuide
AfterADisasterGuide
 
Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...
Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...
Single detached House in Cavite/4BR/15% down Lipat In 60 Days/RFO/Foreclosed/...
 
DESIREE DALAIS (1)
DESIREE DALAIS (1)DESIREE DALAIS (1)
DESIREE DALAIS (1)
 
Lec6 ecom fall16
Lec6 ecom fall16Lec6 ecom fall16
Lec6 ecom fall16
 
Vinilos
VinilosVinilos
Vinilos
 
Creative leadership the value design brigns to business
Creative leadership the value design brigns to businessCreative leadership the value design brigns to business
Creative leadership the value design brigns to business
 
Institutional Opportunities for Early Childhood Education (ECE) in the South ...
Institutional Opportunities for Early Childhood Education (ECE) in the South ...Institutional Opportunities for Early Childhood Education (ECE) in the South ...
Institutional Opportunities for Early Childhood Education (ECE) in the South ...
 

Similar to Ecom lec3 16_ej_bs

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).pdfSPAMVEDANT
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3phanleson
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1Д. Ганаа
 
Understanding and extending p2 for fun and profit
Understanding and extending p2 for fun and profitUnderstanding and extending p2 for fun and profit
Understanding and extending p2 for fun and profitPascal Rapicault
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
Monoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is ModularityMonoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is ModularityGraham Charters
 
Summer industrial trainingnew
Summer industrial trainingnewSummer industrial trainingnew
Summer industrial trainingnewVignesh Ramesh
 
Introduction to java ee
Introduction to java eeIntroduction to java ee
Introduction to java eeRanjan Kumar
 

Similar to Ecom lec3 16_ej_bs (20)

Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
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
 
Java EE 7 introduction
Java EE 7  introductionJava EE 7  introduction
Java EE 7 introduction
 
Java ee introduction
Java ee introductionJava ee introduction
Java ee introduction
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
 
Understanding and extending p2 for fun and profit
Understanding and extending p2 for fun and profitUnderstanding and extending p2 for fun and profit
Understanding and extending p2 for fun and profit
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Monoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is ModularityMonoliths are so 2001 – What you need is Modularity
Monoliths are so 2001 – What you need is Modularity
 
Summer industrial trainingnew
Summer industrial trainingnewSummer industrial trainingnew
Summer industrial trainingnew
 
Lec2 ecom fall16
Lec2 ecom fall16Lec2 ecom fall16
Lec2 ecom fall16
 
Introduction to java ee
Introduction to java eeIntroduction to java ee
Introduction to java ee
 
Java basic
Java basicJava basic
Java basic
 
Spring
SpringSpring
Spring
 

Recently uploaded

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 

Ecom lec3 16_ej_bs

  • 1. 1 | P a g e E-commerce Systems Instructor: Dr. Zainab Khallouf Enterprise JavaBeans (EJB 3.1) Acknowledgements: Lecture notes adapted from: The Java EE 7 Tutorial. http://docs.oracle.com/javaee/7/tutorial/doc/javaeetutorial7.pdf Lecture References: [1]. docs.oracle.com/javaee/7/tutorial/doc/ [2]. http://netbeans.org/kb/docs/javaee/ecommerce [3]. Enterprise JavaBeans 3.1, sixth edition, by Andrew Lee Rubinger, Bill Burke, O'Reilly Media. [4]. Chapter 4 from Distributed Systems Principles and Paradigms, by A. Tanenbaum and M. Van Steen. ‫تذكري‬...‫السابقة‬ ‫احملاضرة‬ ‫من‬ ‫القسم‬‫املقرر‬ ‫من‬ ‫األول‬:‫حت‬‫ق‬‫ي‬‫متعدد‬ ‫الكرتونية‬ ‫جتارة‬ ‫تطبيق‬ ‫ق‬‫املكوانت‬ ّ‫يضم‬ ‫الطبقات‬ّ‫املوضح‬‫الشكل‬ ‫يف‬ ‫ة‬ :‫التايل‬ ‫عن‬ ‫اليوم‬ ‫حماضرة‬Session Beans...
  • 2. 2 | P a g e ‫يف‬‫ر‬‫تع‬Enterprise JavaBeans (EJBs):  Enterprise JavaBeans (EJBs) are server-side Java EE components run in the EJB container and encapsulate the business logic of an application. ‫بسيطة‬ ‫بكلمات‬:EJBs‫تتضمن‬ ‫جافا‬ ‫صفوف‬ ‫هي‬( ‫حقول‬fields‫و‬ )‫طرق‬‫العمل‬ ‫منطق‬ ‫لتحقق‬‫يف‬ ‫التطبيق‬،‫اإلضافية‬ ‫ات‬‫ز‬‫الرتمي‬ ‫بعض‬ ‫الصفوف‬ ‫هذه‬ ‫إىل‬ ‫يضاف‬annotations‫حاوي‬ ‫يتمكن‬ ‫حىت‬ ‫مكوانت‬EJBs‫أو‬EJBs container‫املكوانت‬ ‫هذه‬ ‫إدارة‬ ‫من‬‫هلا‬ ‫خدمات‬ ‫وتقدمي‬. Benefits of Enterprise Beans (Enterprise Beans ‫استخدام‬ ‫ائد‬‫و‬‫)ف‬ Enterprise beans can simplify the development of large, distributed applications. 1. Because the EJBs container provides system-level services such as security, transaction management, Java Naming and Directory Interface (JNDI) API lookups, and remote connectivity to enterprise beans, the bean developer can concentrate on solving business problems. 2. The enterprise beans are reusable components, and the application assembler can build new applications from existing beans. 3. Scalability can be achieved by distributing an application’s components across multiple machines. The enterprise beans of an application can run on different machines, and their location will remain transparent to the clients. Types of Java Enterprise Beans (EJBs): 1. Session beans. 2. Message-driven beans. Session Beans
  • 3. 3 | P a g e What is a Session Bean?  A session bean is a component that encapsulates business logic and include methods that can be invoked by a client.  Session beans are of three types: 1. stateless, 2. stateful, 3. singleton. Developing Enterprise Application with Session Beans Using Netbeans: Step 1: Creating new enterprise application in Netbeans. Step 2: Name and Location.
  • 4. 4 | P a g e Step 3: Server and Settings. Step 4:
  • 5. 5 | P a g e The new project. Step 5: Adding Libraries to CounterBeanFall16-ejb. Step 6: Add session beans.
  • 6. 6 | P a g e
  • 7. 7 | P a g e Step 7: Clean and Build.
  • 8. 8 | P a g e The generated .ear (Enterprise Archive) file. We can explore the content of .ear files using (e.g. WinRAR).
  • 9. 9 | P a g e Step 8: Deploy.
  • 10. 10 | P a g e Server log. ... INFO: EJB5181:Portable JNDI namesfor EJB CounterSession: [java:global/CounterBeanFall16/CounterBeanFall16-ejb/CounterSession, java:global/CounterBeanFall16/CounterBeanFall16- ejb/CounterSession!ejb.CounterSessionRemote] INFO: EJB5182:Glassfish-specific(Non-portable) JNDInamesforEJB CounterSession: [ejb.CounterSessionRemote,ejb.CounterSessionRemote#ejb.CounterSessionRemote] INFO: CounterBeanFall16was successfullydeployedin1,738 milliseconds. ... Accessing Session Beans ‫ـ‬‫ل‬ ‫ميكن‬(Session Bean)‫أ‬‫يعرض‬ ‫ن‬‫الطرق‬(Methods)‫تستدعى‬ ‫أن‬ ‫ميكن‬ ‫اليت‬ّ‫إم‬‫من‬ ‫ا‬ ‫اجهة‬‫و‬ ‫خالل‬(Business Interface)‫اجهة‬‫و‬ ‫استخدام‬ ‫بدون‬ ‫أو‬(No-interface view)( ‫صف‬ ‫من‬ ‫فقط‬ ‫العامة‬ ‫الطرق‬ ‫استدعاء‬ ‫ميكن‬ ‫الثانية‬ ‫احلالة‬ ‫ويف‬Session Bean). ‫يكون‬ ‫أن‬ ‫ميكن‬( ‫إىل‬ ‫الوصول‬Session Bean):‫(عن‬)‫بعد‬remote،)‫(حملي‬local،‫أو‬ )‫وب‬ ‫(كخدمة‬web service(ّ‫ن‬‫أ‬ ً‫ا‬‫علم‬‫سي‬ ‫الوب‬ ‫خدمات‬ ‫ع‬‫موضو‬‫ع‬‫موضو‬ ‫كون‬‫حماضرة‬ ‫مستقلة‬.)
  • 11. 11 | P a g e ‫لتوضيح‬‫احمللي‬ ‫الوصول‬ ‫و‬ ‫بعد‬ ‫عن‬ ‫الوصول‬ ‫بني‬ ‫الفرق‬‫نرى‬ ‫دعنا‬‫بني‬ ‫الفرق‬‫املستدعني‬‫و‬ ‫احملليني‬ ‫املستدعني‬‫البعيدين‬( ‫ـ‬‫ل‬Session Bean.) Local Clients A local client has these characteristics.  It must run in the same application as the enterprise bean it accesses.  It can be a web component or another enterprise bean. To build an enterprise bean that allows only local access, you may do one of the following:  Create an enterprise bean implementation class that does not implement a business interface. For example: @Stateless public class MyBean { ... }  Annotate the business interface of the enterprise bean as a @Local interface. For example: @Local public interface InterfaceName { ... }  Specify the interface by decorating the bean class with @Local and specify the interface name. For example: @Local(InterfaceName.class) public class BeanName implements InterfaceName { ... } Remote Clients A remote client of an enterprise bean has the following traits:
  • 12. 12 | P a g e  It can run on a different machine and a different JVM from the enterprise bean it accesses. (It is not required to run on a different JVM.)  It can be a web component, an application client, or another enterprise bean.  In this case, the session bean must implement a business interface. To create an enterprise bean that allows remote access, you must either  Decorate the business interface of the enterprise bean with the @Remote annotation: @Remote public interface InterfaceName { ... }  Decorate the bean class with @Remote, specifying the business interface or interfaces: @Remote(InterfaceName.class) public class BeanName implements InterfaceName { ... } Using Enterprise Beans in Clients  The client of an enterprise bean obtains a reference to an instance of an enterprise bean through either: 1. Dependency injection o Dependency injection uses the @EJB annotation from javax.ejb.EJB o And specify the enterprise bean's implementation class or enterprise bean's local business interface name (local or remote)
  • 13. 13 | P a g e o Can be used by local clients (i.e. must run in the same application as the enterprise bean it accesses) or remote clients that run within a Java EE server-managed environment. Examples:  Web tier components.  Business tier compononts. 2. JNDI Syntax ‫عرض‬ ‫قبل‬‫كيفية‬‫استخدام‬JNDI‫توضيب‬ ‫كيفية‬‫عن‬ ‫فكرة‬ ‫أنخذ‬ ‫دعنا‬(Packaging)‫تطبيق‬JAVA EE Note About Packaging:  A Java EE application is delivered in a Java Archive (JAR) file, a Web Archive (WAR) file, or an Enterprise Archive (EAR) file. o A WAR or EAR file is a standard JAR (.jar) file with a .war or .ear extension.  An EAR file can contain Java EE modules of the following types: o EJB modules, which contain class files for enterprise beans and, optionally, an EJB deployment descriptor (A deployment descriptor, an XML document with an .xml extension, describes the deployment settings of an application, a module, or a component. ). EJB modules are packaged as JAR files with a .jar extension. o Web modules, which contain servlet class files, web files, supporting class files, GIF and HTML files, and, optionally, a web application deployment descriptor. Web modules are packaged as JAR files with a .war (web archive) extension. o Application client modules, which contain class files and, optionally, an application client deployment descriptor.
  • 14. 14 | P a g e Application client modules are packaged as JAR files with a .jar extension. o Resource adapter modules, (A resource adapter is a Java EE component that implements the Java EE Connector Architecture for a specific EIS-like enterprise resource planning). Resource adapter modules are packaged as JAR files with an .rar (resource adapter archive) extension.  Packaging Enterprise Beans in WAR Modules: o Enterprise beans often provide the business logic of a web application. In these cases, packaging the enterprise bean within the web application's WAR module simplifies deployment and application organization. o Web Module Structure
  • 15. 15 | P a g e  classes: A directory that contains server-side classes: servlets, enterprise bean class files, utility classes, and JavaBeans components.  lib: A directory that contains JAR files that contain enterprise beans, and JAR archives of libraries called by server-side classes.  Deployment descriptors, such as web.xml (the web application deployment descriptor) and ejb-jar.xml (an EJB deployment descriptor). Example 1: Example 2:
  • 16. 16 | P a g e  Three JNDI namespaces are used for portable JNDI lookups: o java:global:  JNDI global addresses are of the following form: java:global[/application name]/module name /enterprise bean name[/interface name ]  Application name is required only if the application is packaged within an Enterprise Archive.  The interface name is required only if the enterprise bean implements more than one business interface. o java:module JNDI namespace used to look up local enterprise beans within the same module. JNDI addresses using the java:module namespace are of the following form: java:module/enterprise bean name/[interface name]  The interface name is required only if the enterprise bean implements more than one business interface. o java:app JNDI namespace used to look up local enterprise beans packaged within the same application.
  • 17. 17 | P a g e JNDI addresses using the java:app namespace are of the following form: java:app[/module name]/enterprise bean name [/interface name]  The module name is optional. The interface name is required only if the enterprise bean implements more than one business interface. o Example: If an enterprise bean, CounterSession.java, from an application CounterBean (EAR archive)is packaged within the module CounterBean-ejb.jar. The JNDI name using the java:global namespace is: We can verify this name from the server log. INFO: EJB5181:Portable JNDI names for EJB CounterSession: [java:global/CounterBean/CounterBean- ejb/CounterSession!ejb.CounterSessionRemote, java:global/CounterBean/CounterBean-ejb/CounterSession] INFO: EJB5182:Glassfish-specific (Non-portable) JNDI names for EJB CounterSession: [ejb.CounterSessionRemote, ejb.CounterSessionRemote#ejb.CounterSessionRemote]
  • 18. 18 | P a g e INFO: CounterBean a été déployé en 875 ms. INFO: set() INFO: count() Return to page 454 from the JEE 7 Tutorial for further details. Stateless Session Bean (SLSB)  The SLSB class is annotated with: @Stateless  A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean's instance variables may contain a state specific to that client but only for the duration of the invocation.  Stateless session bean can be easily pooled. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client.  Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean. Stateless Session Bean Example Application: -This application includes a counter SLSB CounterSession, this bean exposes two methods in a remote interface CounterSessionRemote: set(int val): set the initial value of the counter and count() increases by one the value of the counter. -The client is a JAVA SE application.
  • 19. 19 | P a g e The CounterSession SLSB and its remote interface CounterSessionRemote: The client:
  • 20. 20 | P a g e The output: Note 1: in netbeans, every time you change in the code of the bean you need to “clean and build” then “deploy” Note 2: About integrating EJB project in the client application.
  • 21. 21 | P a g e Example 2 Stateful Session Bean (SFSB)  The SFSB class is annotated with: @Stateful  Stateful session beans maintain conversational state, which means that the instance variables of the bean class can maintain data specific to a unique client between method invocations. When the client terminates, its session bean appears to terminate and is no longer associated with the client.  Stateful session beans are managed using cache; the size of the cache specifies the maximum number of session beans that are held in cache.
  • 22. 22 | P a g e  If the cache overflows (when the number of beans exceeds max-cache-size), the container then passivate some beans or writes out the serialized state of the bean into a file.  Stateful Session Bean Example Application: o This application includes a counter SFSB CounterSession, this bean exposes three methods in a remote interface CounterSessionRemote, these methods are: set(int val): set the initial value of the counter and count() increases by one the value of the counter, and remove() remove the SFSB instance. o The client is a JAVA SE application. The CounterSession SFSB:
  • 23. 23 | P a g e package ejb; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.ejb.PostActivate; import javax.ejb.PrePassivate; import javax.ejb.Remove; import javax.ejb.Stateful; @Stateful public class CounterSession implements CounterSessionRemote { private int val; @Override public int count() { System.out.println("count()"); val = val + 1; return val; } @Remove @Override public void remove() { System.out.println("remove()"); } @Override public void set(int val) { this.val = val; System.out.println("set()"); } @PostConstruct public void construct() { System.out.println("construct()"); }
  • 24. 24 | P a g e @PostActivate public void activate() { System.out.println("activate()"); } @PrePassivate public void passivate() { System.out.println("passivate()"); } @PreDestroy public void destroy() { System.out.println("destroy()"); } }  The callbacks of the Lifecycles of Enterprise Beans: The callbacks:‫حياة‬ ‫من‬ ‫خمتلفة‬ ‫احل‬‫ر‬‫م‬ ‫يف‬ ‫معينة‬ ‫مهام‬ ‫بتنفيذ‬ ‫تسمح‬ ‫طرق‬Enterprise Beans. o @PostConstruct: Methods annotated with @PostConstruct are invoked by the container on newly constructed bean instances (used for stateless , stateful session bean, and message driven bean) o @PreDestroy: Methods annotated with @PreDestroy are invoked after any method annotated @Remove has completed and before the container removes the enterprise bean instance. (used for stateless , stateful session bean, and message driven bean) o @PostActivate: denote method to be invoked after the stateful session activation. o @PrePassivate: denote method to be invoked before the stateful session passivation.
  • 25. 25 | P a g e o @Remove: remove the bean after calling the method annotated by @Remove (Used with stateful session bean). The client: Output And the server log
  • 26. 26 | P a g e Singleton Session Beans  A singleton session bean is instantiated once per application and exists for the lifecycle of the application.  Singleton session bean is shared and concurrently accessed by clients. Creating a Singleton Session Bean  The javax.ejb.Singleton annotation is used to specify that the enterprise bean implementation class is a singleton session bean: @Singleton public class SingletonBean { ... } Initializing Singleton Session Beans  The EJB container is responsible for determining when to initialize a singleton session bean instance unless the singleton session bean implementation class is annotated with the javax.ejb.Startup annotation.  The @javax.ejb.Startup annotation marks that the container must start the bean instance alongside application startup. @Startup
  • 27. 27 | P a g e @Singleton public class StatusBean { ... } Managing Concurrent Access in a Singleton Session Bean  Singleton session beans are designed for concurrent access.  Concurrent access to the singleton’s business methods can be controlled in two ways: 1. Container-managed concurrency. 2. Bean-managed concurrency.  The javax.ejb.ConcurrencyManagement annotation is used to specify container-managed or bean-managed concurrency for the singleton like this: -avax.ejb.ConcurrencyManagementType.CONTAINER -javax.ejb.ConcurrencyManagementType.BEAN  By default the container-managed concurrency is used. Container-Managed Concurrency 1. Annotate a singleton’s business method with: o @Lock(READ) if the method can be concurrently accessed with many clients. o Annotate the business method with @Lock(WRITE) if the singleton session bean should be locked to other clients while a client is calling that method. o If no @Lock annotation is present on the singleton class, the default lock type, @Lock(WRITE), is applied to all business methods. Bean-Managed Concurrency
  • 28. 28 | P a g e 2. Developers who create singletons with bean-managed concurrency are allowed to use the Java programming language synchronization primitives. Singleton Session Bean Example Application o A simple singleton with one method, getHits, that increments a counter representing the number of times the method has been accessed. o The client is a standalone java client application. The singleton bean CounterBean The following version of CounterBean is equivalent to the preceding version: package counter.ejb;
  • 29. 29 | P a g e import javax.ejb.Singleton; import javax.ejb.ConcurrencyManagement; import javax.ejb.ConcurrencyManagementType.CONTAINER; import javax.ejb.Lock; import javax.ejb.LockType.WRITE; @Singleton @ConcurrencyManagement(CONTAINER) public class CounterBean { private int hits = 1; // Increment and return the number of hits @Lock(WRITE) public int getHits() { return hits++; } } The client: Output:
  • 30. 30 | P a g e