/** * Await initialization. */ void awaitInit() { try { metaCacheStartLatch.await(); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } }
/** * */ void awaitInit() { try { dataCacheStartLatch.await(); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } }
/** * @param e Future result exception. * @return Unwrapped exception. */ private IgniteException unwrapFutureException(Exception e) { assert e instanceof InterruptedException || e instanceof ExecutionException : "Expecting either InterruptedException " + "or ExecutionException"; if (e instanceof InterruptedException) return new IgniteInterruptedException((InterruptedException)e); else if (e.getCause() instanceof IgniteException) return (IgniteException)e.getCause(); else return new IgniteException(e.getCause()); } }
/** * Acquire table lock. * * @param exclusive Exclusive flag. */ @SuppressWarnings({"LockAcquiredButNotSafelyReleased", "CallToThreadYield"}) private void lock(boolean exclusive) { Lock l = exclusive ? lock.writeLock() : lock.readLock(); try { if (!exclusive || !GridMapQueryExecutor.FORCE_LAZY) l.lockInterruptibly(); else { for (;;) { if (l.tryLock(200, TimeUnit.MILLISECONDS)) break; else Thread.yield(); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Thread got interrupted while trying to acquire table lock.", e); } }
/** * @param exec Striped executor. * @param applyError Check error reference. */ private void awaitApplyComplete( StripedExecutor exec, AtomicReference<IgniteCheckedException> applyError ) throws IgniteCheckedException { if (applyError.get() != null) throw applyError.get(); // Fail-fast check. else { try { // Await completion apply tasks in all stripes. exec.awaitComplete(); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } // Checking error after all task applied. if (applyError.get() != null) throw applyError.get(); } }
@Override public void run() { try { poolThreadLatch.await(); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } } });
/** {@inheritDoc} */ @Nullable @Override public T take() throws IgniteException { while (true) { try { readSem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue take interrupted.", e); } checkStopping(); T e = poll(); if (e != null) return e; } }
/** Check if lock is in correct state (i.e. not broken in non-failoversafe mode), * if not throw {@linkplain IgniteInterruptedException} */ private void validate(final boolean throwInterrupt) { // Interrupted flag shouldn't be always cleared // (e.g. lock() method doesn't throw exception and doesn't clear interrupted) // but should be cleared if this method is called after lock breakage or node stop. // If interruptAll is set, exception is thrown anyway. boolean interrupted = Thread.currentThread().isInterrupted(); // Clear interrupt flag. if (throwInterrupt || interruptAll) Thread.interrupted(); if (interruptAll) throw new IgniteException("Lock broken (possible reason: node stopped" + " or node owning lock failed while in non-failoversafe mode)."); // Global queue should be synchronized only if interrupted exception should be thrown. if (fair && (throwInterrupt && interrupted) && !interruptAll) { synchronizeQueue(true, Thread.currentThread()); throw new IgniteInterruptedException("Lock is interrupted."); } }
@Override public IgniteException apply(IgniteCheckedException e) { return new IgniteInterruptedException(e.getMessage(), (InterruptedException)e.getCause()); } });
@Override public void run() { arrive.countDown(); try { arrive.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException(e); } } }, true);
throw new IgniteInterruptedException(e);
/** {@inheritDoc} */ @Nullable @Override public T poll(long timeout, TimeUnit unit) throws IgniteException { A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout); long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit); while (U.currentTimeMillis() < end) { T retVal = null; try { if (readSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) { checkStopping(); retVal = poll(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue poll interrupted.", e); } if (retVal != null) return retVal; } return null; }
/** {@inheritDoc} */ @Override public void put(T item) throws IgniteException { A.notNull(item, "item"); if (!bounded()) { boolean offer = offer(item); assert offer; return; } while (true) { try { writeSem.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue put interrupted.", e); } checkStopping(); if (offer(item)) return; } }
/** * @param nodeId Node ID. * @return {@code True} if node joined or joining topology. */ public boolean knownNode(UUID nodeId) { while (!busyLock.enterBusy()) checkState(); try { List<String> children = rtState.zkClient.getChildren(zkPaths.aliveNodesDir); for (int i = 0; i < children.size(); i++) { UUID id = ZkIgnitePaths.aliveNodeId(children.get(i)); if (nodeId.equals(id)) return true; } return false; } catch (ZookeeperClientFailedException e) { if (clientReconnectEnabled) throw new IgniteClientDisconnectedException(null, "Client is disconnected."); throw new IgniteException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException(e); } finally { busyLock.leaveBusy(); } }
@Override public void run() { try { startLatch.await(); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } try { modifyData(jdbcTx()); } catch (SQLException e) { throw new IgniteException(e); } endLatch.countDown(); } }).get();
throw new IgniteInterruptedException((InterruptedException)e); else if (e.getCause() instanceof IgniteException) throw (IgniteException)e.getCause();
/** {@inheritDoc} */ @Override public boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException { A.notNull(item, "item"); A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout); if (!bounded()) { boolean offer = offer(item); assert offer; return true; } long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit); while (U.currentTimeMillis() < end) { boolean retVal = false; try { if (writeSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) { checkStopping(); retVal = offer(item); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IgniteInterruptedException("Queue put interrupted.", e); } if (retVal) return true; } return false; }
/** {@inheritDoc} */ @Override public boolean tryAcquire(long timeout, TimeUnit unit) throws IgniteException { ctx.kernalContext().gateway().readLock(); try { initializeSemaphore(); boolean res = sync.tryAcquireSharedNanos(1, unit.toNanos(timeout)); if (isBroken()) { Thread.interrupted(); // Clear interrupt flag. throw new InterruptedException(); } return res; } catch (IgniteCheckedException e) { throw U.convertException(e); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } finally { ctx.kernalContext().gateway().readUnlock(); } }
throw new IgniteInterruptedException((InterruptedException)e); else throw new IgniteException(e.getCause());
/** {@inheritDoc} */ @Override public boolean tryAcquire(int permits, long timeout, TimeUnit unit) throws IgniteInterruptedException { ctx.kernalContext().gateway().readLock(); A.ensure(permits >= 0, "Number of permits must be non-negative."); try { initializeSemaphore(); boolean res = sync.tryAcquireSharedNanos(permits, unit.toNanos(timeout)); if (isBroken()) { Thread.interrupted(); throw new InterruptedException(); } return res; } catch (IgniteCheckedException e) { throw U.convertException(e); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } finally { ctx.kernalContext().gateway().readUnlock(); } }