Example usage for javax.servlet ReadListener onDataAvailable

List of usage examples for javax.servlet ReadListener onDataAvailable

Introduction

In this page you can find the example usage for javax.servlet ReadListener onDataAvailable.

Prototype

public void onDataAvailable() throws IOException;

Source Link

Document

When an instance of the ReadListener is registered with a ServletInputStream , this method will be invoked by the container the first time when it is possible to read 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  w w w.java2 s  . c om*/
    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();

}