io.pravega.common.Exceptions.unwrap()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(126)

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

Exceptions.unwrap介绍

[英]If the provided exception is a CompletionException or ExecutionException which need be unwrapped.
[中]如果提供的异常是需要展开的CompletionException或ExecutionException。

代码示例

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

/**
 * Determines whether the given exception can be retried.
 */
private static boolean isRetryable(Throwable ex) {
  ex = Exceptions.unwrap(ex);
  return ex instanceof WriteFailureException
      || ex instanceof DataLogNotAvailableException;
}

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

static boolean isRetryable(Throwable e) {
    Throwable cause = Exceptions.unwrap(e);

    return cause instanceof RetryableException;
  }
}

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

@SneakyThrows
private TxnStatus handleDataNotFoundException(Throwable ex) {
  if (Exceptions.unwrap(ex) instanceof DataNotFoundException) {
    return TxnStatus.UNKNOWN;
  } else {
    throw ex;
  }
}

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

@Override
public boolean toPostpone(ControllerEvent event, long pickupTime, Throwable exception) {
  // We will let the event be postponed for 2 minutes before declaring failure.
  return Exceptions.unwrap(exception) instanceof TaskExceptions.StartException &&
      (System.currentTimeMillis() - pickupTime) < Duration.ofMinutes(2).toMillis();
}

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

@SneakyThrows
private <T> T handleIndexOperationException(Throwable ex) {
  // BTreeIndex throws IllegalDataFormatException (since DataCorruptionException does not exist at that level),
  // so we must convert that so that upstream layers can take appropriate action.
  ex = Exceptions.unwrap(ex);
  if (ex instanceof IllegalDataFormatException) {
    throw new DataCorruptionException("BTreeIndex operation failed. Index corrupted.", ex);
  }
  throw ex;
}

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

private void logErrorHandled(Throwable ex) {
  ex = Exceptions.unwrap(ex);
  log.warn("{}: Iteration[{}].HandledError {}", this.traceObjectId, this.state.getIterationId(), ex.toString());
  //        System.out.println(String.format("%s: Iteration[%s].Warn. %s", this.traceObjectId, this.state.getIterationId(), ex));
}

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

private void failConnection(Throwable e) {
  log.info("Failing connection for writer {} with exception {}", writerId, e.toString());
  state.failConnection(Exceptions.unwrap(e));
  reconnect();
}

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

@Override
public void processError(Throwable cause) {
  cause = Exceptions.unwrap(cause);
  if (cause instanceof StreamSegmentSealedException) {
    processResultComplete();
  } else {
    this.completion.completeExceptionally(cause);
  }
}

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

private UpdateStreamStatus.Status handleUpdateStreamError(Throwable ex, long requestId) {
  Throwable cause = Exceptions.unwrap(ex);
  if (cause instanceof StoreException.DataNotFoundException) {
    return UpdateStreamStatus.Status.STREAM_NOT_FOUND;
  } else {
    log.warn(requestId, "Update stream failed due to ", cause);
    return UpdateStreamStatus.Status.FAILURE;
  }
}

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

private DeleteStreamStatus.Status handleDeleteStreamError(Throwable ex, long requestId) {
  Throwable cause = Exceptions.unwrap(ex);
  if (cause instanceof StoreException.DataNotFoundException) {
    return DeleteStreamStatus.Status.STREAM_NOT_FOUND;
  } else {
    log.warn(requestId, "Delete stream failed.", ex);
    return DeleteStreamStatus.Status.FAILURE;
  }
}

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

private Class<? extends Throwable> getErrorType(final Throwable e) {
    if (Exceptions.shouldUnwrap(retryType) || Exceptions.shouldUnwrap(throwType)) {
      return e.getClass();
    } else {
      return Exceptions.unwrap(e).getClass();
    }
  }
}

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

