Example #1
0
    @Override
    public Subscription call(Observer<T> observer) {
      if (started.compareAndSet(false, true)) {
        AtomicObservableSubscription subscription = new AtomicObservableSubscription();
        this.observer = new SynchronizedObserver<T>(observer, subscription);
        /* start the Observers */
        for (ZipObserver<T, ?> rw : observers) {
          rw.startWatching();
        }

        return subscription.wrap(
            new Subscription() {

              @Override
              public void unsubscribe() {
                stop();
              }
            });
      } else {
        /* a Observer already has subscribed so blow up */
        throw new IllegalStateException("Only one Observer can subscribe to this Observable.");
      }
    }
Example #2
0
 public void startWatching() {
   if (subscribed.compareAndSet(false, true)) {
     // only subscribe once even if called more than once
     subscription.wrap(w.subscribe(this));
   }
 }