Exemplo 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();
    }
  }
Exemplo n.º 2
0
  protected void onException(Throwable t, final AtmosphereResource<?, ?> r) {
    logger.debug("onException()", t);

    if (r instanceof AtmosphereEventLifecycle) {
      ((AtmosphereEventLifecycle) r)
          .notifyListeners(
              new AtmosphereResourceEventImpl((AtmosphereResourceImpl) r, true, false, t));
      ((AtmosphereEventLifecycle) r).removeEventListeners();
    }

    /** Make sure we resume the connection on every IOException. */
    bc.getAsyncWriteService()
        .execute(
            new Runnable() {
              @Override
              public void run() {
                r.resume();
              }
            });
  }