Java Code Examples for rx.subjects.Subject#onNext()
The following examples show how to use
rx.subjects.Subject#onNext() .
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: RateLimitedBatcherTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
private void assertEmitSingleAfterReceiving(BatchableOperationMock expected, BatchableOperationMock... receiving) { final RateLimitedBatcher<BatchableOperationMock, String> batcher = buildBatcher(minimumTimeInQueueMs); final Subject<BatchableOperationMock, BatchableOperationMock> updates = PublishSubject.<BatchableOperationMock>create().toSerialized(); final AssertableSubscriber<Batch<BatchableOperationMock, String>> subscriber = updates.lift(batcher).test(); testScheduler.triggerActions(); subscriber.assertNoTerminalEvent().assertNoValues(); for (BatchableOperationMock received : receiving) { updates.onNext(received); } testScheduler.advanceTimeBy(2 * minimumTimeInQueueMs, TimeUnit.MILLISECONDS); subscriber.assertNoErrors() .assertValueCount(1) .assertValue(Batch.of(expected.getResourceId(), Collections.singletonList(expected))); }
Example 2
Source File: RateLimitedBatcherTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void ignoreErrorsFromDownstream() { final Instant now = Instant.ofEpochMilli(testScheduler.now()); final RateLimitedBatcher<BatchableOperationMock, String> batcher = buildBatcher(minimumTimeInQueueMs); final Subject<BatchableOperationMock, BatchableOperationMock> updates = PublishSubject.<BatchableOperationMock>create().toSerialized(); final AssertableSubscriber<?> subscriber = updates.lift(batcher) .lift(new ExceptionThrowingOperator("some error happened")) .test(); testScheduler.triggerActions(); subscriber.assertNoTerminalEvent().assertNoValues(); for (int i = 0; i < 10; i++) { updates.onNext(new BatchableOperationMock(LOW, now, "resource2", "sub2", "create")); testScheduler.advanceTimeBy(minimumTimeInQueueMs, TimeUnit.MILLISECONDS); subscriber.assertNoTerminalEvent().assertNoValues(); } updates.onCompleted(); testScheduler.advanceTimeBy(minimumTimeInQueueMs, TimeUnit.MILLISECONDS); subscriber.assertNoValues().assertCompleted(); }
Example 3
Source File: AbstractGenericHandler.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
/** * Fulfill and complete the response observable. * * When called directly, this method completes on the event loop, but it can also be used in a callback (see * {@link #scheduleDirect(CoreScheduler, CouchbaseResponse, Subject)} for example. */ private void completeResponse(final CouchbaseResponse response, final Subject<CouchbaseResponse, CouchbaseResponse> observable) { // Noone is listening anymore, handle tracing and/or orphan reporting // depending on if enabled or not. CouchbaseRequest request = response.request(); if (request != null && !request.isActive()) { if (env().operationTracingEnabled() && request.span() != null) { Scope scope = env().tracer().scopeManager() .activate(request.span(), true); scope.span().setBaggageItem("couchbase.orphan", "true"); scope.close(); } if (env().orphanResponseReportingEnabled()) { env().orphanResponseReporter().report(response); } } try { observable.onNext(response); observable.onCompleted(); } catch (Exception ex) { LOGGER.warn("Caught exception while onNext on observable", ex); observable.onError(ex); } }
Example 4
Source File: RxBus.java From youqu_master with Apache License 2.0 | 5 votes |
/** * 触发事件 * * @param content */ @SuppressWarnings({"unchecked", "rawtypes"}) public void post(@NonNull Object tag, @NonNull Object content) { LogUtils.logd("post"+ "eventName: " + tag); List<Subject> subjectList = subjectMapper.get(tag); if (!isEmpty(subjectList)) { for (Subject subject : subjectList) { subject.onNext(content); LogUtils.logd("onEvent"+ "eventName: " + tag); } } }
Example 5
Source File: LeMessageManager.java From letv with Apache License 2.0 | 5 votes |
public void sendMessageByRx(LeResponseMessage responseMessage) { if (responseMessage != null) { List<Subject> subjectList = (List) this.subjectMapper.get(responseMessage.getId()); if (subjectList != null && !subjectList.isEmpty()) { for (Subject subject : subjectList) { subject.onNext(responseMessage); } } } }
Example 6
Source File: RxBus.java From RxJava_RxAndroid with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void post(@NonNull Object tag, @NonNull Object content) { List<Subject> subjectList = subjectMapper.get(tag); if (!isEmpty(subjectList)) { for (Subject subject : subjectList) { subject.onNext(content); } } if (DEBUG) Log.d(TAG, "[send]subjectMapper: " + subjectMapper); }
Example 7
Source File: RxBus.java From Elephant with Apache License 2.0 | 5 votes |
/** * 触发事件 * * @param content */ @SuppressWarnings({"unchecked", "rawtypes"}) public void post(@NonNull Object tag, @NonNull Object content) { JLog.d("post", "eventName: " + tag); List<Subject> subjectList = subjectMapper.get(tag); if (!isEmpty(subjectList)) { for (Subject subject : subjectList) { subject.onNext(content); JLog.d("onEvent", "eventName: " + tag); } } }
Example 8
Source File: RxBus.java From RxAndroidEventsSample with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void post(@NonNull Object tag, @NonNull Object content) { List<Subject> subjectList = subjectMapper.get(tag); if (!ABTextUtil.isEmpty(subjectList)) { for (Subject subject : subjectList) { subject.onNext(content); } } if (DEBUG) Log.d(TAG, "[send]subjectMapper: " + subjectMapper); }
Example 9
Source File: RxBusBak.java From RxAndroidEventsSample with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void send(Object tag, Object content) { Subject subject = findSubject(tag); if (null != subject) { subject.onNext(content); } if (DEBUG) Log.d(TAG, "[send]subjectMapper: " + subjectMapper); }
Example 10
Source File: RxBusOlder.java From RxBus with Apache License 2.0 | 5 votes |
public void post(@NonNull Object tag, @NonNull Object content) { List<Subject> subjects = mSubjectsMapper.get(tag); if (subjects != null && !subjects.isEmpty()) { for (Subject subject : subjects) { subject.onNext(content); } } if (DEBUG) { Timber.d("[send] mSubjectsMapper: " + mSubjectsMapper); } }
Example 11
Source File: TestCouchbaseTarget.java From datacollector with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private static CouchbaseConnector getConnector(Class responseClass) throws Exception { ENV = DefaultCouchbaseEnvironment.create(); CouchbaseCore core = mock(CouchbaseCore.class); CouchbaseAsyncBucket asyncBucket = new CouchbaseAsyncBucket(core, ENV, BUCKET, USERNAME, PASSWORD, Collections.emptyList() ); final CouchbaseRequest requestMock = mock(CouchbaseRequest.class); Subject<CouchbaseResponse, CouchbaseResponse> response = AsyncSubject.create(); if(responseClass == SimpleSubdocResponse.class) { final BinarySubdocRequest subdocRequestMock = mock(BinarySubdocRequest.class); when(subdocRequestMock.span()).thenReturn(mock(Span.class)); response.onNext(new SimpleSubdocResponse(ResponseStatus.SUCCESS, KeyValueStatus.SUCCESS.code(), BUCKET, Unpooled.EMPTY_BUFFER, subdocRequestMock, 1234, null )); response.onCompleted(); } else { Constructor con = responseClass.getConstructor(ResponseStatus.class, short.class, long.class, String.class, ByteBuf.class, MutationToken.class, CouchbaseRequest.class ); response.onNext((CouchbaseResponse) con.newInstance(ResponseStatus.SUCCESS, KeyValueStatus.SUCCESS.code(), 1234, BUCKET, Unpooled.EMPTY_BUFFER, null, requestMock )); response.onCompleted(); } when(core.send(any(BinarySubdocRequest.class))).thenReturn(response); when(core.send(any())).thenReturn(response); when(requestMock.span()).thenReturn(mock(Span.class)); CouchbaseConnector connector = mock(CouchbaseConnector.class); when(connector.getScheduler()).thenReturn(ENV.scheduler()); when(connector.bucket()).thenReturn(asyncBucket); return connector; }