public void lockWithException(long timeout) { if (lock(timeout)) return; throw new TimeoutRuntimeException(name); }
public void waitWithException(long timeout) { if (waitUntilUnlock(timeout)) return; throw new TimeoutRuntimeException(name); }
public static <T extends Object> T waitFor(Class<? extends T> ifc, long timeout) { long start = System.currentTimeMillis(); while (true) { try { T api = lookup(ifc); if (api != null) // should not happen return api; } catch (Throwable t) {} if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException("timeout getting API",ifc); MThread.sleep(500); } }
/** * Wait for the checker to return true or throw an TimeoutRuntimeException on timeout. * * @param checker * @param timeout * @throws Exception Thrown if checker throws an exception */ public static void waitForWithException( final Checker checker, long timeout) throws Exception { long start = System.currentTimeMillis(); while (true) { try { if (checker.check()) return; } catch (Throwable t) { throw t; } if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200); } }
@Override public void run() { while (true) { try { T val = provider.getValue(); if (nullAllowed || val != null) { value.value = val; return; } } catch (Throwable t) {} if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200); } } });
/** * Wait for the checker to return true or throw an TimeoutRuntimeException on timeout. A exception * in the checker will be ignored. * * @param checker * @param timeout */ public static void waitFor( final Checker checker, long timeout) { long start = System.currentTimeMillis(); while (true) { try { if (checker.check()) return; } catch (Throwable t) { } if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200); } }
/** * Try every 200ms to get the value. If the provider throws an error or return null * the try will be repeated. If the time out is reached a TimeoutRuntimeException * will be thrown. * * @param provider * @param timeout * @param nullAllowed * @return The requested value */ public static <T> T getWithTimeout( final ValueProvider<T> provider, long timeout, boolean nullAllowed) { long start = System.currentTimeMillis(); while (true) { try { T val = provider.getValue(); if (nullAllowed || val != null) return val; } catch (Throwable t) {} if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200); } }
/** * Try every 200ms to get the value. If the provider throws an error or return null * the try will be repeated. If the time out is reached a TimeoutRuntimeException * will be thrown. * * @param provider * @param timeout * @param nullAllowed * @return The requested value */ public static <T> T getWithTimeout( ValueProvider<T> provider, long timeout, boolean nullAllowed) { long start = System.currentTimeMillis(); while (true) { try { T val = provider.getValue(); if (nullAllowed || val != null) return val; } catch (Throwable t) {} if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200); } }
if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200); t.start(); while (t.isAlive()) { if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200);
throw new TimeoutRuntimeException(key); MThread.sleep(sleepTime );
/** {@inheritDoc} */ @Override public void lock(long timeout) throws TimeoutRuntimeException { if (objects == null) throw new NotSupportedException("Transaction already gone"); if (manager == null) throw new NotSupportedException("DbManager not found, need direct manager or DbObject implementation to grep the manager"); LockStrategy strategy = manager.getSchema().getLockStrategy(); if (strategy == null) return; getLockKeys(); long start = System.currentTimeMillis(); for (Map.Entry<String, Persistable> entry : orderedKeys.entrySet()) { try { strategy.lock(entry.getValue(), entry.getKey(), this, timeout); } catch (Throwable t) {log().d(t);} if (System.currentTimeMillis() - start > timeout) { for (Map.Entry<String, Persistable> entry2 : orderedKeys.entrySet()) { try { strategy.releaseLock(entry2.getValue(), entry2.getKey(), this); } catch (Throwable t) {log().d(t);} } throw new TimeoutRuntimeException(); } } locked = true; }
t.start(); while (t.isAlive()) { if (System.currentTimeMillis() - start > timeout) throw new TimeoutRuntimeException(); sleep(200);
throw new TimeoutRuntimeException(key); MThread.sleep(sleepTime );