Java Code Examples for rx.subjects.PublishSubject#onError()

The following examples show how to use rx.subjects.PublishSubject#onError() . 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: PushServers.java    From mantis with Apache License 2.0 6 votes vote down vote up
public static <T> LegacyTcpPushServer<T> infiniteStreamLegacyTcpNested(ServerConfig<T> config, Observable<Observable<T>> o) {
    final PublishSubject<String> serverSignals = PublishSubject.create();
    final String serverName = config.getName();
    Action0 onComplete = new Action0() {
        @Override
        public void call() {
            serverSignals.onNext("ILLEGAL_STATE_COMPLETED");
            throw new IllegalStateException("OnComplete signal received, Server: " + serverName + " is pushing an infinite stream, should not complete");
        }
    };

    Action1<Throwable> onError = new Action1<Throwable>() {
        @Override
        public void call(Throwable t) {
            serverSignals.onError(t);
        }
    };

    PushTrigger<T> trigger = ObservableTrigger.oo(serverName, o, onComplete, onError);
    return new LegacyTcpPushServer<T>(trigger, config, serverSignals);
}
 
Example 2
Source File: PushServers.java    From mantis with Apache License 2.0 6 votes vote down vote up
public static <K, V> LegacyTcpPushServer<KeyValuePair<K, V>> infiniteStreamLegacyTcpNestedGroupedObservable(ServerConfig<KeyValuePair<K, V>> config,
                                                                                                            Observable<Observable<GroupedObservable<K, V>>> go,
                                                                                                            long groupExpirySeconds, final Func1<K, byte[]> keyEncoder,
                                                                                                            HashFunction hashFunction) {
    final PublishSubject<String> serverSignals = PublishSubject.create();
    final String serverName = config.getName();
    Action0 onComplete = new Action0() {
        @Override
        public void call() {
            serverSignals.onNext("ILLEGAL_STATE_COMPLETED");
            throw new IllegalStateException("OnComplete signal received, Server: " + serverName + " is pushing an infinite stream, should not complete");
        }
    };

    Action1<Throwable> onError = new Action1<Throwable>() {
        @Override
        public void call(Throwable t) {
            serverSignals.onError(t);
        }
    };

    PushTrigger<KeyValuePair<K, V>> trigger = ObservableTrigger.oogo(serverName, go, onComplete, onError, groupExpirySeconds,
            keyEncoder, hashFunction);
    return new LegacyTcpPushServer<KeyValuePair<K, V>>(trigger, config, serverSignals);
}
 
Example 3
Source File: PushServers.java    From mantis with Apache License 2.0 6 votes vote down vote up
public static <K, V> LegacyTcpPushServer<KeyValuePair<K, V>> infiniteStreamLegacyTcpNestedMantisGroup(ServerConfig<KeyValuePair<K, V>> config,
                                                                                                      Observable<Observable<MantisGroup<K, V>>> go,
                                                                                                      long groupExpirySeconds, final Func1<K, byte[]> keyEncoder,
                                                                                                      HashFunction hashFunction) {
    final PublishSubject<String> serverSignals = PublishSubject.create();
    final String serverName = config.getName();
    Action0 onComplete = new Action0() {
        @Override
        public void call() {
            serverSignals.onNext("ILLEGAL_STATE_COMPLETED");
            throw new IllegalStateException("OnComplete signal received, Server: " + serverName + " is pushing an infinite stream, should not complete");
        }
    };

    Action1<Throwable> onError = new Action1<Throwable>() {
        @Override
        public void call(Throwable t) {
            serverSignals.onError(t);
        }
    };

    PushTrigger<KeyValuePair<K, V>> trigger = ObservableTrigger.oomgo(serverName, go, onComplete, onError, groupExpirySeconds,
            keyEncoder, hashFunction);
    return new LegacyTcpPushServer<KeyValuePair<K, V>>(trigger, config, serverSignals);
}
 
Example 4
Source File: OperatorFromTransformerTest.java    From rxjava-extras with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorsPassedThroughToOperator() {
    PublishSubject<Integer> subject = PublishSubject.create();
    Recorder recorder1 = new Recorder();
    Recorder recorder2 = new Recorder();
    subject.subscribe(recorder1);
    subject.subscribe(recorder2);
    subject.onNext(1);
    assertEquals(asList(1), recorder1.list());
    assertEquals(asList(1), recorder2.list());
    subject.onNext(2);
    assertEquals(asList(1, 2), recorder1.list());
    assertEquals(asList(1, 2), recorder2.list());
    Exception e = new Exception("boo");
    assertTrue(recorder1.errors().isEmpty());
    assertTrue(recorder2.errors().isEmpty());
    subject.onError(e);
    assertEquals(asList(e), recorder1.errors());
    assertEquals(asList(e), recorder2.errors());
}
 
Example 5
Source File: PushServers.java    From mantis with Apache License 2.0 5 votes vote down vote up
public static <T, S> PushServerSse<T, S> infiniteStreamSse(ServerConfig<T> config, Observable<T> o,
                                                           Func2<Map<String, List<String>>, S, Void> requestPreprocessor,
                                                           Func2<Map<String, List<String>>, S, Void> requestPostprocessor,
                                                           final Func2<Map<String, List<String>>, S, Void> subscribeProcessor,
                                                           S state, boolean supportLegacyMetrics) {

    final String serverName = config.getName();
    final PublishSubject<String> serverSignals = PublishSubject.create();
    Action0 onComplete = new Action0() {
        @Override
        public void call() {
            serverSignals.onNext("ILLEGAL_STATE_COMPLETED");
            throw new IllegalStateException("OnComplete signal received, Server: " + serverName + " is pushing an infinite stream, should not complete");
        }
    };

    Action1<Throwable> onError = new Action1<Throwable>() {
        @Override
        public void call(Throwable t) {
            serverSignals.onError(t);
        }
    };

    PushTrigger<T> trigger = ObservableTrigger.o(serverName, o, onComplete, onError);

    return new PushServerSse<T, S>(trigger, config, serverSignals,
            requestPreprocessor, requestPostprocessor,
            subscribeProcessor, state, supportLegacyMetrics);
}
 
Example 6
Source File: RxMobiusLoopTest.java    From mobius with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPropagateIncomingErrorsAsUnrecoverable() throws Exception {
  RxMobiusLoop<Integer, String, Boolean> loop =
      new RxMobiusLoop<>(builder, "", Collections.emptySet());
  PublishSubject<Integer> input = PublishSubject.create();

  AssertableSubscriber<String> subscriber = input.compose(loop).test();

  Exception expected = new RuntimeException("expected");
  input.onError(expected);
  subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
  subscriber.assertError(new UnrecoverableIncomingException(expected));
  assertEquals(0, connection.valueCount());
}
 
Example 7
Source File: RxActivityResult.java    From RxActivityResult with Apache License 2.0 4 votes vote down vote up
void onError(int requestCode, ActivityNotFoundException exception) {
    PublishSubject<ActivityResult> subject = results.remove(requestCode);
    subject.onError(exception);
}