private void logError(Throwable ex, boolean critical) {
  ex = Exceptions.unwrap(ex);
  if (critical) {
    log.error("{}: Iteration[{}].CriticalError.", this.traceObjectId, this.state.getIterationId(), ex);
  } else {
    log.error("{}: Iteration[{}].Error.", this.traceObjectId, this.state.getIterationId(), ex);
  }
  //System.out.println(String.format("%s: Iteration[%s].Error. %s", this.traceObjectId, this.state.getIterationId(), ex));
}

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

@SneakyThrows
private Void attemptReconcile(Throwable ex, ProducerOperation operation) {
  ex = Exceptions.unwrap(ex);
  if (this.dataSource.isClosed(operation.getTarget())) {
    return null;
  } else {
    throw ex;
  }
}

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

@Override
public CompletableFuture<Map<String, Data>> getTxnInEpoch(int epoch) {
  return Futures.exceptionallyExpecting(store.getChildren(getEpochPath(epoch)),
      e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, Collections.emptyList())
         .thenCompose(txIds -> Futures.allOfWithResults(txIds.stream().collect(
             Collectors.toMap(txId -> txId, txId -> Futures.exceptionallyExpecting(store.getData(getActiveTxPath(epoch, txId)),
                 e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, EMPTY_DATA)))
             ).thenApply(txnMap -> txnMap.entrySet().stream().filter(x -> !x.getValue().equals(EMPTY_DATA))
                           .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
         );
}

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

private void close(Throwable failureCause) {
  if (!this.closed.getAndSet(true)) {
    this.readResult.close();
    if (failureCause == null) {
      // We are closing normally with no processing exception.
      this.entryHandler.processResultComplete();
    } else {
      // An exception was encountered; this must be reported to the entry handler.
      this.entryHandler.processError(Exceptions.unwrap(failureCause));
    }
  }
}

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

private CompletableFuture<Integer> getSegmentSealedEpoch(long segmentId) {
  return getSegmentSealedRecordData(segmentId).handle((x, e) -> {
    if (e != null) {
      if (Exceptions.unwrap(e) instanceof DataNotFoundException) {
        return -1;
      } else {
        throw new CompletionException(e);
      }
    }
    return BitConverter.readInt(x.getData(), 0);
  });
}

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

@SneakyThrows(StreamingException.class)
private void checkTruncatedSegment(StreamingException ex, RollingSegmentHandle handle, SegmentChunk segmentChunk) {
  if (ex != null && (Exceptions.unwrap(ex) instanceof StreamSegmentNotExistsException) || !segmentChunk.exists()) {
    // We ran into a SegmentChunk that does not exist (either marked as such or due to a failed read).
    segmentChunk.markInexistent();
    String message = String.format("Offsets %d-%d have been deleted.", segmentChunk.getStartOffset(), segmentChunk.getLastOffset());
    ex = new StreamSegmentTruncatedException(handle.getSegmentName(), message, ex);
  }
  if (ex != null) {
    throw ex;
  }
}

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

private CompletableFuture<TxnStatus> getCompletedTxnStatus(UUID txId) {
  return getCompletedTx(txId).handle((ok, ex) -> {
    if (ex != null && Exceptions.unwrap(ex) instanceof DataNotFoundException) {
      return TxnStatus.UNKNOWN;
    } else if (ex != null) {
      throw new CompletionException(ex);
    }
    return CompletedTxnRecord.fromBytes(ok.getData()).getCompletionStatus();
  });
}

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

private CompletableFuture<Void> deleteStream(String name) {
  return this.store.delete(name, this.config.getTimeout())
           .exceptionally(ex -> {
             ex = Exceptions.unwrap(ex);
             if (!(ex instanceof StreamSegmentNotExistsException)) {
               throw new CompletionException(ex);
             }
             return null;
           })
      .thenRun(() -> postStreamDeletion(name));
}

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

@Override
protected void errorHandler(Throwable ex) {
  ex = Exceptions.unwrap(ex);
  closeQueue(ex);
  if (!isShutdownException(ex)) {
    // Shutdown exceptions means we are already stopping, so no need to do anything else. For all other cases,
    // record the failure and then stop the OperationProcessor.
    super.errorHandler(ex);
    stopAsync();
  }
}

相关文章