class ArrayCompositeDisposable extends AtomicReferenceArray<Disposable> implements Disposable {

    public Disposable replaceResource(int index, Disposable resource) {
        for (;;) {
            Disposable o = get(index);
            if (o == DisposableHelper.DISPOSED) {
                resource.dispose();
                return null;
            }
            if (compareAndSet(index, o, resource)) {
                return o;
            }
        }
    }

    public  ArrayCompositeDisposable(int capacity);

}