Package org.jboss.errai.bus.server.io

Examples of org.jboss.errai.bus.server.io.OutputStreamWriteAdapter


      return;
    }

    queue.heartBeat();

    final OutputStreamWriteAdapter writer;

    if (isSSERequest(request)) {
      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(getSSETimeout());
      queue.setTimeout(getSSETimeout() + 5000);
     
      final HttpServletResponse asynResponse = (HttpServletResponse) asyncContext.getResponse();
      prepareSSE(asynResponse);
      prepareSSEContinue(asynResponse);
      asynResponse.getOutputStream().flush();
      writer = new OutputStreamWriteAdapter(asynResponse.getOutputStream());

      asyncContext.addListener(new AsyncListener() {
        @Override
        public void onComplete(final AsyncEvent event) throws IOException {
          synchronized (queue.getActivationLock()) {
            queue.setActivationCallback(null);
            asyncContext.complete();
          }
        }

        @Override
        public void onTimeout(final AsyncEvent event) throws IOException {
          onComplete(event);
        }

        @Override
        public void onError(final AsyncEvent event) throws IOException {
          queue.setActivationCallback(null);
        }

        @Override
        public void onStartAsync(final AsyncEvent event) throws IOException {
        }
      });

      synchronized (queue.getActivationLock()) {
        if (queue.messagesWaiting()) {
          queue.poll(writer);
          writer.write(SSE_TERMINATION_BYTES);
          writer.flush();
          return;
        }

        queue.setActivationCallback(new QueueActivationCallback() {
          @Override
          public void activate(final MessageQueue queue) {
            try {
              queue.poll(writer);

              writer.write(SSE_TERMINATION_BYTES);

              queue.heartBeat();
              writer.flush();

              prepareSSEContinue(asynResponse);
            }
            catch (IOException e) {
              log.debug("Closing queue with id: " + queue.getSession().getSessionId() + " due to IOException", e);
              queue.stopQueue();
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (Throwable t2) {
                log.debug("Failed to write exception to dead client", t2);
              }
            }
          }
        });
      }
    }

    else {
      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(60000);
      queue.setTimeout(65000);
      writer = new OutputStreamWriteAdapter(asyncContext.getResponse().getOutputStream());

      asyncContext.addListener(new AsyncListener() {
          @Override
          public void onComplete(final AsyncEvent event) throws IOException {
            synchronized (queue.getActivationLock()) {
              queue.setActivationCallback(null);
              asyncContext.complete();
            }
          }

          @Override
          public void onTimeout(final AsyncEvent event) throws IOException {
            onComplete(event);
          }

          @Override
          public void onError(final AsyncEvent event) throws IOException {
            queue.setActivationCallback(null);
          }

          @Override
          public void onStartAsync(final AsyncEvent event) throws IOException {
          }
        });

      synchronized (queue.getActivationLock()) {
        if (queue.messagesWaiting()) {
          queue.poll(writer);
          asyncContext.complete();
          return;
        }

        queue.setActivationCallback(new QueueActivationCallback() {
          @Override
          public void activate(final MessageQueue queue) {
            try {
              queue.poll(writer);
              queue.setActivationCallback(null);

              queue.heartBeat();
              writer.flush();
            }
            catch (IOException e) {
              log.debug("Closing queue with id: " + queue.getSession().getSessionId() + " due to IOException", e);
             
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (Throwable t2) {
                log.debug("Failed to write exception to dead client", t2);
              }
            }
            finally {
              asyncContext.complete();
            }
          }
        });
        writer.flush();
      }
    }
  }
