/** * 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); } }
/** * Attempts to failover pipeline execution. * * @param fut Future. */ private void failover(GridStreamerStageExecutionFuture fut) { assert fut.rootExecution(); assert fut.error() != null; if (fut.failoverAttemptCount() >= c.getMaximumFailoverAttempts() || stopping) { // Release semaphore when no failover will be attempted anymore. if (sem != null) sem.release(); notifyFailure(fut.stageName(), fut.events(), fut.error()); } else { try { addEvents0(null, fut.failoverAttemptCount() + 1, 0, null, Collections.singleton(ctx.localNodeId()), fut.stageName(), fut.events()); } catch (GridInterruptedException e) { e.printStackTrace(); assert false : "Failover submit should never attempt to acquire semaphore: " + fut + ']'; } } }
return new GridTuple3<>(spec.host(), false, e.getMessage());
/** * 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); } }
/** * 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); } }
/** * 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 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); } }
/** * Awaits for the latch. * * @param latch Latch to wait for. * @param timeout Maximum time to wait. * @param unit Time unit for timeout. * @return {@code True} if the count reached zero and {@code false} * if the waiting time elapsed before the count reached zero. * @throws GridInterruptedException Wrapped {@link InterruptedException}. */ public static boolean await(CountDownLatch latch, long timeout, TimeUnit unit) throws GridInterruptedException { try { return latch.await(timeout, unit); } 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); } }
/** * Awaits either until snapshot is ready or timeout elapses. * * @param timeout Timeout to wait. * @throws GridInterruptedException If wait was interrupted. */ public synchronized void awaitReady(long timeout) throws GridInterruptedException { long start = System.currentTimeMillis(); try { while (!ready()) { long now = System.currentTimeMillis(); if (start + timeout - now <= 0) return; wait(start + timeout - now); } } 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); } }
/** * @param fut Future. * @return Future result. * @throws GridException If failed. */ private static int get(Future<Integer> fut) throws GridException { try { return fut.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } catch (ExecutionException e) { if (e.getCause() instanceof ClosedChannelException) throw new NoDataException(e); throw new GridException(e); } }
/** * Gets result from the given future with right exception handling. * * @param fut Future. * @return Future result. * @throws GridException If failed. */ public static <T> T get(Future<T> fut) throws GridException { try { return fut.get(); } catch (ExecutionException e) { throw new GridException(e.getCause()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new GridInterruptedException(e); } catch (CancellationException e) { throw new GridException(e); } }