test_class.file: rxjava/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java
test_class.identifier: ObservablePublishTest
test_case.body: @Test
      public void disposedUpfront() {
          ConnectableObservable<Integer> co = Observable.just(1)
                  .concatWith(Observable.<Integer>never())
                  .publish();
  
          TestObserver<Integer> to1 = co.test();
  
          TestObserver<Integer> to2 = co.test(true);
  
          co.connect();
  
          to1.assertValuesOnly(1);
  
          to2.assertEmpty();
  
          ((ObservablePublish<Integer>)co).current.get().remove(null);
      }
test_case.class_method_signature: ObservablePublishTest.disposedUpfront()
test_case.full_signature: @Test public void disposedUpfront()
test_case.identifier: disposedUpfront
test_case.invocations: publish concatWith just never test test connect assertValuesOnly assertEmpty remove get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void disposedUpfront()
focal_class.declarator: source
focal_class.modifier: final
focal_class.original_string: final ObservableSource<T> source;
focal_class.type: ObservableSource<T>
focal_class.var_name: source
focal_class.declarator: current
focal_class.modifier: final
focal_class.original_string: final AtomicReference<PublishObserver<T>> current;
focal_class.type: AtomicReference<PublishObserver<T>>
focal_class.var_name: current
focal_class.declarator: onSubscribe
focal_class.modifier: final
focal_class.original_string: final ObservableSource<T> onSubscribe;
focal_class.type: ObservableSource<T>
focal_class.var_name: onSubscribe
focal_class.file: rxjava/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java
focal_class.identifier: ObservablePublish
focal_class.interfaces: implements HasUpstreamObservableSource<T>
focal_class.class_method_signature: ObservablePublish.create(ObservableSource<T> source)
focal_class.full_signature: public static ConnectableObservable<T> create(ObservableSource<T> source)
focal_class.identifier: create
focal_class.modifiers: public static
focal_class.parameters: (ObservableSource<T> source)
focal_class.return: ConnectableObservable<T>
focal_class.signature: ConnectableObservable<T> create(ObservableSource<T> source)
focal_class.class_method_signature: ObservablePublish.ObservablePublish(ObservableSource<T> onSubscribe, ObservableSource<T> source,
                                final AtomicReference<PublishObserver<T>> current)
focal_class.full_signature: private  ObservablePublish(ObservableSource<T> onSubscribe, ObservableSource<T> source,
                                final AtomicReference<PublishObserver<T>> current)
focal_class.identifier: ObservablePublish
focal_class.modifiers: private
focal_class.parameters: (ObservableSource<T> onSubscribe, ObservableSource<T> source,
                                final AtomicReference<PublishObserver<T>> current)
focal_class.signature:  ObservablePublish(ObservableSource<T> onSubscribe, ObservableSource<T> source,
                                final AtomicReference<PublishObserver<T>> current)
focal_class.class_method_signature: ObservablePublish.source()
focal_class.full_signature: @Override public ObservableSource<T> source()
focal_class.identifier: source
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: ObservableSource<T>
focal_class.signature: ObservableSource<T> source()
focal_class.class_method_signature: ObservablePublish.subscribeActual(Observer<? super T> observer)
focal_class.full_signature: @Override protected void subscribeActual(Observer<? super T> observer)
focal_class.identifier: subscribeActual
focal_class.modifiers: @Override protected
focal_class.parameters: (Observer<? super T> observer)
focal_class.return: void
focal_class.signature: void subscribeActual(Observer<? super T> observer)
focal_class.class_method_signature: ObservablePublish.connect(Consumer<? super Disposable> connection)
focal_class.full_signature: @Override public void connect(Consumer<? super Disposable> connection)
focal_class.identifier: connect
focal_class.modifiers: @Override public
focal_class.parameters: (Consumer<? super Disposable> connection)
focal_class.return: void
focal_class.signature: void connect(Consumer<? super Disposable> connection)
focal_class.superclass: extends ConnectableObservable<T>
focal_method.body: @Override
      public void connect(Consumer<? super Disposable> connection) {
          boolean doConnect;
          PublishObserver<T> ps;
          // we loop because concurrent connect/disconnect and termination may change the state
          for (;;) {
              // retrieve the current subscriber-to-source instance
              ps = current.get();
              // if there is none yet or the current has been disposed
              if (ps == null || ps.isDisposed()) {
                  // create a new subscriber-to-source
                  PublishObserver<T> u = new PublishObserver<T>(current);
                  // try setting it as the current subscriber-to-source
                  if (!current.compareAndSet(ps, u)) {
                      // did not work, perhaps a new subscriber arrived
                      // and created a new subscriber-to-source as well, retry
                      continue;
                  }
                  ps = u;
              }
              // if connect() was called concurrently, only one of them should actually
              // connect to the source
              doConnect = !ps.shouldConnect.get() && ps.shouldConnect.compareAndSet(false, true);
              break; // NOPMD
          }
          /*
           * Notify the callback that we have a (new) connection which it can dispose
           * but since ps is unique to a connection, multiple calls to connect() will return the
           * same Disposable and even if there was a connect-disconnect-connect pair, the older
           * references won't disconnect the newer connection.
           * Synchronous source consumers have the opportunity to disconnect via dispose on the
           * Disposable as subscribe() may never return in its own.
           *
           * Note however, that asynchronously disconnecting a running source might leave
           * child observers without any terminal event; PublishSubject does not have this
           * issue because the dispose() was always triggered by the child observers
           * themselves.
           */
          try {
              connection.accept(ps);
          } catch (Throwable ex) {
              Exceptions.throwIfFatal(ex);
              throw ExceptionHelper.wrapOrThrow(ex);
          }
          if (doConnect) {
              source.subscribe(ps);
          }
      }
focal_method.class_method_signature: ObservablePublish.connect(Consumer<? super Disposable> connection)
focal_method.full_signature: @Override public void connect(Consumer<? super Disposable> connection)
focal_method.identifier: connect
focal_method.invocations: get isDisposed compareAndSet get compareAndSet accept throwIfFatal wrapOrThrow subscribe
focal_method.modifiers: @Override public
focal_method.parameters: (Consumer<? super Disposable> connection)
focal_method.return: void
focal_method.signature: void connect(Consumer<? super Disposable> connection)