Java Code Examples for io.reactivex.subjects.SingleSubject#create()
The following examples show how to use
io.reactivex.subjects.SingleSubject#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppServer.java From crnk-framework with Apache License 2.0 | 6 votes |
public void start() { VertxOptions options = new VertxOptions(); options.setMaxEventLoopExecuteTime(Long.MAX_VALUE); SingleSubject waitSubject = SingleSubject.create(); Handler<AsyncResult<String>> completionHandler = event -> { if (event.succeeded()) { waitSubject.onSuccess(event.result()); } else { event.cause().printStackTrace(); System.exit(0); } }; vertx = Vertx.vertx(options); vertx.deployVerticle(vehicle, completionHandler); waitSubject.blockingGet(); }
Example 2
Source File: SearchInteractorImpl.java From marvel with MIT License | 6 votes |
@Override public Single<CharactersResponse> loadCharacter(String query, String privateKey, String publicKey, long timestamp) { if (characterSubscription == null || characterSubscription.isDisposed()) { characterSubject = SingleSubject.create(); // generate hash using timestamp and API keys String hash = HashGenerator.generate(timestamp, privateKey, publicKey); characterSubscription = api.getCharacters(query, publicKey, hash, timestamp) .subscribeOn(scheduler.backgroundThread()) .subscribe(characterSubject::onSuccess); } return characterSubject.hide(); }
Example 3
Source File: CorePeripheral.java From RxCentralBle with Apache License 2.0 | 5 votes |
@Override public Single<byte[]> read(UUID svc, UUID chr) { final SingleSubject<Pair<UUID, byte[]>> scopedSubject = SingleSubject.create(); return scopedSubject .filter(chrPair -> chrPair.first.equals(chr)) .flatMapSingle(chrPair -> Single.just(chrPair.second)) .doOnSubscribe(disposable -> processRead(scopedSubject, svc, chr)) .doFinally(() -> clearReadSubject(scopedSubject)); }
Example 4
Source File: CorePeripheral.java From RxCentralBle with Apache License 2.0 | 5 votes |
@Override public Completable write(UUID svc, UUID chr, byte[] data) { final SingleSubject<UUID> scopedSubject = SingleSubject.create(); return scopedSubject .filter(writeChr -> writeChr.equals(chr)) .ignoreElement() .doOnSubscribe(disposable -> processWrite(scopedSubject, svc, chr, data)) .doFinally(() -> clearWriteSubject(scopedSubject)); }
Example 5
Source File: CorePeripheral.java From RxCentralBle with Apache License 2.0 | 5 votes |
@Override public Completable registerNotification(UUID svc, UUID chr, @Nullable Preprocessor preprocessor) { final SingleSubject<UUID> scopedSubject = SingleSubject.create(); return scopedSubject .filter(regChr -> regChr.equals(chr)) .ignoreElement() .doOnSubscribe( disposable -> processRegisterNotification(scopedSubject, svc, chr, preprocessor)) .doFinally(() -> clearRegisterNotificationSubject(scopedSubject)); }
Example 6
Source File: CorePeripheral.java From RxCentralBle with Apache License 2.0 | 5 votes |
@Override public Completable unregisterNotification(UUID svc, UUID chr) { final SingleSubject<UUID> scopedSubject = SingleSubject.create(); return scopedSubject .filter(regChr -> regChr.equals(chr)) .ignoreElement() .doOnSubscribe(disposable -> processUnregisterNotification(scopedSubject, svc, chr)) .doOnComplete(() -> preprocessorMap.remove(chr)) .doFinally(() -> clearRegisterNotificationSubject(scopedSubject)); }
Example 7
Source File: CorePeripheral.java From RxCentralBle with Apache License 2.0 | 5 votes |
@TargetApi(21) @Override public Single<Integer> requestMtu(int mtu) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return Single.error(new PeripheralError(PeripheralError.Code.MINIMUM_SDK_UNSUPPORTED)); } final SingleSubject<Integer> scopedSubject = SingleSubject.create(); return scopedSubject .doOnSubscribe(disposable -> processRequestMtu(scopedSubject, mtu)) .doFinally(() -> clearRequestMtuSubject(scopedSubject)); }
Example 8
Source File: CorePeripheral.java From RxCentralBle with Apache License 2.0 | 5 votes |
@Override public Single<Integer> readRssi() { SingleSubject<Integer> scopedSubject = SingleSubject.create(); return scopedSubject .doOnSubscribe(disposable -> processReadRssi(scopedSubject)) .doFinally(() -> clearReadRssiSubject(scopedSubject)); }
Example 9
Source File: CrnkVertxHandler.java From crnk-framework with Apache License 2.0 | 5 votes |
private Mono getBody(VertxRequestContext vertxRequestContext) { HttpServerRequest serverRequest = vertxRequestContext.getServerRequest(); SingleSubject<VertxRequestContext> bodySubject = SingleSubject.create(); Handler<Buffer> bodyHandler = (event) -> { vertxRequestContext.setRequestBody(event.toString().getBytes(StandardCharsets.UTF_8)); bodySubject.onSuccess(vertxRequestContext); }; serverRequest.bodyHandler(bodyHandler); return Mono.from(bodySubject.toFlowable()); }
Example 10
Source File: VertxTestContainer.java From crnk-framework with Apache License 2.0 | 5 votes |
@Override public void stop() { SingleSubject waitSubject = SingleSubject.create(); Handler<AsyncResult<Void>> completionHandler = event -> waitSubject.onSuccess("test"); vertx.close(completionHandler); waitSubject.blockingGet(); vehicle.testModule.clear(); vertx = null; vehicle = null; port = -1; }
Example 11
Source File: ConcurrentSingleCache.java From akarnokd-misc with Apache License 2.0 | 5 votes |
public Single<Entity> getEntity(String guid) { SingleSubject<Entity> e = map.get(guid); if (e == null) { e = SingleSubject.create(); SingleSubject<Entity> f = map.putIfAbsent(guid, e); if (f == null) { longLoadFromDatabase(guid).subscribe(e); } else { e = f; } } return e; }
Example 12
Source File: AppServer.java From crnk-framework with Apache License 2.0 | 4 votes |
public void stop() { SingleSubject waitSubject = SingleSubject.create(); Handler<AsyncResult<Void>> completionHandler = event -> waitSubject.onSuccess("test"); vertx.close(completionHandler); waitSubject.blockingGet(); }
Example 13
Source File: SingleObserveOnRaceTest.java From akarnokd-misc with Apache License 2.0 | 4 votes |
@Test public void race() throws Exception { Worker w = Schedulers.newThread().createWorker(); try { for (int i = 0; i < 1000; i++) { Integer[] value = { 0, 0 }; TestObserver<Integer> to = new TestObserver<Integer>() { @Override public void onSuccess(Integer v) { value[1] = value[0]; super.onSuccess(v); } }; SingleSubject<Integer> subj = SingleSubject.create(); subj.observeOn(Schedulers.single()) .onTerminateDetach() .subscribe(to); AtomicInteger wip = new AtomicInteger(2); CountDownLatch cdl = new CountDownLatch(2); w.schedule(() -> { if (wip.decrementAndGet() != 0) { while (wip.get() != 0); } subj.onSuccess(1); cdl.countDown(); }); Schedulers.single().scheduleDirect(() -> { if (wip.decrementAndGet() != 0) { while (wip.get() != 0); } to.cancel(); value[0] = null; cdl.countDown(); }); cdl.await(); Assert.assertNotNull(value[1]); } } finally { w.dispose(); } }