java.util.concurrent.TimeoutException.initCause()方法的使用及代码示例

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

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

TimeoutException.initCause介绍

暂无

代码示例

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException {
    A.ensure(timeout >= 0, "timeout >= 0");
    A.notNull(unit, "unit != null");
    try {
      T res = fut.get(unit.toMillis(timeout));
      if (fut.isCancelled())
        throw new CancellationException("Task was cancelled: " + fut);
      return res;
    }
    catch (IgniteFutureTimeoutCheckedException e) {
      TimeoutException e2 = new TimeoutException();
      e2.initCause(e);
      throw e2;
    }
    catch (ComputeTaskTimeoutCheckedException e) {
      throw new ExecutionException("Task execution timed out during waiting for task result: " + fut, e);
    }
    catch (IgniteCheckedException e) {
      // Task cancellation may cause throwing exception.
      if (fut.isCancelled()) {
        RuntimeException ex = new CancellationException("Task was cancelled: " + fut);
        ex.initCause(e);
        throw ex;
      }
      throw new ExecutionException("Failed to get task result.", e);
    }
  }
}

代码示例来源:origin: ehcache/ehcache3

private EhcacheEntityResponse invokeInternalAndWait(InvocationBuilder<EhcacheEntityMessage, EhcacheEntityResponse> invocationBuilder, Duration timeLimit, EhcacheEntityMessage message, boolean track)
  throws ClusterException, TimeoutException {
 try {
  LongSupplier nanosRemaining = nanosStartingFromNow(timeLimit);
  InvokeFuture<EhcacheEntityResponse> future = invokeInternal(invocationBuilder, Duration.ofNanos(nanosRemaining.getAsLong()), message, track);
  EhcacheEntityResponse response = waitFor(nanosRemaining.getAsLong(), future);
  if (EhcacheResponseType.FAILURE.equals(response.getResponseType())) {
   throw ((Failure)response).getCause();
  } else {
   return response;
  }
 } catch (EntityException e) {
  throw new RuntimeException(message + " error: " + e.toString(), e);
 } catch (TimeoutException e) {
  String msg = "Timeout exceeded for " + message + " message; " + timeLimit;
  TimeoutException timeoutException = new TimeoutException(msg);
  timeoutException.initCause(e);
  LOGGER.info(msg, timeoutException);
  throw timeoutException;
 }
}

代码示例来源:origin: apache/phoenix

TimeoutException toThrow = new TimeoutException("Operation " + op.getOperationName()
    + " didn't complete because of exception. Time elapsed: " + watch.elapsedMillis());
toThrow.initCause(ex);
throw toThrow;

代码示例来源:origin: org.eclipse.net4j/util

public TimeoutException createTimeoutException()
 {
  TimeoutException timeoutException = new TimeoutException(getMessage());
  timeoutException.initCause(this);
  return timeoutException;
 }
}

代码示例来源:origin: org.eclipse.net4j/util

/**
  * @since 3.0
  */
 public TimeoutException createTimeoutException()
 {
  TimeoutException timeoutException = new TimeoutException(getMessage());
  timeoutException.initCause(this);
  return timeoutException;
 }
}

代码示例来源:origin: org.jboss.arquillian.container/arquillian-container-osgi

@Override
  public MBeanServerConnection call() throws Exception {
    Exception lastException = null;
    long timeoutMillis = System.currentTimeMillis() + unit.toMillis(timeout);
    while (System.currentTimeMillis() < timeoutMillis) {
      try {
        return getMBeanServerConnection();
      } catch (Exception ex) {
        lastException = ex;
        Thread.sleep(500);
      }
    }
    TimeoutException timeoutException = new TimeoutException();
    timeoutException.initCause(lastException);
    throw timeoutException;
  }
};

代码示例来源:origin: diennea/herddb

public Pdu sendMessageWithPduReply(long id, ByteBuf request, long timeout) throws InterruptedException, TimeoutException {
  CompletableFuture<Pdu> resp = new CompletableFuture<>();
  long _start = System.currentTimeMillis();
  sendRequestWithAsyncReply(id, request, timeout, (Pdu message1, Throwable error) -> {
    if (error != null) {
      resp.completeExceptionally(error);
    } else {
      resp.complete(message1);
    }
  });
  try {
    return resp.get(timeout, TimeUnit.MILLISECONDS);
  } catch (ExecutionException err) {
    if (err.getCause() instanceof IOException) {
      TimeoutException te = new TimeoutException("io-error while waiting for reply: " + err.getCause());
      te.initCause(err.getCause());
      throw te;
    }
    throw new RuntimeException(err.getCause());
  } catch (TimeoutException timeoutException) {
    long _stop = System.currentTimeMillis();
    TimeoutException err = new TimeoutException("Timed-out after waiting response for " + (_stop - _start) + " ms");
    err.initCause(timeoutException);
    throw err;
  }
}

代码示例来源:origin: org.sonatype.nexus/nexus-pax-exam

Loggers.getLogger(NexusPaxExamSupport.class).warn("Timed out waiting for {} after {} ms", function, millis);
throw (TimeoutException) new TimeoutException("Condition still unsatisfied after " + millis + " ms")
  .initCause(functionEvaluationException);

代码示例来源:origin: jboss-fuse/fabric8

