1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16- package rx .internal . operators ;
16+ package rx .subjects ;
1717
1818import java .util .Queue ;
1919import java .util .concurrent .atomic .*;
2020
2121import rx .*;
22+ import rx .annotations .Experimental ;
2223import rx .exceptions .*;
23- import rx .functions .*;
24+ import rx .functions .Action0 ;
25+ import rx .internal .operators .*;
2426import rx .internal .util .atomic .*;
2527import rx .internal .util .unsafe .*;
26- import rx .subjects .Subject ;
27- import rx .subscriptions .Subscriptions ;
2828
2929/**
3030 * A Subject variant which buffers events until a single Subscriber arrives and replays them to it
3535 *
3636 * @param <T> the input and output value type
3737 */
38+ @ Experimental
3839public final class UnicastSubject <T > extends Subject <T , T > {
3940
4041 /**
@@ -111,7 +112,7 @@ public boolean hasObservers() {
111112 *
112113 * @param <T> the value type
113114 */
114- static final class State <T > extends AtomicLong implements Producer , Observer <T >, Action0 , OnSubscribe <T > {
115+ static final class State <T > extends AtomicLong implements Producer , Observer <T >, OnSubscribe <T >, Subscription {
115116 /** */
116117 private static final long serialVersionUID = -9044104859202255786L ;
117118 /** The single subscriber. */
@@ -250,7 +251,7 @@ public void request(long n) {
250251 @ Override
251252 public void call (Subscriber <? super T > subscriber ) {
252253 if (this .subscriber .compareAndSet (null , subscriber )) {
253- subscriber .add (Subscriptions . create ( this ) );
254+ subscriber .add (this );
254255 subscriber .setProducer (this );
255256 } else {
256257 subscriber .onError (new IllegalStateException ("Only a single subscriber is allowed" ));
@@ -326,7 +327,7 @@ void replay() {
326327 * Should be called only when the child unsubscribes
327328 */
328329 @ Override
329- public void call () {
330+ public void unsubscribe () {
330331
331332 doTerminate ();
332333
@@ -339,6 +340,12 @@ public void call() {
339340 }
340341 queue .clear ();
341342 }
343+
344+ @ Override
345+ public boolean isUnsubscribed () {
346+ return done ;
347+ }
348+
342349 /**
343350 * Checks if one of the terminal conditions have been met: child unsubscribed,
344351 * an error happened or the source terminated and the queue is empty
0 commit comments