Java Reference
In-Depth Information
public class WriteListenerImpl implements WriteListener {
ServletOutputStream os;
AsyncContext context;
public WriteListenerImpl(ServletOutputStream out, AsyncContext ctx){
this.os = out;
this.context = ctx;
System.out.println("Write Listener Initialized");
public void onWritePossible() {
System.out.println("Now possible to write...");
// Write implementation goes here...
public void onError(Throwable thrwbl) {
System.out.println("Error occurred");
In most cases, the ReadListener and WriteListener implementation classes can be embedded within the calling
servlet. they have been broken out into separate classes for the examples in this topic for demonstration purposes.
The new Non-Blocking I/O API helps bring the Servlet API into compliance with new web standards. The new
API makes it possible to create web-based applications that perform in an asynchronous fashion, making it possible
to handle a larger number of requests.
Upgrade Protocol
An HTTP response protocol can now be upgraded from HTTP 1.1 to some other protocol via a new protocol
upgrade API. Typically this is used for upgrading to WebSocket for more advanced communication. All protocol
processing takes place in a servlet named HttpUpgradeHandler , and although the servlet container is responsible for
performing the upgrade, the servlet code needs to invoke the process. An HttpServletResponse can be upgraded
by invoking its upgrade method, and when this occurs, the appropriate HttpUpgradeHandler for the requested
protocol is instantiated. Upon instantiation, the HttpUpgradeHandler.init method is invoked, which passes a
WebConnection to allow the protocol handler to access the data streams. If servlet filters are used before and during
the upgrade process, they will continue to process normally, and after the upgrade has been completed, then all
servlet filters will stop performing operations. Finally, the HttpUpgradeHandler.destroy method is invoked once the
upgrade processing is complete.
Search WWH ::

Custom Search