public Subscription replaceResource(int index, Subscription resource) {
        for (;;) {
            Subscription o = get(index);
            if (o == SubscriptionHelper.CANCELLED) {
                if (resource != null) {
                    resource.cancel();
                }
                return null;
            }
            if (compareAndSet(index, o, resource)) {
                return o;
            }
        }
    }
public Subscription replaceResource(int index, Subscription resource) {
        for (;;) {
            Subscription o = get(index);
            if (o == SubscriptionHelper.CANCELLED) {
                if (resource != null) {
                    resource.cancel();
                }
                return null;
            }
            if (compareAndSet(index, o, resource)) {
                return o;
            }
        }
    }
public Subscription replaceResource ( int index , Subscription resource ) { for ( ; ; ) { Subscription o = get ( index ) ; if ( o == SubscriptionHelper . CANCELLED ) { if ( resource != null ) { resource . cancel ( ) ; } return null ; } if ( compareAndSet ( index , o , resource ) ) { return o ; } } }
Replaces the resource at the specified index and returns the old resource.
@param index the index of the resource to replace
@param resource the new resource
@return the old resource, can be null
Replaces the resource at the specified index and returns the old resource .