Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public AtmosphereResource<?, ?> removeAtmosphereResource(AtmosphereResource r) {

    if (destroyed.get())
      throw new IllegalStateException("This Broadcaster has been destroyed and cannot be used");

    if (!resources.contains(r)) {
      return null;
    }
    resources.remove(r);

    // Will help preventing OOM.
    if (resources.isEmpty()) {
      notifyEmptyListener();
      if (lifeCyclePolicy.getLifeCyclePolicy()
          == BroadcasterLifeCyclePolicy.ATMOSPHERE_RESOURCE_POLICY.EMPTY) {
        releaseExternalResources();
      } else if (lifeCyclePolicy.getLifeCyclePolicy()
          == BroadcasterLifeCyclePolicy.ATMOSPHERE_RESOURCE_POLICY.EMPTY_DESTROY) {
        notifyDestroyListener();
        BroadcasterFactory.getDefault().remove(this, name);
        destroy();
      }
    }
    return r;
  }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  public void destroy() {
    started.set(false);
    destroyed.set(true);
    releaseExternalResources();
    if (notifierFuture != null) {
      notifierFuture.cancel(true);
    }

    if (asyncWriteFuture != null) {
      asyncWriteFuture.cancel(true);
    }

    if (bc != null) {
      bc.destroy();
    }

    if (broadcasterCache != null) {
      broadcasterCache.stop();
    }
    resources.clear();
    broadcastOnResume.clear();
    messages.clear();
    asyncWriteQueue.clear();
    delayedBroadcast.clear();
    broadcasterCache = null;

    if (BroadcasterFactory.getDefault() != null) {
      BroadcasterFactory.getDefault().remove(this, name);
    }

    if (currentLifecycleTask != null) {
      currentLifecycleTask.cancel(true);
    }
  }