rx.Single.onErrorReturn()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中rx.Single.onErrorReturn()方法的一些代码示例,展示了Single.onErrorReturn()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.onErrorReturn()方法的具体详情如下:
包路径:rx.Single
类名称:Single
方法名:onErrorReturn

Single.onErrorReturn介绍

暂无

代码示例

代码示例来源:origin: Netflix/EVCache

private <T> Single<T> getData(EVCacheClient client, String canonicalKey, Transcoder<T> tc, boolean throwException, boolean hasZF, Scheduler scheduler) {
  if (client == null) return Single.error(new IllegalArgumentException("Client cannot be null"));
  if(hashKey.get()) {
    return Single.error(new IllegalArgumentException("Not supported"));
  } else { 
    if(tc == null && _transcoder != null) tc = (Transcoder<T>)_transcoder;
    return client.get(canonicalKey, tc, throwException, hasZF, scheduler).onErrorReturn(ex -> {
      if (ex instanceof EVCacheReadQueueException) {
        if (log.isDebugEnabled() && shouldLog()) log.debug("EVCacheReadQueueException while getting data for APP " + _appName + ", key : " + canonicalKey + "; hasZF : " + hasZF, ex);
        if (!throwException || hasZF) return null;
        throw sneakyThrow(ex);
      } else if (ex instanceof EVCacheException) {
        if (log.isDebugEnabled() && shouldLog()) log.debug("EVCacheException while getting data for APP " + _appName + ", key : " + canonicalKey + "; hasZF : " + hasZF, ex);
        if (!throwException || hasZF) return null;
        throw sneakyThrow(ex);
      } else {
        if (log.isDebugEnabled() && shouldLog()) log.debug("Exception while getting data for APP " + _appName + ", key : " + canonicalKey, ex);
        if (!throwException || hasZF) return null;
        throw sneakyThrow(ex);
      }
    });
  }
}

代码示例来源:origin: Netflix/EVCache

if (event != null) endEvent(event);
  return data;
}).onErrorReturn(ex -> {
  if (ex instanceof net.spy.memcached.internal.CheckedOperationTimeoutException) {
    if (event != null) eventError(event, ex);

代码示例来源:origin: Netflix/EVCache

}).onErrorReturn(ex -> {
  if (ex instanceof net.spy.memcached.internal.CheckedOperationTimeoutException) {
    if (event != null) eventError(event, ex);

代码示例来源:origin: georocket/georocket

@Override
 public Single<Boolean> isRunning() {
  return client.performRequestNoRetry(HttpMethod.HEAD, "/", null)
    .map(v -> true).onErrorReturn(t -> false);
 }
}

代码示例来源:origin: Petikoch/Java_MVVM_with_Swing_and_RxJava_Examples

createAccountResult.onErrorReturn(throwable -> FinishedIndicator.INSTANCE),
    sendEmailResult.onErrorReturn(throwable -> FinishedIndicator.INSTANCE),
    (finishedIndicator, finishedIndicator2) -> FinishedIndicator.INSTANCE
);

代码示例来源:origin: meltwater/rxrabbit

private Observable<PublishedMessage> sendNMessagesAsync(int numMessages, int offset, RabbitPublisher publisher) {
  final List<Observable<PublishedMessage>> sendCallbacks = new ArrayList<>();
  log.infoWithParams("Scheduling messages to rabbit", "numMessages", numMessages);
  for (int it = 1; it <= numMessages; it++) {
    final int id = it + offset;
    String messageId = String.valueOf(it);
    sendCallbacks.add(
        publisher.call(
            new Exchange(inputExchange),
            new RoutingKey("routing"),
            new AMQP.BasicProperties.Builder()
                .appId("send-messages")
                .messageId(messageId)
                .deliveryMode(DeliveryMode.persistent.code)
                .headers(new HashMap<>())
                .build(),
            new Payload(messageId.getBytes()))
            .map(aVoid -> new PublishedMessage(id, false))
            .onErrorReturn(throwable -> {
              log.errorWithParams("Failed message.", throwable);
              return new PublishedMessage(id, true);
            })
            .toObservable());
  }
  return Observable.merge(sendCallbacks);
}

代码示例来源:origin: meltwater/rxrabbit

private Observable<RxRabbitTests.PublishedMessage> sendNMessagesAsync(int numMessages, int offset, RabbitPublisher publisher) {
  final List<Observable<RxRabbitTests.PublishedMessage>> sendCallbacks = new ArrayList<>();
  log.infoWithParams("Scheduling messages to rabbit", "numMessages", numMessages);
  for (int it = 1 ; it<=numMessages; it++) {
    final int id = it+offset;
    String messageId = String.valueOf(it);
    sendCallbacks.add(
        publisher.call(
            new Exchange(inputExchange),
            new RoutingKey("routing"),
            new AMQP.BasicProperties.Builder()
                .appId("send-messages")
                .messageId(messageId)
                .deliveryMode(DeliveryMode.persistent.code)
                .headers(new HashMap<>())
                .build(),
            new Payload(messageId.getBytes()))
            .map(aVoid -> new RxRabbitTests.PublishedMessage(id, false))
            .onErrorReturn(throwable -> {
              log.errorWithParams("Failed message.", throwable);
              return new RxRabbitTests.PublishedMessage(id, true);
            })
            .toObservable());
  }
  return Observable.merge(sendCallbacks);
}

代码示例来源:origin: hawkular/hawkular-metrics

.onErrorReturn(t -> {
  logger.warnf(t, "Job execution of %s for time slice %d failed", jobDetails, timeSlice.getTime());
  return new JobExecutionState(jobDetails, timeSlice, t, activeJobs);

相关文章