private void waitForSuccessfulDeploymentOf(String containerName, BundleContext syscontext, long timeout) throws TimeoutException {
    System.out.println(String.format("Waiting for container %s to provision.", containerName));
    Exception lastException = null;
    long startedAt = System.currentTimeMillis();
    while (!Thread.interrupted() && System.currentTimeMillis() < startedAt + timeout) {
      ServiceReference<FabricService> sref = syscontext.getServiceReference(FabricService.class);
      FabricService fabricService = sref != null ? syscontext.getService(sref) : null;
      try {
        Container container = fabricService != null ? fabricService.getContainer(containerName) : null;
        if (container != null && container.isAlive() && "success".equals(container.getProvisionStatus())) {
          return;
        } else {
          Thread.sleep(500);
        }
      } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        lastException = ex;
      } catch (Exception ex) {
        lastException = ex;
      }
    }
    TimeoutException toex = new TimeoutException("Cannot provision container in time");
    if (lastException != null) {
      toex.initCause(lastException);
    }
    throw toex;
  }
}

代码示例来源:origin: zeroturnaround/zt-exec

private TimeoutException newTimeoutException(long timeout, TimeUnit unit, WaitForProcess task) {
 StringBuilder sb = new StringBuilder();
 Process process = task.getProcess();
 Integer exitValue = getExitCodeOrNull(process);
 if (exitValue == null) {
  sb.append("Timed out waiting for ").append(process).append(" to finish");
 }
 else {
  sb.append("Timed out finishing ").append(process);
  sb.append(", exit value: ").append(exitValue);
 }
 sb.append(", timeout: ").append(timeout).append(" ").append(getUnitsAsString(timeout, unit));
 task.addExceptionMessageSuffix(sb);
 TimeoutException result = new TimeoutException(sb.toString());
 if (exitValue != null) {
  StackTraceElement[] stackTrace = task.getStackTrace();
  if (stackTrace != null) {
   Exception cause = new Exception("Stack dump of worker thread.");
   cause.setStackTrace(stackTrace);
   result.initCause(cause);
  }
 }
 return result;
}

代码示例来源:origin: jboss-fuse/fabric8

toex.initCause(lastException);

代码示例来源:origin: org.apache.ignite/ignite-core

/** {@inheritDoc} */
  @SuppressWarnings({"MethodWithTooExceptionsDeclared"})
  @Override public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException {
    A.ensure(timeout >= 0, "timeout >= 0");
    A.notNull(unit, "unit != null");
    try {
      T res = fut.get(unit.toMillis(timeout));
      if (fut.isCancelled())
        throw new CancellationException("Task was cancelled: " + fut);
      return res;
    }
    catch (IgniteFutureTimeoutCheckedException e) {
      TimeoutException e2 = new TimeoutException();
      e2.initCause(e);
      throw e2;
    }
    catch (ComputeTaskTimeoutCheckedException e) {
      throw new ExecutionException("Task execution timed out during waiting for task result: " + fut, e);
    }
    catch (IgniteCheckedException e) {
      // Task cancellation may cause throwing exception.
      if (fut.isCancelled()) {
        RuntimeException ex = new CancellationException("Task was cancelled: " + fut);
        ex.initCause(e);
        throw ex;
      }
      throw new ExecutionException("Failed to get task result.", e);
    }
  }
}

代码示例来源:origin: org.gridgain/gridgain-core

/** {@inheritDoc} */
  @SuppressWarnings({"MethodWithTooExceptionsDeclared"})
  @Override public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException {
    A.ensure(timeout >= 0, "timeout >= 0");
    A.notNull(unit, "unit != null");
    try {
      T res = fut.get(unit.toMillis(timeout));
      if (fut.isCancelled())
        throw new CancellationException("Task was cancelled: " + fut);
      return res;
    }
    catch (GridFutureTimeoutException e) {
      TimeoutException e2 = new TimeoutException();
      e2.initCause(e);
      throw e2;
    }
    catch (GridComputeTaskTimeoutException e) {
      throw new ExecutionException("Task execution timed out during waiting for task result: " + fut, e);
    }
    catch (GridException e) {
      // Task cancellation may cause throwing exception.
      if (fut.isCancelled()) {
        RuntimeException ex = new CancellationException("Task was cancelled: " + fut);
        ex.initCause(e);
        throw ex;
      }
      throw new ExecutionException("Failed to get task result.", e);
    }
  }
}

代码示例来源:origin: org.ehcache/ehcache-clustered

private EhcacheEntityResponse invokeInternalAndWait(InvocationBuilder<EhcacheEntityMessage, EhcacheEntityResponse> invocationBuilder, Duration timeLimit, EhcacheEntityMessage message, boolean track)
  throws ClusterException, TimeoutException {
 try {
  LongSupplier nanosRemaining = nanosStartingFromNow(timeLimit);
  InvokeFuture<EhcacheEntityResponse> future = invokeInternal(invocationBuilder, Duration.ofNanos(nanosRemaining.getAsLong()), message, track);
  EhcacheEntityResponse response = waitFor(nanosRemaining.getAsLong(), future);
  if (EhcacheResponseType.FAILURE.equals(response.getResponseType())) {
   throw ((Failure)response).getCause();
  } else {
   return response;
  }
 } catch (EntityException e) {
  throw new RuntimeException(message + " error: " + e.toString(), e);
 } catch (TimeoutException e) {
  String msg = "Timeout exceeded for " + message + " message; " + timeLimit;
  TimeoutException timeoutException = new TimeoutException(msg);
  timeoutException.initCause(e);
  LOGGER.info(msg, timeoutException);
  throw timeoutException;
 }
}

代码示例来源:origin: com.aliyun.phoenix/ali-phoenix-core

TimeoutException toThrow = new TimeoutException("Operation " + op.getOperationName()
    + " didn't complete because of exception. Time elapsed: " + watch.elapsedMillis());
toThrow.initCause(ex);
throw toThrow;

代码示例来源:origin: org.apache.phoenix/phoenix-core

TimeoutException toThrow = new TimeoutException("Operation " + op.getOperationName()
    + " didn't complete because of exception. Time elapsed: " + watch.elapsedMillis());
toThrow.initCause(ex);
throw toThrow;

相关文章