/** {@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); } } }
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; } }
TimeoutException toThrow = new TimeoutException("Operation " + op.getOperationName() + " didn't complete because of exception. Time elapsed: " + watch.elapsedMillis()); toThrow.initCause(ex); throw toThrow;
public TimeoutException createTimeoutException() { TimeoutException timeoutException = new TimeoutException(getMessage()); timeoutException.initCause(this); return timeoutException; } }
/** * @since 3.0 */ public TimeoutException createTimeoutException() { TimeoutException timeoutException = new TimeoutException(getMessage()); timeoutException.initCause(this); return timeoutException; } }
@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; } };
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; } }
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);
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; } }
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; }
toex.initCause(lastException);
/** {@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); } } }
/** {@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); } } }
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; } }
TimeoutException toThrow = new TimeoutException("Operation " + op.getOperationName() + " didn't complete because of exception. Time elapsed: " + watch.elapsedMillis()); toThrow.initCause(ex); throw toThrow;
TimeoutException toThrow = new TimeoutException("Operation " + op.getOperationName() + " didn't complete because of exception. Time elapsed: " + watch.elapsedMillis()); toThrow.initCause(ex); throw toThrow;