View Full Code Here


      if (queue != null) {
        if (shouldWait(request)) {
          doGet(request, response);
        }
        else {
          queue.poll(new OutputStreamWriteAdapter(response.getOutputStream()));
        }
      }
    }
    catch (Exception e) {
      final String message = e.getMessage();
View Full Code Here

      if (sse) {
        final long timeout = System.currentTimeMillis() + getSSETimeout();
        while (System.currentTimeMillis() < timeout) {
          prepareSSEContinue(httpServletResponse);
          outputStream.flush();
          queue.poll(TimeUnit.MILLISECONDS, getSSETimeout(), new OutputStreamWriteAdapter(outputStream));
          outputStream.write(SSE_TERMINATION_BYTES);
          queue.heartBeat();
        }
      }
      else if (wait) {
        queue.poll(TimeUnit.MILLISECONDS, getLongPollTimeout(), new OutputStreamWriteAdapter(outputStream));
      }
      else {
        queue.poll(new OutputStreamWriteAdapter(outputStream));
      }

      outputStream.close();
    }
    catch (final Throwable t) {
View Full Code Here

      return;
    }

    queue.heartBeat();

    final OutputStreamWriteAdapter writer = new OutputStreamWriteAdapter(response.getOutputStream());

    if (isSSERequest(request)) {
      prepareSSE(response);
      prepareSSEContinue(response);

      response.getOutputStream().flush();

      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(getSSETimeout());
      queue.setTimeout(getSSETimeout() + 5000);

      asyncContext.addListener(new AsyncListener() {
        @Override
        public void onComplete(final AsyncEvent event) throws IOException {
          synchronized (queue.getActivationLock()) {
            queue.setActivationCallback(null);
            asyncContext.complete();
          }
        }

        @Override
        public void onTimeout(final AsyncEvent event) throws IOException {
          onComplete(event);
        }

        @Override
        public void onError(final AsyncEvent event) throws IOException {
          queue.setActivationCallback(null);
        }

        @Override
        public void onStartAsync(final AsyncEvent event) throws IOException {
        }
      });

      synchronized (queue.getActivationLock()) {
        if (queue.messagesWaiting()) {
          queue.poll(writer);
          writer.write(SSE_TERMINATION_BYTES);
        }

        queue.setActivationCallback(new QueueActivationCallback() {
          @Override
          public void activate(final MessageQueue queue) {
            try {
              queue.setActivationCallback(null);
              queue.poll(writer);

              writer.write(SSE_TERMINATION_BYTES);

              queue.heartBeat();
              writer.flush();

              prepareSSEContinue(response);
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (IOException e) {
                throw new RuntimeException("Failed to write exception to output stream", e);
              }
            }
          }
        });

        writer.flush();
      }
    }

    else {
      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(60000);
      queue.setTimeout(65000);

      asyncContext.addListener(new AsyncListener() {
          @Override
          public void onComplete(final AsyncEvent event) throws IOException {
            synchronized (queue.getActivationLock()) {
              queue.setActivationCallback(null);
              asyncContext.complete();
            }
          }

          @Override
          public void onTimeout(final AsyncEvent event) throws IOException {
            onComplete(event);
          }

          @Override
          public void onError(final AsyncEvent event) throws IOException {
            queue.setActivationCallback(null);
          }

          @Override
          public void onStartAsync(final AsyncEvent event) throws IOException {
          }
        });

      synchronized (queue.getActivationLock()) {
        if (queue.messagesWaiting()) {
          queue.poll(writer);
          asyncContext.complete();
          return;
        }

        queue.setActivationCallback(new QueueActivationCallback() {
          @Override
          public void activate(final MessageQueue queue) {
            try {
              queue.poll(writer);
              queue.setActivationCallback(null);

              queue.heartBeat();
              writer.flush();
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (IOException e) {
                throw new RuntimeException("Failed to write exception to output stream", e);
              }
            }
            finally {
              asyncContext.complete();
            }
          }
        });
        writer.flush();
      }
    }
  }
