|
EJB 3.0 |
|
• In this tutorial, you will learn how a
stateless EJB application is developed
using an Application Server Jboss 4.2.0.
So lets first see the life cycle of a
Stateless Session Bean.
Life Cycle of a Stateless Session Bean:
Since the Stateless session bean does not
passivates across method calls therefore a
stateless session bean includes only two
stages. Whether it does not exist or ready for
method invocation. A stateless session bean
starts its life cycle when the client first obtains
the reference of the session bean. For this,
the container performs the dependency
injection before invoking the annotated
@PreConstruct method if any exists. After
invoking the annotated @PreConstruct
method the bean will be ready to invoke its
method by the client.
The above figure demonstrates how the
Stateless Session Beans are created and
destroyed.
The container calls the annotated @PreDestroy
method while ending the life cycle of the session
bean. After this, the bean is ready for garbage
collection.
In this tutorial, we are going to develop a
Stateless Session Bean Application named
example. The purpose of example is to
perform the mathematical operations such as
Addition, Subtraction, Multiplication, and
Division.
|
|
The example application consists of an
enterprise bean, which performs the
calculations, and a web client.
There are following steps that you have to follow
to develop a calculator JEE application.
1. Create the enterprise bean: CalculatorBean
2. Create web clients: index.jsp,
form.jsp, WebClient.jsp
3. Deploy example onto the server.
4. Using a browser, run the web client.
1.Creating the enterprise bean:
The enterprise bean in our example is a stateless
session bean called CalculatorBean. The
source code for CalculatorBean is in “com.javajazz/examples/ejb3/stateless”
directory.
Creating CalculatorBean requires these steps:
1) Coding the bean’s Remote business
interface and Enterprise bean class.
2) Compiling the source code with the Ant
tool.
(i) Coding the Business Interface
The business interface defines the business
methods that a client can call remotely. The
business methods are implemented in the
enterprise bean class. The source code for the
CalculatorRemote business interface is given
below.
package
com.javajazzup.examples.ejb3.stateless;
import java.math.*;
import javax.ejb.Remote;
import java.lang.annotation.*;
@Remote
public interface CalculatorRemote {
public float add(float x, float y);
public float subtract(float x, float y);
public float multiply(float x, float y);
public float division(float x, float y);
} |
|
|
Jan 2008 | Java Jazz Up | 17 |
|
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 ,
70 ,
71 ,
72 ,
73 ,
74 ,
75 ,
76 ,
77 ,
78 ,
79 ,
80 ,
81 ,
82 ,
83,
84 ,
85 ,
86,
87 ,
88,
89 ,
90 ,
91 ,
92 ,
93 ,
94 ,
95 ,
96 ,
97 ,
98 ,
99 ,
100 ,
101 ,
102 ,
103,
104 ,
105 ,
106,
107,
Download PDF |
|
|
|
|
|
|
|
|
|