當前位置: 首頁>>代碼示例>>Java>>正文


Java ReplaySubject.createWithSize方法代碼示例

本文整理匯總了Java中rx.subjects.ReplaySubject.createWithSize方法的典型用法代碼示例。如果您正苦於以下問題:Java ReplaySubject.createWithSize方法的具體用法?Java ReplaySubject.createWithSize怎麽用?Java ReplaySubject.createWithSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.subjects.ReplaySubject的用法示例。


在下文中一共展示了ReplaySubject.createWithSize方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: operatorUnbufferedObserveOn

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Test
public void operatorUnbufferedObserveOn() throws Exception {
    ReplaySubject<Integer> numbers = ReplaySubject.createWithSize(1);

    final AtomicInteger counter = new AtomicInteger();
    numbers.lift(new Rx.OperatorUnbufferedObserveOn<Integer>(Schedulers.immediate()))
            .subscribe(new Action1<Integer>() {
                @Override
                public void call(Integer number) {
                    counter.addAndGet(number);
                }
            });

    numbers.onNext(3);
    numbers.onNext(3);
    numbers.onNext(3);

    assertEquals(9, counter.get());
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:20,代碼來源:RxTests.java

示例2: build

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
/**
 * Builds and validates the structure of the expected header then
 * returns an {@link Observable} that can be used to submit info to the
 * {@link Network}
 * @return  a new Publisher
 */
public Publisher build() {
    subject = ReplaySubject.createWithSize(3);
    for(int i = 0;i < HEADER_SIZE;i++) {
        if(lines[i] == null) {
            throw new IllegalStateException("Header not properly formed (must contain 3 lines) see Header.java");
        }
        subject.onNext(lines[i]);
    }
    
    Publisher p = new Publisher();
    p.subject = subject;
    
    if(notifier != null) {
        notifier.accept(p);
    }
    
    return p;
}
 
開發者ID:numenta,項目名稱:htm.java,代碼行數:25,代碼來源:Publisher.java

示例3: write

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public Observable<Net.HttpResponse> write (ByteString data) {

    Buffer buffer = Buffer.buffer (data.toByteArray ());
      ReplaySubject<Net.HttpResponse> subject = ReplaySubject.createWithSize(1);

      request.handler (response ->  {

          if (!okStatuses.contains (response.statusCode ())) {
            throw new IllegalStateException (format("Unexpected statusCode %s and message %S",
              response.statusCode (), response.statusMessage ()));
          }

          response.bodyHandler (body -> {

            subject.onNext (
              new Net.HttpResponse () {

                @Override
                public BytesEvent data () {
                  return Codecs.BYTES.from (body.getBytes ());
                }

                @Override
                public int status () {
                  return response.statusCode ();
                }
            });
            subject.onCompleted ();
          });
        })
        .exceptionHandler ( ex -> subject.onError (ex))
        .putHeader ("Content-Length", String.valueOf (buffer.length ()))
        .end (buffer);

      return subject;
    }
 
開發者ID:sonyxperiadev,項目名稱:lumber-mill,代碼行數:37,代碼來源:VertxHttpRequestWrapper.java

示例4: getFeed

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
private RefreshableRemoteData<Feed> getFeed(String tag) {
    ReplaySubject<RemoteStatus> statusSubject = ReplaySubject.createWithSize(1);
    ReplaySubject<Feed> feedSubject = ReplaySubject.createWithSize(1);
    PublishSubject<Void> refresh = PublishSubject.create();
    refresh.observeOn(scheduler).forEach($ -> {
        CacheMode mode = CacheMode.DISABLE_CACHE;
        fetch(tag, feedSubject, statusSubject, mode);
    });
    fetch(tag, feedSubject, statusSubject, CacheMode.ENABLE_CACHE);
    return new RefreshableRemoteData<>(feedSubject, statusSubject, refresh);
}
 
開發者ID:mmastrac,項目名稱:progscrape-android,代碼行數:12,代碼來源:Model.java

示例5: stopUpdates

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@SuppressWarnings("MissingPermission")
@Override
public void stopUpdates() {
    Log.d(TAG, "stopUpdates()");
    ((LocationManager) context
            .getSystemService(Context.LOCATION_SERVICE))
            .removeUpdates(locationListener);
    locationSubject.onCompleted();
    locationSubject = ReplaySubject.createWithSize(BUFFER_SIZE);
}
 
開發者ID:dhis2,項目名稱:dhis2-android-eventcapture,代碼行數:11,代碼來源:LocationProviderImpl.java

示例6: Aws2Rx

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public Aws2Rx() {
    this.subject = ReplaySubject.createWithSize(1);
}
 
開發者ID:sonyxperiadev,項目名稱:lumber-mill,代碼行數:4,代碼來源:Aws2Rx.java

示例7: turnOn

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Override
@RequiresPermission(allOf = {
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN,
})
public Observable<Void> turnOn() {
    if (adapter == null) {
        return Observable.error(new ChangePowerStateException());
    }

    final ReplaySubject<Void> turnOnMirror = ReplaySubject.createWithSize(1);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE,
                                                    BluetoothAdapter.ERROR);
            final int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                                    BluetoothAdapter.ERROR);
            if (oldState == BluetoothAdapter.STATE_OFF &&
                    newState == BluetoothAdapter.STATE_TURNING_ON) {
                logger.info(LOG_TAG, "Bluetooth turning on");
            } else if (oldState == BluetoothAdapter.STATE_TURNING_ON &&
                    newState == BluetoothAdapter.STATE_ON) {
                logger.info(LOG_TAG, "Bluetooth turned on");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onNext(null);
                turnOnMirror.onCompleted();
            } else {
                logger.info(LOG_TAG, "Bluetooth failed to turn on");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onError(new ChangePowerStateException());
            }
        }
    };
    applicationContext.registerReceiver(receiver,
                                        new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
    if (!adapter.enable()) {
        applicationContext.unregisterReceiver(receiver);
        return Observable.error(new ChangePowerStateException());
    }

    return turnOnMirror;
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:48,代碼來源:NativeBluetoothStack.java

示例8: turnOff

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Override
@RequiresPermission(allOf = {
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN,
})
public Observable<Void> turnOff() {
    if (adapter == null) {
        return Observable.error(new ChangePowerStateException());
    }

    final ReplaySubject<Void> turnOnMirror = ReplaySubject.createWithSize(1);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE,
                                                    BluetoothAdapter.ERROR);
            final int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                                    BluetoothAdapter.ERROR);
            if (oldState == BluetoothAdapter.STATE_ON &&
                    newState == BluetoothAdapter.STATE_TURNING_OFF) {
                logger.info(LOG_TAG, "Bluetooth turning off");
            } else if (oldState == BluetoothAdapter.STATE_TURNING_OFF &&
                    newState == BluetoothAdapter.STATE_OFF) {
                logger.info(LOG_TAG, "Bluetooth turned off");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onNext(null);
                turnOnMirror.onCompleted();
            } else {
                logger.info(LOG_TAG, "Bluetooth failed to turn off");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onError(new ChangePowerStateException());
            }
        }
    };
    applicationContext.registerReceiver(receiver,
                                        new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
    if (!adapter.disable()) {
        applicationContext.unregisterReceiver(receiver);
        return Observable.error(new ChangePowerStateException());
    }

    return turnOnMirror;
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:48,代碼來源:NativeBluetoothStack.java

示例9: operatorConditionalBinding

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
@Test
public void operatorConditionalBinding() throws Exception {
    AtomicBoolean permitted = new AtomicBoolean(true);
    Func1<AtomicBoolean, Boolean> predicate = new Func1<AtomicBoolean, Boolean>() {
        @Override
        public Boolean call(AtomicBoolean atomicBoolean) {
            return atomicBoolean.get();
        }
    };

    ReplaySubject<Integer> numbers = ReplaySubject.createWithSize(1);

    final AtomicInteger counter = new AtomicInteger();
    final AtomicBoolean errorCalled = new AtomicBoolean();
    numbers.lift(new Rx.OperatorConditionalBinding<Integer, AtomicBoolean>(permitted, predicate))
            .subscribe(new Subscriber<Integer>() {
                @Override
                public void onCompleted() {
                }

                @Override
                public void onError(Throwable e) {
                    errorCalled.set(true);
                }

                @Override
                public void onNext(Integer number) {
                    counter.addAndGet(number);
                }
            });

    numbers.onNext(1);
    numbers.onNext(2);
    numbers.onNext(3);

    assertEquals(6, counter.get());

    permitted.set(false);

    numbers.onNext(3);
    numbers.onNext(4);
    numbers.onNext(5);
    numbers.onError(new Throwable("Everything is broken!"));

    assertEquals(6, counter.get());
    assertFalse(errorCalled.get());
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:48,代碼來源:RxTests.java

示例10: RxSnapperListener

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
public RxSnapperListener(String tag) {
    this.subject = ReplaySubject.createWithSize(1);
    this.tag = tag;
}
 
開發者ID:techery,項目名稱:snapper,代碼行數:5,代碼來源:RxSnapperListener.java

示例11: RxBus

import rx.subjects.ReplaySubject; //導入方法依賴的package包/類
/**
 * With this constructor the {@link RxBus} use a {@link ReplaySubject} and instantiate it calling the static method {@code ReplaySubject.createWithSize(cacheSize)}
 * @see ReplaySubject
 * @param cacheSize numbers of max events retained
 */
public RxBus(int cacheSize) {
    super((Subject<T, R>) ReplaySubject.createWithSize(cacheSize));
    mSubscriptionsList = new WeakHashMap<>();
}
 
開發者ID:SysdataSpA,項目名稱:UniversalEventBus,代碼行數:10,代碼來源:RxBus.java


注:本文中的rx.subjects.ReplaySubject.createWithSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。