List of usage examples for java.util.concurrent TimeoutException TimeoutException
public TimeoutException(String message)
From source file:org.cloudifysource.esc.util.Utils.java
/** * Gets a "full" admin object. The function waits until all GridServiceManagers are found before returning the * object.//from w w w . j a va 2s .c o m * * @param managementIP * The IP of the management machine to connect to (through the default LUS port) * @param expectedGsmCount * The number of GridServiceManager objects that are expected to be * found. Only when this number is reached, the admin object is considered loaded and can be returned * @param lusPort port the lus is running on. * * * @return An updated admin object * @throws TimeoutException * Indicates the timeout (default is 90 seconds) was reached before the admin object was fully loaded * @throws InterruptedException * Indicated the thread was interrupted while waiting */ public static Admin getAdminObject(final String managementIP, final int expectedGsmCount, final Integer lusPort) throws TimeoutException, InterruptedException { final AdminFactory adminFactory = new AdminFactory(); adminFactory.addLocator(IPUtils.getSafeIpAddress(managementIP) + ":" + lusPort); final Admin admin = adminFactory.createAdmin(); GridServiceManagers gsms = admin.getGridServiceManagers(); final long end = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(ADMIN_API_TIMEOUT); while (admin.getLookupServices() == null || gsms == null || expectedGsmCount > 0 && gsms.getSize() < expectedGsmCount) { if (System.currentTimeMillis() > end) { throw new TimeoutException("Admin API timed out"); } Thread.sleep(TimeUnit.SECONDS.toMillis(1)); gsms = admin.getGridServiceManagers(); } return admin; }
From source file:org.apache.reef.vortex.api.VortexAggregateFuture.java
/** * @param timeout the timeout for the operation. * @param timeUnit the time unit of the timeout. * @return the next aggregation result for the future, within the user specified timeout, null if no more results. * @throws TimeoutException if time out hits. *///w w w . ja v a2s .co m public synchronized AggregateResultSynchronous<TInput, TOutput> get(final long timeout, final TimeUnit timeUnit) throws InterruptedException, TimeoutException { if (taskletIdInputMap.isEmpty()) { return null; } final Pair<List<Integer>, AggregateResult> resultPair = resultQueue.poll(timeout, timeUnit); if (resultPair == null) { throw new TimeoutException("Synchronous aggregation of the next future result timed out. Timeout = " + timeout + " in time units: " + timeUnit); } removeFromTaskletIdInputMap(resultPair.getLeft()); return new AggregateResultSynchronous<>(resultPair.getRight(), !taskletIdInputMap.isEmpty()); }
From source file:org.openmrs.scheduler.web.controller.TaskHelper.java
/** * Waits until a task is executing or until a timeout occurs. * * @param task the task that is expected to be executing * @param timeoutInMilliseconds defines how long to wait before raising a timeout exception * * @throws InterruptedException if an interrupt occurs while waiting * @throws TimeoutException if the task is not executing after the specified timeout * * @should wait until task is executing//from w w w. j a va2 s . c o m * @should raise a timeout exception when the timeout is exceeded */ public void waitUntilTaskIsExecuting(TaskDefinition task, long timeoutInMilliseconds) throws InterruptedException, TimeoutException { long scheduledBefore = System.currentTimeMillis(); log.debug("waiting for test task to start executing"); while (!task.getTaskInstance().isExecuting()) { if (System.currentTimeMillis() - scheduledBefore > timeoutInMilliseconds) { throw new TimeoutException( "A timeout has occurred while starting a test task. The task has been scheduled " + timeoutInMilliseconds + " milliseconds ago and is not yet executing."); } Thread.sleep(10); } log.debug("test task has started executing " + (System.currentTimeMillis() - scheduledBefore) + " milliseconds after having been scheduled"); }
From source file:org.eclipse.gyrex.cloud.tests.internal.zookeeper.CountdownCloudStateHandler.java
public void waitForInterrupted(final int timeout) throws InterruptedException, TimeoutException { if (!interrupted.await(timeout, TimeUnit.MILLISECONDS)) { throw new TimeoutException("Did not became interrupted!"); }//from w w w . j ava 2 s . co m }
From source file:Highcharts.SVGConverter.java
public String requestServer(String params) throws SVGConverterException, TimeoutException, NoSuchElementException, PoolException { Server server = null;/*from w w w . j a v a 2 s . c om*/ try { server = (Server) serverPool.borrowObject(); String response = server.request(params); return response; } catch (SocketTimeoutException ste) { throw new TimeoutException(ste.getMessage()); } catch (TimeoutException te) { throw new TimeoutException(te.getMessage()); } catch (PoolException nse) { logger.error("POOL EXHAUSTED!!"); throw new PoolException(nse.getMessage()); } catch (Exception e) { logger.debug(e.getMessage()); throw new SVGConverterException("Error converting SVG" + e.getMessage()); } finally { try { serverPool.returnObject(server, true); } catch (Exception e) { logger.error("Exception while returning server to pool: " + e.getMessage()); } } }
From source file:com.crossbusiness.resiliency.aspect.AbstractTimeout2Aspect.java
public Object doTimeout(final ProceedingJoinPoint point, Timeout2 timeoutConfig) throws Throwable { log.debug(point + " -> " + timeoutConfig); Method method = ((MethodSignature) point.getSignature()).getMethod(); TimeoutThread thread = new TimeoutThread(); thread.setDaemon(timeoutConfig.daemon()); thread.setPoint(point);// w w w . ja v a 2s .c om thread.start(); thread.join(timeoutConfig.unit().toMillis(timeoutConfig.value())); if (!thread.isCompleted()) { throw new TimeoutException("Method " + method + " exceeded timeout of " + timeoutConfig.unit().toMillis(timeoutConfig.value()) + " ms"); } else if (thread.getThrowable() != null) { throw thread.getThrowable(); } else { return thread.getValue(); } }
From source file:org.eclipse.gyrex.cloud.tests.internal.zookeeper.CountdownCloudStateHandler.java
public void waitForOffline(final int timeout) throws InterruptedException, TimeoutException { if (!offline.await(timeout, TimeUnit.MILLISECONDS)) { throw new TimeoutException("Did not became offline!"); }//from ww w . j av a 2 s .c o m }
From source file:com.microsoft.applicationinsights.test.framework.ApplicationTelemetryManager.java
public List<TelemetryItem> getApplicationTelemetries(String runId, int numberOfExpectedTelemetries) throws Exception { List<TelemetryItem> telemetriesForRunId = getTelemetriesFromCacheWithRunId(runId); if (telemetriesForRunId.size() < numberOfExpectedTelemetries) { int missingTelemetriesCount = numberOfExpectedTelemetries - telemetriesForRunId.size(); updateTelemetryCache(runId, missingTelemetriesCount); }/*from w w w . ja v a 2 s . c o m*/ telemetriesForRunId = getTelemetriesFromCacheWithRunId(runId); if (telemetriesForRunId.size() < numberOfExpectedTelemetries) { String message = String.format( "Got only %d out of %d expected telemetries within the timeout (%d seconds)", telemetriesForRunId.size(), numberOfExpectedTelemetries, this.pollingTimeoutInSeconds); throw new TimeoutException(message); } return telemetriesForRunId; }
From source file:org.eclipse.gyrex.cloud.tests.internal.zookeeper.CountdownCloudStateHandler.java
public void waitForOnline(final int timeout) throws InterruptedException, TimeoutException { if (!online.await(timeout, TimeUnit.MILLISECONDS)) { throw new TimeoutException("Did not became online!"); }/*from ww w.jav a2 s. c om*/ }
From source file:com.tomtom.speedtools.services.lbs.route.implementation.TomTomLbsRouteEngineRouteEngineActorImpl.java
@Override @Nonnull//from ww w .j a va2s. c om public Future<RouteEngineResponse> route(@Nonnull final GeoPoint from, @Nonnull final GeoPoint to, @Nullable final DateTime executeBefore) { assert from != null; assert to != null; // TODO ST-3: For as long as this is a route actor, we shall prevent crashing this actor at all cost. try { LOG.debug("route: {} Request, from={}, to={}, traffic={}", name, from, to, lbsProperties.isTrafficEnabled()); final DateTime now = UTCTime.now(); if ((executeBefore == null) || now.isBefore(executeBefore)) { final String url = getBaseQueryString(from, to); final TomTomLbsRouteEngineResponse lbsResponse; lbsResponse = executeLbsQuery(url); LOG.debug("route: {} Success, from={}, to={}, response={}", name, from, to, lbsResponse); final RouteEngineResponse routeEngineResponse = lbsResponse.convertToRouteEngineResponse(); return Futures.successful(routeEngineResponse); } else { final String message = "Expected execution before: " + executeBefore.toString(DATE_FORMAT) + " but started at: " + now.toString(DATE_FORMAT); LOG.debug("route: {} Too busy, from={}, to={}, {}", name, from, to, message); return Futures.failed(new TimeoutException(message)); } } catch (final AuthorizationException e) { return Futures.failed(e); } catch (final ServiceUnavailableException e) { return Futures.failed(e); } catch (final IOException e) { return Futures.failed(e); } catch (final Throwable e) { // Catch all to make sure the actor won't die and takes its parent down. return Futures.failed(new IllegalStateException(e)); } }