/** * Sleeps for given number of milliseconds. * * @param ms Time to sleep. * @throws GridInterruptedException Wrapped {@link InterruptedException}. */ public static void sleep(long ms) throws GridInterruptedException { try { Thread.sleep(ms); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Acquires a permit from provided semaphore. * * @param sem Semaphore. * @throws GridInterruptedException Wrapped {@link InterruptedException}. */ public static void acquire(Semaphore sem) throws GridInterruptedException { try { sem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Awaits for condition. * * @param cond Condition to await for. * @throws GridInterruptedException Wrapped {@link InterruptedException} */ public static void await(Condition cond) throws GridInterruptedException { try { cond.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Await for that worker batch to complete. * * @throws GridException In case any exception has occurred during batch tasks processing. */ void await() throws GridException { try { completeLatch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } GridException err0 = err; if (err0 != null) throw err0; }
/** * Joins thread. * * @param t Thread. * @throws GridInterruptedException Wrapped {@link InterruptedException}. */ public static void join(Thread t) throws GridInterruptedException { try { t.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Await for that worker batch to complete. * * @throws GridException In case any exception has occurred during batch tasks processing. */ void await() throws GridException { try { completeLatch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } GridException err0 = err; if (err0 != null) throw err0; }
/** * Converts {@link InterruptedException} to {@link GridException}. * * @param mux Mux to wait on. * @throws GridInterruptedException If interrupted. */ @SuppressWarnings({"WaitNotInLoop", "WaitWhileNotSynced"}) public static void wait(Object mux) throws GridInterruptedException { try { mux.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Tries to acquire asynchronous operations permit, if limited. * * @return Failed future if waiting was interrupted. */ @Nullable protected <T> GridFuture<T> asyncOpAcquire() { try { if (asyncOpsSem != null) asyncOpsSem.acquire(); return null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); return new GridFinishedFutureEx<>(new GridInterruptedException("Failed to wait for asynchronous " + "operation permit (thread got interrupted).", e)); } }
/** * Awaits for condition. * * @param cond Condition to await for. * @param time The maximum time to wait, * @param unit The unit of the {@code time} argument. * @return {@code false} if the waiting time detectably elapsed before return from the method, else {@code true} * @throws GridInterruptedException Wrapped {@link InterruptedException} */ public static boolean await(Condition cond, long time, TimeUnit unit) throws GridInterruptedException { try { return cond.await(time, unit); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Awaits for the latch. * * @param latch Latch to wait for. * @throws GridInterruptedException Wrapped {@link InterruptedException}. */ public static void await(CountDownLatch latch) throws GridInterruptedException { try { if (latch.getCount() > 0) latch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Joins worker. * * @param w Worker. * @throws GridInterruptedException Wrapped {@link InterruptedException}. */ public static void join(GridWorker w) throws GridInterruptedException { try { if (w != null) w.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * Gets holder from pool or thread local. * * @return Stream holder. * @throws GridInterruptedException If thread is interrupted while trying to take holder from pool. */ private static StreamHolder holder() throws GridInterruptedException { StreamHolder holder = holders.get(); if (holder == null) { try { holders.set(holder = pool != null ? pool.take() : new StreamHolder()); } catch (InterruptedException e) { throw new GridInterruptedException("Failed to take object stream from pool (thread interrupted).", e); } } return holder; }
/** {@inheritDoc} */ @Override public void store(byte[] dataCenterIds, byte[] data) throws GridException { try { buf.add(new DrEntry(dataCenterIds, data), evictC); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** {@inheritDoc} */ @Override public R get(long timeout, TimeUnit unit) throws IOException, GridException { A.ensure(timeout >= 0, "timeout cannot be negative: " + timeout); A.notNull(unit, "unit"); try { return get0(unit.toNanos(timeout)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException("Got interrupted while waiting for future to complete.", e); } }
/** {@inheritDoc} */ @Override public R get(long timeout, TimeUnit unit) throws GridException { A.ensure(timeout >= 0, "timeout cannot be negative: " + timeout); A.notNull(unit, "unit"); checkValid(); try { return get0(unit.toNanos(timeout)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException("Got interrupted while waiting for future to complete.", e); } }
/** {@inheritDoc} */ @Override public R get(long timeout, TimeUnit unit) throws GridException { A.ensure(timeout >= 0, "timeout cannot be negative: " + timeout); A.notNull(unit, "unit"); checkValid(); try { return get0(unit.toNanos(timeout)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException("Got interrupted while waiting for future to complete.", e); } }
/** {@inheritDoc} */ @Override public R get() throws IOException, GridException { try { if (endTime == 0) acquireSharedInterruptibly(0); if (getState() == CANCELLED) throw new GridFutureCancelledException("Future was cancelled: " + this); if (err != null) throw U.cast(err); return res; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** {@inheritDoc} */ @Override public R get() throws GridException { checkValid(); try { if (endTime == 0) acquireSharedInterruptibly(0); if (getState() == CANCELLED) throw new GridFutureCancelledException("Future was cancelled: " + this); if (err != null) throw U.cast(err); return res; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** * @param key Removed key. * @param ver Removed version. * @throws GridException If failed. */ public void onDeferredDelete(K key, GridCacheVersion ver) throws GridException { try { T2<K, GridCacheVersion> evicted = rmvQueue.add(new T2<>(key, ver)); if (evicted != null) cctx.dht().removeVersionedEntry(evicted.get1(), evicted.get2()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } }
/** {@inheritDoc} */ @SuppressWarnings( {"LockAcquiredButNotSafelyReleased"}) @Override public void onKernalStop() { if (log.isDebugEnabled()) log.debug("DHT preloader onKernalStop callback."); cctx.events().removeListener(discoLsnr); // Acquire write busy lock. busyLock.writeLock().lock(); // Finish all exchange futures. for (GridDhtPartitionsExchangeFuture<K, V> f : exchFuts.values()) f.onDone(new GridInterruptedException("Grid is stopping: " + cctx.gridName())); if (supplyPool != null) supplyPool.stop(); if (demandPool != null) demandPool.stop(); top = null; exchFuts = null; }