Java Reference
In-Depth Information
true
, calls to
SessionContext.wasCancelled
by the session bean instance will
return
true
. If
mayInterruptIfRunning
is to set
false
, calls to
SessionCon-
text.wasCancelled
by the session bean instance will return
false
.
The
Future<V>.isCancelled
method is used to check whether the method invoca-
tion was cancelled before the asynchronous method invocation completed by calling
Fu-
ture<V>.cancel
. The
isCancelled
method returns
true
if the invocation was
cancelled.
Checking the Status of an Asynchronous Method Invocation
The
Future<V>.isDone
method returns
true
if the session bean instance completed
processing the method invocation. The
isDone
method returns
true
if the asynchron-
ous method invocation completed normally, was cancelled, or resulted in an exception.
That is,
isDone
indicates only whether the session bean has completed processing the
invocation.
The
async
Example Application
The
async
example demonstrates how to define an asynchronous business method on
a session bean and call it from a web client. The
MailerBean
stateless session bean
defines an asynchronous method,
sendMessage
, which uses the JavaMail API to send
an email to a specified email address.
Note
This example needs to be configured for your environment before it
runs correctly, and requires access to an SMTPS server.
Architecture of the
async
Example Application
The
async
application consists of a single stateless session bean,
MailerBean
, and a
JavaServer Faces web application front end that uses Facelets tags in XHTML files to dis-
play a form for users to enter the email address for the recipient of an email. The status of
the email is updated when the email is finally sent.
The
MailerBean
session bean injects a JavaMail resource used to send an email mes-
sage to an address specified by the user. The message is created, modified, and sent us-
ing the JavaMail API. The injected JavaMail resource is configured through the GlassFish
Server Administration Console, or through a resource configuration file packaged with
the application. The resource configuration can be modified at runtime by the GlassFish
Server administrator to use a different mail server or transport protocol.