Example usage for javax.servlet WriteListener onWritePossible

List of usage examples for javax.servlet WriteListener onWritePossible

Introduction

In this page you can find the example usage for javax.servlet WriteListener onWritePossible.

Prototype

public void onWritePossible() throws IOException;

Source Link

Document

When an instance of the WriteListener is registered with a ServletOutputStream , this method will be invoked by the container the first time when it is possible to write data.

Usage

From source file:com.kolich.curacao.examples.controllers.NonBlockingIOExampleController.java

@PUT("/api/nonblocking")
public final void nonblocking(final AsyncContext context, final HttpServletRequest request,
        final HttpServletResponse response, final ServletInputStream input, final ServletOutputStream output)
        throws Exception {

    final Queue<Option<String>> queue = new ConcurrentLinkedQueue<Option<String>>();

    final WriteListener writer = new StupidWriteListener(context, queue, output);

    final ReadListener reader = new StupidReadListener(queue, input, output, writer,
            request.getContentLength());

    // Producer//from ww  w .  j a va2 s.  co m
    input.setReadListener(reader);
    logger__.info("Tomcat, is input ready?: " + input.isReady());
    reader.onDataAvailable();

    // Consumer
    output.setWriteListener(writer);
    logger__.info("Tomcat, is input ready?: " + output.isReady());
    writer.onWritePossible();

}