List of usage examples for java.util.concurrent TimeoutException TimeoutException
public TimeoutException()
From source file:com.highcharts.export.util.SVGCreator.java
public static int executeCommandLine(final String commandLine, final long timeout) throws IOException, InterruptedException, TimeoutException { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(commandLine); Worker worker = new Worker(process); worker.start();//from w w w . j a v a2s . co m try { worker.join(timeout); if (worker.exit != null) return worker.exit; else throw new TimeoutException(); } catch (InterruptedException ex) { worker.interrupt(); Thread.currentThread().interrupt(); throw ex; } finally { process.destroy(); } }
From source file:com.armeniopinto.stress.control.sensorimotor.SensorimotorAgent.java
public synchronized Response sendCommand(final Request command) throws SensorimotorException { try {//from w w w .jav a 2s.com return executor.submit(() -> { synchronized (responseHolder) { sender.send(command); responseHolder.wait(timeout); final Response response = responseHolder.getValue(); if (response != null) { responseHolder.setValue(null); return response; } else { throw new TimeoutException(); } } }).get(); } catch (final InterruptedException | ExecutionException e) { throw new SensorimotorException( String.format("Failed to run sensorimotor command: %s", command.toString()), e); } }
From source file:ch.petikoch.examples.mvvm_rxjava.TestingClock.java
private void checkTimeout(long timeoutMs, Stopwatch stopWatch) throws TimeoutException { if (stopWatch.elapsed(TimeUnit.MILLISECONDS) >= timeoutMs) { throw new TimeoutException(); }/*from w w w. ja va 2 s . c om*/ }
From source file:org.xbmc.kore.testhelpers.action.ViewActions.java
/** * ViewAction that waits until view with viewId becomes visible * @param viewId Resource identifier of view item that must be checked * @param checkStatus called when viewId has been found to check its status. If return value * is true waitForView will stop, false it will continue until timeout is exceeded * @param millis amount of time to wait for view to become visible * @return//from w w w .ja v a 2 s. com */ public static ViewAction waitForView(final int viewId, final CheckStatus checkStatus, final long millis) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isRoot(); } @Override public String getDescription() { return "Searches for view with id: " + viewId + " and tests its status using CheckStatus, using timeout " + millis + " ms."; } @Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); final long endTime = System.currentTimeMillis() + millis; do { for (View child : TreeIterables.breadthFirstViewTraversal(view)) { if (child.getId() == viewId) { if (checkStatus.check(child)) { return; } } } uiController.loopMainThreadForAtLeast(50); } while (System.currentTimeMillis() < endTime); throw new PerformException.Builder().withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()) .build(); } }; }
From source file:com.vmware.photon.controller.rootscheduler.SchedulerDcpHostTest.java
private void waitForServicesStartup(SchedulerDcpHost host) throws TimeoutException, InterruptedException, NoSuchFieldException, IllegalAccessException { serviceSelfLinks = ServiceHostUtils.getServiceSelfLinks( SchedulerDcpHost.FACTORY_SERVICE_FIELD_NAME_SELF_LINK, SchedulerDcpHost.FACTORY_SERVICES); final CountDownLatch latch = new CountDownLatch(serviceSelfLinks.size()); Operation.CompletionHandler handler = (operation, throwable) -> { latch.countDown();/*from w ww. jav a2 s .c om*/ }; String[] links = new String[serviceSelfLinks.size()]; host.registerForServiceAvailability(handler, serviceSelfLinks.toArray(links)); if (!latch.await(10, TimeUnit.SECONDS)) { throw new TimeoutException(); } }
From source file:com.android.volley.toolbox.RequestFuture.java
private synchronized T doGet(Long timeoutMs) throws InterruptedException, ExecutionException, TimeoutException { if (mException != null) { throw new ExecutionException(mException); }//from w ww. j a v a2 s . c om if (mResultReceived) { return mResult; } if (timeoutMs == null) { wait(0); } else if (timeoutMs > 0) { wait(timeoutMs); } if (mException != null) { throw new ExecutionException(mException); } if (!mResultReceived) { throw new TimeoutException(); } return mResult; }
From source file:org.resthub.rpc.AMQPHessianProxy.java
/** * Handles the object invocation./*from w ww . j a v a 2s.c o m*/ * * @param proxy the proxy object to invoke * @param method the method to call * @param args the arguments to the proxy object */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); Class<?>[] params = method.getParameterTypes(); // equals and hashCode are special cased if (methodName.equals("equals") && params.length == 1 && params[0].equals(Object.class)) { Object value = args[0]; if (value == null || !Proxy.isProxyClass(value.getClass())) { return Boolean.FALSE; } AMQPHessianProxy handler = (AMQPHessianProxy) Proxy.getInvocationHandler(value); return _factory.equals(handler._factory); } else if (methodName.equals("hashCode") && params.length == 0) { return _factory.hashCode(); } else if (methodName.equals("toString") && params.length == 0) { return "[HessianProxy " + proxy.getClass() + "]"; } ConnectionFactory connectionFactory = _factory.getConnectionFactory(); try { Message response = sendRequest(connectionFactory, method, args); if (response == null) { throw new TimeoutException(); } MessageProperties props = response.getMessageProperties(); boolean compressed = "deflate".equals(props.getContentEncoding()); AbstractHessianInput in; InputStream is = new ByteArrayInputStream(response.getBody()); if (compressed) { is = new InflaterInputStream(is, new Inflater(true)); } int code = is.read(); if (code == 'H') { int major = is.read(); int minor = is.read(); in = _factory.getHessian2Input(is); return in.readReply(method.getReturnType()); } else if (code == 'r') { int major = is.read(); int minor = is.read(); in = _factory.getHessianInput(is); in.startReplyBody(); Object value = in.readObject(method.getReturnType()); in.completeReply(); return value; } else { throw new HessianProtocolException("'" + (char) code + "' is an unknown code"); } } catch (HessianProtocolException e) { throw new HessianRuntimeException(e); } }
From source file:com.vmware.photon.controller.rootscheduler.xenon.SchedulerServiceGroupTest.java
private void waitForServicesStartup(PhotonControllerXenonHost host) throws TimeoutException, InterruptedException, NoSuchFieldException, IllegalAccessException { boolean isReady = false; for (int i = 0; i < 10; i++) { if (host.isReady()) { isReady = true;// w ww . j a v a 2s . c o m } else { try { Thread.sleep(1000); } catch (Exception e) { // do nothing, we will throw a timeout exception anyway } } } if (!isReady) { throw new TimeoutException(); } }
From source file:org.openo.nfvo.jujuvnfmadapter.common.LocalComandUtils.java
/** * <br/>//from www . j a v a2 s . c om * * @param er * @param p * @param timeout millis * @throws TimeoutException * @throws InterruptedException * @since NFVO 0.5 */ private static void buildProcessResult(ExeRes er, Process p, long timeout) throws TimeoutException, InterruptedException { Worker worker = new Worker(p); worker.start(); try { worker.join(timeout); if (worker.exitValue != null) { int exit = worker.exitValue; if (exit != 0) { er.setCode(ExeRes.FAILURE); log.warn("the process exit non-normal"); } else { er.setCode(ExeRes.SUCCESS); } } else { er.setCode(ExeRes.FAILURE); log.warn("the process execute timeout."); throw new TimeoutException(); } } catch (InterruptedException e) { worker.interrupt(); Thread.currentThread().interrupt(); throw e; } }
From source file:org.diorite.impl.scheduler.DioriteFuture.java
@Override public synchronized T get(long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { timeout = unit.toMillis(timeout);//from w ww . j a v a2s .c o m long period = this.getPeriod(); long timestamp = (timeout > 0) ? System.currentTimeMillis() : 0; while (true) { if ((period == STATE_SINGLE) || (period == STATE_FUTURE)) { this.wait(timeout); period = this.getPeriod(); if ((period == -STATE_SINGLE) || (period == STATE_FUTURE)) { if (timeout == 0) { continue; } timeout += timestamp - (timestamp = System.currentTimeMillis()); if (timeout > 0) { continue; } throw new TimeoutException(); } } if (period == -STATE_CANCEL) { throw new CancellationException(); } if (period == STATE_FUTURE_DONE) { if (this.exception == null) { return this.value; } throw new ExecutionException(this.exception); } throw new IllegalStateException("Expected from -1 to -4, but got " + period); } }