当前位置: 首页>>代码示例>>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;未经允许,请勿转载。