Esempio n. 1
0
  protected void executeAsyncWrite(
      final AtmosphereResource<?, ?> resource, final Object msg, final BroadcasterFuture future) {
    if (resource.getAtmosphereResourceEvent().isCancelled()) {
      return;
    }

    final AtmosphereResourceEvent event = resource.getAtmosphereResourceEvent();
    event.setMessage(msg);

    try {
      if (resource.getAtmosphereResourceEvent() != null
          && !resource.getAtmosphereResourceEvent().isCancelled()
          && HttpServletRequest.class.isAssignableFrom(resource.getRequest().getClass())) {
        HttpServletRequest.class
            .cast(resource.getRequest())
            .setAttribute(CometSupport.MAX_INACTIVE, System.currentTimeMillis());
      }
    } catch (Exception t) {
      // Shield us from any corrupted Request
      logger.debug("Preventing corruption of a recycled request: resource" + resource, event);
      removeAtmosphereResource(resource);
      BroadcasterFactory.getDefault().removeAllAtmosphereResource(resource);
      return;
    }

    broadcast(resource, event);
    if (resource instanceof AtmosphereEventLifecycle) {
      ((AtmosphereEventLifecycle) resource).notifyListeners();
    }

    if (future != null) {
      future.done();
    }
  }
Esempio n. 2
0
  protected Object perRequestFilter(AtmosphereResource<?, ?> r, Entry msg) {
    Object finalMsg = msg.message;

    if (AtmosphereResourceImpl.class.isAssignableFrom(r.getClass())) {
      if (AtmosphereResourceImpl.class.cast(r).isInScope()) {
        if (r.getRequest() instanceof HttpServletRequest && bc.hasPerRequestFilters()) {
          Object message = msg.originalMessage;
          BroadcastAction a =
              bc.filter(
                  (HttpServletRequest) r.getRequest(),
                  (HttpServletResponse) r.getResponse(),
                  message);
          if (a.action() == BroadcastAction.ACTION.ABORT || a.message() != msg.originalMessage) {
            finalMsg = a.message();
          }
        }
        trackBroadcastMessage(r, finalMsg);
      } else {
        // The resource is no longer valid.
        removeAtmosphereResource(r);
        BroadcasterFactory.getDefault().removeAllAtmosphereResource(r);
      }
    }
    return finalMsg;
  }