List of usage examples for java.util.concurrent TimeoutException TimeoutException
public TimeoutException()
From source file:com.android.volley.mock.WaitableQueue.java
public void waitUntilEmpty(long timeoutMillis) throws TimeoutException, InterruptedException { add(mStopRequest);/*from w w w . ja va 2s . c om*/ if (!mStopEvent.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS)) { throw new TimeoutException(); } }
From source file:de.quist.samy.remocon.RemoteSession.java
public static RemoteSession create(String applicationName, String uniqueId, String host, int port) throws IOException, ConnectionDeniedException, TimeoutException { RemoteSession session = new RemoteSession(applicationName, uniqueId, host, port); String result = session.initialize(); if (result.equals(ALLOWED)) { return session; } else if (result.equals(DENIED)) { throw new ConnectionDeniedException(); } else if (result.equals(TIMEOUT)) { throw new TimeoutException(); } else {//from ww w . j ava 2 s . com // for now we just assume to be connected return session; } }
From source file:Main.java
/** * If the given time (based on {@link System#currentTimeMillis}) has passed, throw a TimeoutException. * Otherwise, invoke {@link Object#wait(long)} on the given object, which may return due to * a {@code notify()} call, the timeout being reached, or a spurious wake-up. To distinguish between * these possibilities, clients should wrap this call in a while loop: * {@code long t = futureTimeMillis(...); while (!condition) waitUntilMillis(lock, t);} * This loop either completes if the condition is satisfied or throws an appropriate exception * due to an interrupt or timeout.// ww w. j a va 2s. c o m * @param obj Object whose {@code wait()} method will be invoked. Must be locked by the current thread. * @param futureTime A millisecond time value based on {@code System.currentTimeMillis()} after which * this method should no longer invoke {@code obj.wait()}. * @throws InterruptedException If the wait is interrupted. * @throws TimeoutException If, at invocation time, {@code futureTime} is in the past. * @see #futureTimeMillis */ public static void waitUntilMillis(Object obj, long futureTime) throws InterruptedException, TimeoutException { long delta = futureTime - System.currentTimeMillis(); if (delta > 0) { obj.wait(delta); } else { throw new TimeoutException(); } }
From source file:Main.java
/** * If the given time (based on {@link System#nanoTime}) has passed, throw a TimeoutException. * Otherwise, invoke {@link Object#wait(long, int)} on the given object, which may return due to * a {@code notify()} call, the timeout being reached, or a spurious wake-up. To distinguish between * these possibilities, clients should wrap this call in a while loop: * {@code long t = futureTimeNanos(...); while (!condition) waitUntilNanos(lock, t);} * This loop either completes if the condition is satisfied or throws an appropriate exception * due to an interrupt or timeout./*from w ww . j a v a2s .c om*/ * @param obj Object whose {@code wait()} method will be invoked. Must be locked by the current thread. * @param futureTime A nanosecond time value based on {@code System.nanoTime()} after which * this method should no longer invoke {@code obj.wait()}. * @throws InterruptedException If the wait is interrupted. * @throws TimeoutException If, at invocation time, {@code futureTime} is in the past. * @see #futureTimeNanos */ public static void waitUntilNanos(Object obj, long futureTime) throws InterruptedException, TimeoutException { long delta = futureTime - System.nanoTime(); if (delta > 0) { TimeUnit.NANOSECONDS.timedWait(obj, delta); } else { throw new TimeoutException(); } }
From source file:io.vertigo.dynamo.impl.search.WritableFuture.java
/** {@inheritDoc} */ @Override// w ww .j a va2s.c o m public synchronized V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Assertion.checkNotNull(unit, "Time unit was null"); //----- final long msecs = unit.toMillis(timeout); final long startTime = msecs <= 0 ? 0 : System.currentTimeMillis(); long waitTime = msecs; if (this.completed) { return getResult(); } else if (waitTime <= 0) { throw new TimeoutException(); } else { for (;;) { wait(waitTime); if (this.completed) { return getResult(); } waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) { throw new TimeoutException(); } } } }
From source file:org.nuxeo.ecm.automation.elasticsearch.ElasticsearchWaitForIndexingOperation.java
@OperationMethod public Boolean run() { long start = System.currentTimeMillis(); WorkManager workManager = Framework.getService(WorkManager.class); try {/*from w ww .j a v a 2s. c o m*/ if (!workManager.awaitCompletion(timeout, TimeUnit.SECONDS)) { throw new TimeoutException(); } esa.prepareWaitForIndexing().get(computeRemainingTime(start), TimeUnit.SECONDS); } catch (TimeoutException e) { return Boolean.FALSE; } catch (InterruptedException e) { return Boolean.FALSE; } catch (ExecutionException e) { return Boolean.FALSE; } if (refresh) { esa.refreshRepositoryIndex(repo.getRepositoryName()); } return Boolean.TRUE; }
From source file:com.ocean.common.concurrent.ext.BasicFuture.java
@Override public synchronized T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Validate.notNull(unit, "Time unit"); final long msecs = unit.toMillis(timeout); final long startTime = (msecs <= 0) ? 0 : System.currentTimeMillis(); long waitTime = msecs; if (this.completed) { return getResult(); } else if (waitTime <= 0) { throw new TimeoutException(); } else {//from ww w .j av a 2 s .co m for (;;) { wait(waitTime); if (this.completed) { return getResult(); } else { waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) { throw new TimeoutException(); } } } } }
From source file:no.sintef.ict.splcatool.CoveringArrayChvatal.java
@Override public void generate(int coverLimit, Integer sizelimit) throws TimeoutException { if (t == 1) { try {/*from w ww .ja va 2 s . c o m*/ generate1(coverLimit, sizelimit); } catch (org.sat4j.specs.TimeoutException e) { throw new TimeoutException(); } } else if (t == 2) { generate2(coverLimit, sizelimit); } else if (t == 3) { generate3(coverLimit, sizelimit); } else if (t == 4) { generate4(coverLimit, sizelimit); } else throw new UnsupportedOperationException(); }
From source file:no.sintef.ict.splcatool.CoveringArrayAlgICPL.java
@Override public void generate(int coverLimit, Integer sizelimit) throws TimeoutException { if (t == 1) { try {//from w w w. ja v a2s. c om generate1(coverLimit, sizelimit); } catch (org.sat4j.specs.TimeoutException e) { throw new TimeoutException(); } } else if (t == 2) { try { generate2(coverLimit, sizelimit); } catch (org.sat4j.specs.TimeoutException e) { throw new TimeoutException(); } } else if (t == 3) { try { generate3(coverLimit, sizelimit); } catch (org.sat4j.specs.TimeoutException e) { throw new TimeoutException(); } } else throw new UnsupportedOperationException(); }
From source file:org.resthub.rpc.AMQPProxy.java
/** * Handles the object invocation.//from w w w.j a v a 2 s . co 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; } AMQPProxy handler = (AMQPProxy) 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(); Message response = sendRequest(connectionFactory, method, args); if (response == null) { throw new TimeoutException(); } MessageProperties props = response.getMessageProperties(); boolean compressed = "deflate".equals(props.getContentEncoding()); InputStream is = new ByteArrayInputStream(response.getBody()); if (compressed) { is = new InflaterInputStream(is, new Inflater(true)); } return _factory.getSerializationHandler().readObject(method.getReturnType(), is); }