Esempio n. 1
0
  /** {@inheritDoc} */
  @SuppressWarnings({"unchecked"})
  @Override
  public void listenAsync(@Nullable final GridInClosure<? super GridFuture<R>> lsnr) {
    if (lsnr != null) {
      checkValid();

      boolean done;

      synchronized (mux) {
        done = this.done;

        if (!done) lsnrs.add(lsnr);
      }

      if (done) {
        try {
          if (syncNotify) notifyListener(lsnr);
          else
            ctx.closure()
                .runLocalSafe(
                    new GPR() {
                      @Override
                      public void run() {
                        notifyListener(lsnr);
                      }
                    },
                    true);
        } catch (IllegalStateException ignore) {
          U.warn(
              null,
              "Future notification will not proceed because grid is stopped: " + ctx.gridName());
        }
      }
    }
  }
Esempio n. 2
0
  /** Notifies all registered listeners. */
  private void notifyListeners() {
    final Collection<GridInClosure<? super GridFuture<R>>> tmp;

    synchronized (mux) {
      tmp = new ArrayList<GridInClosure<? super GridFuture<R>>>(lsnrs);
    }

    boolean concurNotify = this.concurNotify;
    boolean syncNotify = this.syncNotify;

    if (concurNotify) {
      for (final GridInClosure<? super GridFuture<R>> lsnr : tmp)
        ctx.closure()
            .runLocalSafe(
                new GPR() {
                  @Override
                  public void run() {
                    notifyListener(lsnr);
                  }
                },
                true);
    } else {
      // Always notify in the thread different from start thread.
      if (Thread.currentThread() == thread && !syncNotify) {
        ctx.closure()
            .runLocalSafe(
                new GPR() {
                  @Override
                  public void run() {
                    // Since concurrent notifications are off, we notify
                    // all listeners in one thread.
                    for (GridInClosure<? super GridFuture<R>> lsnr : tmp) notifyListener(lsnr);
                  }
                },
                true);
      } else {
        for (GridInClosure<? super GridFuture<R>> lsnr : tmp) notifyListener(lsnr);
      }
    }
  }