/** * @param opCtx Operation context to guard. * @return Previous operation context set on this thread. */ @Nullable public CacheOperationContext enterNoLock(@Nullable CacheOperationContext opCtx) { onEnter(opCtx); checkState(false, false); return setOperationContextPerCall(opCtx); }
/** * @param gate Cache gateway. * @return {@code True} if enter successful. */ private boolean onEnterIfNoStop(@Nullable GridCacheGateway<K, V> gate) { try { checkProxyIsValid(gate, false); } catch (Exception e) { return false; } return lock ? gate.enterIfNotStopped() : gate.enterIfNotStoppedNoLock(); }
/** * @param gate Cache gateway. */ private void onLeave(GridCacheGateway<K, V> gate) { if (lock) gate.leave(); else gate.leaveNoLock(); }
/** * Enter a cache call without lock. * * @return {@code True} if enter successful, {@code false} if the cache or the node was stopped. */ public boolean enterIfNotStoppedNoLock() { onEnter(null); return checkState(false, false); }
/** * @return Previous projection set on this thread. */ private CacheOperationGate onEnter() { GridCacheGateway<K, V> gate = checkProxyIsValid(gate(), true); try { return new CacheOperationGate(gate, lock ? gate.enter(opCtx) : gate.enterNoLock(opCtx)); } catch (IllegalStateException e) { boolean isCacheProxy = delegate instanceof IgniteCacheProxyImpl; if (isCacheProxy) ((IgniteCacheProxyImpl) delegate).checkRestart(true); throw e; // If we reached this line. } }
@Override public Object applyx() throws IgniteCheckedException { IgniteInternalCache<GridCacheInternalKey, AtomicDataStructureValue> cache = ctx.cache().cache(cacheName); if (cache != null && cache.context().gate().enterIfNotStopped()) { boolean isInterrupted = Thread.interrupted(); cache.context().gate().leave();
/** * @param prev Previous. */ public void leave(CacheOperationContext prev) { try { leaveNoLock(prev); } finally { rwLock.readLock().unlock(); } }
/** * */ public boolean isStopped() { return !checkState(false, false); }
/** * @param opCtx Cache operation context. */ private void onEnter(CacheOperationContext opCtx) { ctx.itHolder().checkWeakQueue(); if (ctx.deploymentEnabled()) ctx.deploy().onEnter(); if (opCtx != null) checkAtomicOpsInTx(opCtx); }
/** * Checks that proxy is in valid state (not closed, restarted or destroyed). * Throws IllegalStateException or CacheRestartingException if proxy is in invalid state. * * @param gate Cache gateway. */ private GridCacheGateway<K, V> checkProxyIsValid(@Nullable GridCacheGateway<K, V> gate, boolean tryRestart) { if (isProxyClosed()) throw new IllegalStateException("Cache has been closed: " + context().name()); boolean isCacheProxy = delegate instanceof IgniteCacheProxyImpl; if (isCacheProxy) ((IgniteCacheProxyImpl) delegate).checkRestart(); if (gate == null) throw new IllegalStateException("Gateway is unavailable. Probably cache has been destroyed, but proxy is not closed."); if (isCacheProxy && tryRestart && gate.isStopped() && context().kernalContext().gateway().getState() == GridKernalState.STARTED) { IgniteCacheProxyImpl proxyImpl = (IgniteCacheProxyImpl) delegate; try { IgniteInternalCache<K, V> cache = context().kernalContext().cache().<K, V>publicJCache(context().name()).internalProxy(); proxyImpl.opportunisticRestart(cache); return gate(); } catch (IgniteCheckedException ice) { // Opportunity didn't work out. } } return gate; }
gate = new GridCacheGateway<>(this);
/** * @param opGate Operation context to guard. */ private void onLeave(CacheOperationGate opGate) { if (lock) opGate.gate.leave(opGate.prev); else opGate.gate.leaveNoLock(opGate.prev); }
/** * Enter a cache call. * * @return {@code True} if enter successful, {@code false} if the cache or the node was stopped. */ public boolean enterIfNotStopped() { onEnter(null); // Must unlock in case of unexpected errors to avoid deadlocks during kernal stop. rwLock.readLock().lock(); return checkState(true, false); }
/** * @return Previous projection set on this thread. */ private CacheOperationGate onEnter() { GridCacheGateway<K, V> gate = checkProxyIsValid(gate(), true); return new CacheOperationGate(gate, lock ? gate.enter(opCtx) : gate.enterNoLock(opCtx)); }
@Override public Object applyx() throws IgniteCheckedException { IgniteInternalCache<GridCacheInternalKey, AtomicDataStructureValue> cache = ctx.cache().cache(cacheName); if (cache != null && cache.context().gate().enterIfNotStopped()) { boolean isInterrupted = Thread.interrupted(); cache.context().gate().leave();
/** * Leave a cache call entered by {@link #enter()} method. */ public void leave() { try { leaveNoLock(); } finally { rwLock.readLock().unlock(); } }
/** * Enter a cache call. */ public void enter() { if (ctx.deploymentEnabled()) ctx.deploy().onEnter(); rwLock.readLock().lock(); checkState(true, true); }
/** * @param opCtx Cache operation context. */ private void onEnter(CacheOperationContext opCtx) { ctx.itHolder().checkWeakQueue(); if (ctx.deploymentEnabled()) ctx.deploy().onEnter(); if (opCtx != null) checkAtomicOpsInTx(opCtx); }
throw new IllegalStateException("Gateway is unavailable. Probably cache has been destroyed, but proxy is not closed."); if (isCacheProxy && tryRestart && gate.isStopped() && context().kernalContext().gateway().getState() == GridKernalState.STARTED) { IgniteCacheProxyImpl proxyImpl = (IgniteCacheProxyImpl) delegate;