in the business layer and wrap the
AsyncContext in a neutral wrapper. In the
open source project LightFish, the class
Browser Window is used to push GlassFish
monitoring data to the JavaFX 2 client,
as shown in Listing 6.
private AsyncContext asyncContext;
private final ServletResponse response;
private String channel;
JCA—If You Want More
Java EE Connector Architecture (JCA) 1. 6
connectors give you the most control
over concurrency in a “legal,” convenient,
and monitorable way. Furthermore, JCA
connectors are managed by the application server, which usually gives you many
configuration options. Building a JCA 1. 6
connector is not trivial, but it can be
achieved in a few hours.
The implementation of the
ResourceAdapter receives the
BootstrapContext in the overridden start
method, which gives you access to the
WorkManager instance. You can safely
ignore all other methods defined in the
ResourceAdapter interface (see Listing 7).
You only need to compile the class
shown in Listing 7, put it into a JAR
file, change the .jar extension to
.rar, and deploy the connector. The
application server would create the
WorkManagerBootstrap connector and
pass the BootstrapContext with which the
WorkManager instance can be obtained.
A WorkManager allows you to execute
javax.resource.spi.work. Work instances
that extend the Runnable interface. This
solution would work, but your applica-
tion would not be able to get a refer-
ence to the WorkManager without nasty
hacks. However, this implementation
would be sufficient to implement a
manageable network server.
public Browser Window(AsyncContext asyncContext) {
this.asyncContext = asyncContext;
this.response = this.asyncContext.getResponse();
this.response.setContentType("application/xml");
}
JAVA IN ACTION
public Browser Window(AsyncContext asyncContext,String channel){
this(asyncContext);
this.channel = channel;
}
public void send(){
try{
}
public Writer get Writer(){
try {
return this.asyncContext.getResponse().get Writer();
} catch (IOException ex) {
throw new IllegalStateException("Cannot return writer: " + ex,ex);
}
}
this.asyncContext.complete();
}catch(Exception e){ }
ABOUT US
public void nothing ToSay(){
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setStatus(204);
this.asyncContext.complete();
}
public String getChannel() {
return channel;
blog