Java Reference
In-Depth Information
right, the EJB container (server) makes code that uses your interfaces, along
with its own code, to do the infrastructure work of EJBs.
Talking about all these pieces of an EJB can be confusing, too. Sometimes
it is helpful to think of an EJB as a single class; sometimes it's better to think
of it as a family of classes that act together pretending to be a single bean that
is distributed across several hosts. This can make it a bit confusing when talking
about an EJB—do we mean the family of interacting classes or do we mean the
single class that provides the application functionality that we want?
The names of EJB classes and EJB interfaces (which we will extend and
implement) don't help much either—they can be confusing, too. For example,
we will extend EJBObject , but not to write an EJB session bean; no, we extend
SessionBean for that, but EJBObject is the name for the remote interface.
Go figure.
A bit of perspective may help here. The names Remote , Local , and Home
are used as modifiers on these classes. Local means “on the same host as the
bean.” But Home and Remote don't offer much of a clue. The home interface
is what we get from a lookup; it produces remote objects (objects which imple-
ment the remote interface). A remote object is what our application uses as if
it were a Java object doing what we need, even though its application-specific
activity will happen on a bean somewhere else on the network.
Let's look at a very very simple example, to see the pieces in action.
SessionBean
22.2.1
Let's write a stateless session bean that will compute the time value of money.
Why that? Well, two reasons. First, we already have an SAMoney class with a
save() method for computing some values; and second, we need some simple,
stateless, but somewhat computationally intensive task to make for a halfway
reasonable example.
The real guts of an EJB, the core of the application functionality—in our
example, the computation of the time value of money—is the session (or entity)
bean. For our session bean we begin by implementing the SessionBean
interface, which means that we need to define these methods:
public void setSessionContext(SessionContext context) { }
public void ejbCreate() { }
public void ejbRemove() { }
public void ejbActivate() { }
public void ejbPassivate() { }
Search WWH ::




Custom Search