List of usage examples for java.util.concurrent TimeoutException TimeoutException
public TimeoutException(String message)
From source file:com.ning.http.client.providers.apache.ApacheResponseFuture.java
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { V content = null;/*from w w w.jav a 2 s. c o m*/ try { if (innerFuture != null) { content = innerFuture.get(timeout, unit); } } catch (TimeoutException t) { if (!contentProcessed.get() && timeout != -1 && ((System.currentTimeMillis() - touch.get()) <= responseTimeoutInMs)) { return get(timeout, unit); } if (exception.get() == null) { timedOut.set(true); throw new ExecutionException( new TimeoutException(String.format("No response received after %s", responseTimeoutInMs))); } } catch (CancellationException ce) { } if (exception.get() != null) { throw new ExecutionException(exception.get()); } return content; }
From source file:org.asynchttpclient.providers.apache.ApacheResponseFuture.java
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { V content = null;/*from w ww . j a v a 2 s. c om*/ try { if (innerFuture != null) { content = innerFuture.get(timeout, unit); } } catch (TimeoutException t) { if (!contentProcessed.get() && timeout != -1 && ((millisTime() - touch.get()) <= responseTimeoutInMs)) { return get(timeout, unit); } if (exception.get() == null) { timedOut.set(true); throw new ExecutionException( new TimeoutException(String.format("No response received after %s", responseTimeoutInMs))); } } catch (CancellationException ce) { } if (exception.get() != null) { throw new ExecutionException(exception.get()); } return content; }
From source file:edu.biu.scapi.comm.twoPartyComm.SocketCommunicationSetup.java
/** * Initiates the creation of the actual sockets connections between the parties. If this function succeeds, the * application may use the send and receive functions of the created channels to pass messages. * @throws TimeoutException in case a timeout has occurred before all channels have been connected. *//*from w w w. j a v a 2 s .c o m*/ @Override public Map<String, Channel> prepareForCommunication(String[] connectionsIds, long timeOut) throws TimeoutException { //Start the watch dog with the given timeout. watchdog = new Watchdog(timeOut); //Add this instance as the observer in order to receive the event of time out. watchdog.addTimeoutObserver(this); watchdog.start(); //Establish the connections. establishConnections(connectionsIds); //Verify that all connections have been connected. connector.verifyConnectingStatus(); //If we already know that all the connections were established we can stop the watchdog. watchdog.stop(); //In case of timeout, throw a TimeoutException if (bTimedOut) { throw new TimeoutException("timeout has occurred"); } //Set Nagle algorithm. if (enableNagle) connector.enableNagle(); //Update the number of the created connections. connectionsNumber += connector.getConnectionsCount(); //Return the map of channels held in the established connection object. Map<String, Channel> connections = connector.getConnections(); connector.reset(); return connections; }
From source file:org.apache.pulsar.compaction.TwoPhaseCompactor.java
private void scheduleTimeout(CompletableFuture<RawMessage> future) { Future<?> timeout = scheduler.schedule(() -> { future.completeExceptionally(new TimeoutException("Timeout")); }, 10, TimeUnit.SECONDS);/* w w w.j a v a 2 s. c o m*/ future.whenComplete((res, exception) -> { timeout.cancel(true); }); }
From source file:org.apache.geode.internal.statistics.DiskSpaceLimitIntegrationTest.java
private void sampleUntilFileDeleted(final File file) throws InterruptedException, TimeoutException { long minutes = 1; long timeout = System.nanoTime() + MINUTES.toNanos(minutes); int count = 0; do {//ww w . j a va 2 s.c o m sample(advanceNanosTimeStamp()); count++; Thread.sleep(10); } while (file.exists() && System.nanoTime() < timeout); if (file.exists()) { throw new TimeoutException("File " + file + " does not exist after " + count + " samples within " + minutes + " " + MINUTES); } System.out.println("Sampled " + count + " times to delete " + file); }
From source file:com.streamsets.datacollector.cluster.ShellClusterProvider.java
@Override public void killPipeline(File tempDir, ApplicationState applicationState, PipelineConfiguration pipelineConfiguration, PipelineConfigBean pipelineConfigBean) throws TimeoutException, IOException { String appId = applicationState.getAppId(); Map<String, String> environment = new HashMap<>(); environment.put(CLUSTER_TYPE, CLUSTER_TYPE_YARN); addKerberosConfiguration(environment); ImmutableList.Builder<String> args = ImmutableList.builder(); args.add(clusterManagerScript.getAbsolutePath()); args.add("kill"); args.add(appId);/* ww w . j av a2 s .c o m*/ ExecutionMode executionMode = PipelineBeanCreator.get().getExecutionMode(pipelineConfiguration, new ArrayList<Issue>()); if (executionMode == ExecutionMode.CLUSTER_MESOS_STREAMING) { addMesosArgs(pipelineConfiguration, environment, args); } SystemProcess process = getSystemProcessFactory().create(BaseClusterProvider.class.getSimpleName(), tempDir, args.build()); try { process.start(environment); if (!process.waitFor(30, TimeUnit.SECONDS)) { throw new TimeoutException(errorString("Kill command for {} timed out.", appId)); } } finally { process.cleanup(); } }
From source file:org.apache.hadoop.hdfs.server.balancer.TestBalancerWithNodeGroup.java
/** * Wait until balanced: each datanode gives utilization within * BALANCE_ALLOWED_VARIANCE of average// w ww . j a va 2 s.co m * @throws IOException * @throws TimeoutException */ private void waitForBalancer(long totalUsedSpace, long totalCapacity) throws IOException, TimeoutException { long timeout = TIMEOUT; long failtime = (timeout <= 0L) ? Long.MAX_VALUE : System.currentTimeMillis() + timeout; final double avgUtilization = ((double) totalUsedSpace) / totalCapacity; boolean balanced; do { DatanodeInfo[] datanodeReport = client.getDatanodeReport(DatanodeReportType.ALL); assertEquals(datanodeReport.length, cluster.getDataNodes().size()); balanced = true; for (DatanodeInfo datanode : datanodeReport) { double nodeUtilization = ((double) datanode.getDfsUsed()) / datanode.getCapacity(); if (Math.abs(avgUtilization - nodeUtilization) > BALANCE_ALLOWED_VARIANCE) { balanced = false; if (System.currentTimeMillis() > failtime) { throw new TimeoutException("Rebalancing expected avg utilization to become " + avgUtilization + ", but on datanode " + datanode + " it remains at " + nodeUtilization + " after more than " + TIMEOUT + " msec."); } try { Thread.sleep(100); } catch (InterruptedException ignored) { } break; } } } while (!balanced); }
From source file:org.apache.hadoop.hdfs.server.datanode.TestDataNodeHotSwapVolumes.java
/** * Wait the block to have the exact number of replicas as expected. *//*www . j a v a2 s . com*/ private static void waitReplication(FileSystem fs, Path file, int blockIdx, int numReplicas) throws IOException, TimeoutException, InterruptedException { int attempts = 50; // Wait 5 seconds. while (attempts > 0) { int actualReplicas = getNumReplicas(fs, file, blockIdx); if (actualReplicas == numReplicas) { return; } System.out.printf("Block %d of file %s has %d replicas (desired %d).\n", blockIdx, file.toString(), actualReplicas, numReplicas); Thread.sleep(100); attempts--; } throw new TimeoutException("Timed out waiting the " + blockIdx + "-th block" + " of " + file + " to have " + numReplicas + " replicas."); }
From source file:com.appdirect.sdk.support.FakeAppmarket.java
public void waitForResolvedEvents(int desiredNumberOfResolvedEvents) throws Exception { long maxNumberOfTries = 100, timeoutOfOneTryMs = 50; synchronized (resolvedEventsLock) { int tries = 0; while (resolvedEvents.size() < desiredNumberOfResolvedEvents && tries < maxNumberOfTries) { tries++;//from w w w.j a va 2 s. co m resolvedEventsLock.wait(timeoutOfOneTryMs); } if (tries == maxNumberOfTries) { throw new TimeoutException( "Could not find " + desiredNumberOfResolvedEvents + " resolved event after trying for " + maxNumberOfTries * timeoutOfOneTryMs + "ms. | resolvedEvents: " + resolvedEvents); } } }
From source file:models.Application.java
/** * Verify whether an application is started by sending HTTP 'pings' for a specified time-out period * @throws TimeoutException Is thrown when the time-out period is expired *//*w w w .j av a2 s . com*/ private void checkApplicationIsRunning(final String url) throws InterruptedException, TimeoutException { int n = 0; int timeout = getCommandTimeout(); while (n < timeout) { try { final WSRequest request = WS.url(url); request.timeout("1s"); // low time-out so we make sure the time-out cycle is as long as we define it to be request.get(); break; } catch (RuntimeException e) { Thread.sleep(ONE_SECOND); n++; } } if (n == timeout) { throw new TimeoutException("Time-out value reached"); } }