/** * Throws {@code IgniteCacheRestartingException} if proxy is restarting. */ public void checkRestart() { checkRestart(false); }
/** * @return Context or throw restart exception. */ private GridCacheContext<K, V> getContextSafe() { while (true) { GridCacheContext<K, V> ctx = this.ctx; if (ctx == null) { checkRestart(); if (Thread.currentThread().isInterrupted()) throw new IgniteException(new InterruptedException()); } else return ctx; } }
/** * @return Delegate or throw restart exception. */ private IgniteInternalCache<K, V> getDelegateSafe() { while (true) { IgniteInternalCache<K, V> delegate = this.delegate; if (delegate == null) { checkRestart(); if (Thread.currentThread().isInterrupted()) throw new IgniteException(new InterruptedException()); } else return delegate; } }
/** * @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. } }
/** * 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; }
/** * @return Internal proxy. */ @Override public GridCacheProxyImpl<K, V> internalProxy() { checkRestart(); return new GridCacheProxyImpl<>(ctx, delegate, ctx.operationContextPerCall()); }
((IgniteCacheProxyImpl) delegate).checkRestart();