View Full Code Here

      if (queue != null) {
        if (shouldWait(request)) {
          doGet(request, response);
        }
        else {
          queue.poll(new OutputStreamWriteAdapter(response.getOutputStream()));
        }
      }
    }
    catch (Exception e) {
      final String message = e.getMessage();
View Full Code Here

      queue.heartBeat();

      if (sse) {
        while (!queue.isStale()) {
          prepareSSEContinue(httpServletResponse);
          queue.poll(TimeUnit.MILLISECONDS, getSSETimeout(), new OutputStreamWriteAdapter(outputStream));
          outputStream.write(SSE_TERMINATION_BYTES);
          outputStream.flush();
          queue.heartBeat();
        }
      }
      else if (wait) {
        queue.poll(TimeUnit.MILLISECONDS, getLongPollTimeout(), new OutputStreamWriteAdapter(outputStream));
        outputStream.close();
      }
      else {
        queue.poll(new OutputStreamWriteAdapter(outputStream));
        outputStream.close();
      }
    }
    catch (final Throwable t) {
      writeExceptionToOutputStream(httpServletResponse, t);
View Full Code Here

      return;
    }

    queue.heartBeat();

    final OutputStreamWriteAdapter writer;
    final AsyncContext asyncContext = request.startAsync();
    asyncContext.setTimeout(60000);
    queue.setTimeout(65000);
    writer = new OutputStreamWriteAdapter(asyncContext.getResponse().getOutputStream());

    asyncContext.addListener(new AsyncListener() {
        @Override
        public void onComplete(final AsyncEvent event) throws IOException {
          synchronized (queue.getActivationLock()) {
            queue.setActivationCallback(null);
            asyncContext.complete();
          }
        }

        @Override
        public void onTimeout(final AsyncEvent event) throws IOException {
          onComplete(event);
        }

        @Override
        public void onError(final AsyncEvent event) throws IOException {
          queue.setActivationCallback(null);
        }

        @Override
        public void onStartAsync(final AsyncEvent event) throws IOException {
        }
      });

    synchronized (queue.getActivationLock()) {
      if (queue.messagesWaiting()) {
        queue.poll(writer);
        asyncContext.complete();
        return;
      }

      queue.setActivationCallback(new QueueActivationCallback() {
        @Override
        public void activate(final MessageQueue queue) {
          try {
            queue.poll(writer);
            queue.setActivationCallback(null);

            queue.heartBeat();
            writer.flush();
          }
          catch (IOException e) {
            log.debug("Closing queue with id: " + queue.getSession().getSessionId() + " due to IOException", e);
           
          }
          catch (final Throwable t) {
            try {
              writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
            }
            catch (Throwable t2) {
              log.debug("Failed to write exception to dead client", t2);
            }
          }
          finally {
            asyncContext.complete();
          }
        }
      });
      writer.flush();
    }
  }
View Full Code Here

      if (queue != null) {
        if (shouldWait(request)) {
          doGet(request, response);
        }
        else {
          queue.poll(new OutputStreamWriteAdapter(response.getOutputStream()));
        }
      }
    }
    catch (Exception e) {
      final String message = e.getMessage();
View Full Code Here

    httpServletResponse.setHeader("Cache-Control", "no-cache");
    httpServletResponse.setHeader("Pragma", "no-cache");
    httpServletResponse.setHeader("Expires", "-1");
    httpServletResponse.setContentType("application/json");
    return queue.poll(new OutputStreamWriteAdapter(stream));
  }
View Full Code Here

      final ServletOutputStream outputStream = httpServletResponse.getOutputStream();
      if (sse) {
        while (!queue.isStale()) {
          try {
            prepareSSEContinue(httpServletResponse);
            queue.poll(TimeUnit.MILLISECONDS, getSSETimeout(), new OutputStreamWriteAdapter(outputStream));
            outputStream.write(SSE_TERMINATION_BYTES);
            outputStream.flush();
            queue.heartBeat();
          }
          catch (IOException e) {
            log.debug("SSE problem when polling for new messages", e);
            outputStream.close();
            return;
          }
        }
      }
      else if (wait) {
        queue.poll(TimeUnit.MILLISECONDS, getLongPollTimeout(), new OutputStreamWriteAdapter(outputStream));
      }
      else {
        queue.poll(new OutputStreamWriteAdapter(outputStream));
      }
    }
    catch (final IOException io) {
      log.debug("Problem when polling for new messages", io);
    }
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.server.io.OutputStreamWriteAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.