Exemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 public void action(AtmosphereResourceImpl r) {
   super.action(r);
   if (r.isResumed() && r.getRequest().getAttribute(ASYNCHRONOUS_HOOK) != null) {
     if (r.getRequest().getAttribute(CHANNEL) == null) return;
     try {
       ((AsyncIOWriter) r.getRequest().getAttribute(CHANNEL)).close();
     } catch (IOException e) {
       logger.trace("", e);
     }
   }
 }
  void invokeAtmosphereHandler(AtmosphereResourceImpl r) throws IOException {
    if (!r.isInScope()) return;

    AtmosphereRequest req = r.getRequest(false);
    String disableOnEvent =
        r.getAtmosphereConfig().getInitParameter(ApplicationConfig.DISABLE_ONSTATE_EVENT);

    try {
      if (disableOnEvent == null || !disableOnEvent.equals(String.valueOf(true))) {
        AtmosphereHandler atmosphereHandler =
            (AtmosphereHandler) req.getAttribute(FrameworkConfig.ATMOSPHERE_HANDLER);

        synchronized (r) {
          atmosphereHandler.onStateChange(r.getAtmosphereResourceEvent());

          Meteor m = (Meteor) req.getAttribute(AtmosphereResourceImpl.METEOR);
          if (m != null) {
            m.destroy();
          }
        }
        req.removeAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
      }
    } catch (IOException ex) {
      try {
        r.onThrowable(ex);
      } catch (Throwable t) {
        logger.warn("failed calling onThrowable()", ex);
      }
    }
  }
Exemplo n.º 3
0
 @Override
 public void action(AtmosphereResourceImpl r) {
   super.action(r);
   if (r.action().type() == Action.TYPE.RESUME && r.isInScope()) {
     HttpEvent event = (HttpEvent) r.getRequest(false).getAttribute(HTTP_EVENT);
     if (event != null && !r.transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET)) {
       close(event);
     }
   }
 }
 public void timedOut() {
   try {
     ((AsynchronousProcessor) r.cometSupport)
         .timedout(r.getRequest(false), r.getResponse(false));
   } catch (IOException e) {
     logger.debug("", e);
   } catch (ServletException e) {
     logger.debug("", e);
   }
 }
 public void closed() {
   try {
     ((AsynchronousProcessor) r.cometSupport)
         .cancelled(r.getRequest(false), r.getResponse(false));
   } catch (IOException e) {
     logger.debug("", e);
   } catch (ServletException e) {
     logger.debug("", e);
   }
 }
Exemplo n.º 6
0
  /** {@inheritDoc} */
  @Override
  public void action(AtmosphereResourceImpl resource) {
    super.action(resource);
    if (resource.action().type() == Action.TYPE.RESUME && resource.isInScope()) {
      try {
        CometEvent event = (CometEvent) resource.getRequest().getAttribute(COMET_EVENT);
        if (event == null) return;

        // Resume without closing the underlying suspended connection.
        if (config.getInitParameter(ApplicationConfig.RESUME_AND_KEEPALIVE) == null
            || config
                .getInitParameter(ApplicationConfig.RESUME_AND_KEEPALIVE)
                .equalsIgnoreCase("false")) {
          bz51881(event);
        }
      } catch (IOException ex) {
        logger.debug("action failed", ex);
      }
    }
  }
Exemplo n.º 7
0
 @Override
 public AsyncSupport complete(AtmosphereResourceImpl r) {
   final HttpEvent event = (HttpEvent) r.getRequest(false).getAttribute(HTTP_EVENT);
   // Prevent Deadlock
   // https://github.com/Atmosphere/atmosphere/issues/1782
   if (event != null) {
     if (!r.isResumed()) {
       ExecutorsFactory.getScheduler(config)
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   close(event);
                 }
               },
               500,
               TimeUnit.MILLISECONDS);
     } else {
       close(event);
     }
   }
   return this;
 }
  /** {@inheritDoc} */
  @Override
  public void action(AtmosphereResourceImpl r) {
    try {
      super.action(r);
      if (r.action().type() == Action.TYPE.RESUME) {
        AtmosphereRequest req = r.getRequest(false);
        CountDownLatch latch = null;

        if (req.getAttribute(LATCH) != null) {
          latch = (CountDownLatch) req.getAttribute(LATCH);
        }

        String s = config.getInitParameter(ApplicationConfig.RESUME_AND_KEEPALIVE);
        if (latch != null && (s == null || s.equalsIgnoreCase("false"))) {
          latch.countDown();
        } else if (req.getAttribute(AtmosphereResourceImpl.PRE_SUSPEND) == null) {
          logger.trace("Unable to resume the suspended connection");
        }
      }
    } catch (Exception ex) {
      logger.error("", ex);
    }
  }
Exemplo n.º 9
0
  @Override
  public Action inspect(final AtmosphereResource ar) {
    final AtmosphereResourceImpl r = AtmosphereResourceImpl.class.cast(ar);
    final AtmosphereRequest request = r.getRequest(false);
    final AtmosphereResponse response = r.getResponse(false);

    String uuid = request.getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID);
    String handshakeUUID = request.getHeader(HeaderConfig.X_ATMO_PROTOCOL);
    if (uuid != null && uuid.equals("0") && handshakeUUID != null) {
      request.header(HeaderConfig.X_ATMO_PROTOCOL, null);
      // Since 1.0.10

      final StringBuffer message =
          new StringBuffer(r.uuid()).append(wsDelimiter).append(System.currentTimeMillis());

      // https://github.com/Atmosphere/atmosphere/issues/993
      boolean track = false;
      if (r.getBroadcaster().getBroadcasterConfig().hasFilters()) {
        for (BroadcastFilter bf : r.getBroadcaster().getBroadcasterConfig().filters()) {
          if (TrackMessageSizeFilter.class.isAssignableFrom(bf.getClass())) {
            track = true;
            break;
          }
        }
      }

      final AtomicReference<String> protocolMessage =
          new AtomicReference<String>(message.toString());
      if (track) {
        protocolMessage.set(
            (String) f.filter(r, protocolMessage.get(), protocolMessage.get()).message());
      }

      if (!Utils.resumableTransport(r.transport())) {
        OnSuspend a =
            new OnSuspend() {
              @Override
              public void onSuspend(AtmosphereResourceEvent event) {
                response.write(protocolMessage.get());
                try {
                  response.flushBuffer();
                } catch (IOException e) {
                  logger.trace("", e);
                }
              }
            };
        // Pass the information to Servlet Based Framework
        request.setAttribute(CALLBACK_JAVASCRIPT_PROTOCOL, a);
        r.addEventListener(a);
      } else {
        response.write(protocolMessage.get());
      }

      // We don't need to reconnect here
      if (r.transport() == AtmosphereResource.TRANSPORT.WEBSOCKET
          || r.transport() == AtmosphereResource.TRANSPORT.STREAMING
          || r.transport() == AtmosphereResource.TRANSPORT.SSE) {
        return Action.CONTINUE;
      } else {
        return Action.SKIP_ATMOSPHEREHANDLER;
      }
    }
    return Action.CONTINUE;
  }
Exemplo n.º 10
0
 /** {@inheritDoc} */
 public void action(AtmosphereResourceImpl r) {
   if (trackActiveRequest) {
     aliveRequests.remove(r.getRequest(false));
   }
 }