/** * Wraps EntryProcessor if needed. * * @param ctx Context. * @param proc Entry proc. * @return Wrapped entry proc if wrapping is needed. */ public static <K, V, T> EntryProcessor<K, V, T> wrap(GridKernalContext ctx, @Nullable EntryProcessor<K, V, T> proc) { if (proc == null || proc instanceof EntryProcessorResourceInjectorProxy) return proc; GridResourceProcessor rsrcProcessor = ctx.resource(); return rsrcProcessor.isAnnotationsPresent(null, proc, GridResourceIoc.AnnotationSet.ENTRY_PROCESSOR) ? new EntryProcessorResourceInjectorProxy<>(proc) : proc; }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. * @throws IgniteCheckedException If failed. */ private void prepare(CacheConfiguration cfg, @Nullable Object rsrc, boolean near) throws IgniteCheckedException { if (rsrc != null) { ctx.resource().injectGeneric(rsrc); ctx.resource().injectCacheName(rsrc, cfg.getName()); registerMbean(rsrc, cfg.getName(), near); } }
/** * Injects resources to SPI. * * @throws IgniteCheckedException If failed. */ protected void inject() throws IgniteCheckedException { if (injected) return; for (T spi : spis) { // Inject all spi resources. ctx.resource().inject(spi); // Inject SPI internal objects. inject(spi); } injected = true; }
/** {@inheritDoc} */ @Override public RegisterStatus register(UUID nodeId, UUID routineId, GridKernalContext ctx) throws IgniteCheckedException { final IgniteClosure trans = getTransformer(); if (trans != null) ctx.resource().injectGeneric(trans); if (locTransLsnr != null) { ctx.resource().injectGeneric(locTransLsnr); asyncCb = U.hasAnnotation(locTransLsnr, IgniteAsyncCallback.class); } return super.register(nodeId, routineId, ctx); }
/** * @param dep Deployment to release. */ private void release(GridDeployment dep) { assert dep != null; dep.release(); if (dep.obsolete()) ctx.resource().onUndeployed(dep); }
/** * @param o Object to inject resources to. * @throws IgniteCheckedException If failure occurred while injecting resources. */ private void injectResources(@Nullable Object o) throws IgniteCheckedException { if (o != null) { GridKernalContext ctx = cctx.kernalContext(); ClassLoader ldr = o.getClass().getClassLoader(); if (ctx.deploy().isGlobalLoader(ldr)) ctx.resource().inject(ctx.deploy().getDeployment(ctx.deploy().getClassLoaderId(ldr)), o.getClass(), o); else ctx.resource().inject(ctx.deploy().getDeployment(o.getClass().getName()), o.getClass(), o); } }
/** * @param dep Deployment to release. */ private void release(GridDeployment dep) { dep.release(); if (dep.obsolete()) ctx.resource().onUndeployed(dep); }
/** * @param spi SPI whose internal objects need to be injected. * @throws IgniteCheckedException If injection failed. */ private void inject(IgniteSpi spi) throws IgniteCheckedException { if (spi instanceof IgniteSpiAdapter) { Collection<Object> injectables = ((IgniteSpiAdapter)spi).injectables(); if (!F.isEmpty(injectables)) for (Object o : injectables) ctx.resource().injectGeneric(o); } }
/** * @param spi SPI whose internal objects need to be injected. * @throws IgniteCheckedException If injection failed. */ private void cleanup(IgniteSpi spi) throws IgniteCheckedException { if (spi instanceof IgniteSpiAdapter) { Collection<Object> injectables = ((IgniteSpiAdapter)spi).injectables(); if (!F.isEmpty(injectables)) for (Object o : injectables) ctx.resource().cleanupGeneric(o); } }
/** * Performs injections and MBean registration. * * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. * @throws IgniteCheckedException If failed. */ private void prepare(CacheConfiguration cfg, @Nullable Object rsrc, boolean near) throws IgniteCheckedException { cctx.kernalContext().resource().injectGeneric(rsrc); cctx.kernalContext().resource().injectCacheName(rsrc, cfg.getName()); registerMbean(rsrc, cfg.getName(), near); }
/** * Injects the Ignite. * * @param ignite Ignite. */ @SuppressWarnings("unused") @IgniteInstanceResource public void setIgnite(Ignite ignite) throws IgniteCheckedException { this.ignite = ignite; if (baseFunc != null && ignite != null) ((IgniteEx)ignite).context().resource().injectGeneric(baseFunc); } }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. */ private void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near) { if (rsrc != null) { unregisterMbean(rsrc, cfg.getName(), near); try { ctx.resource().cleanupGeneric(rsrc); } catch (IgniteCheckedException e) { U.error(log, "Failed to cleanup resource: " + rsrc, e); } } }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. */ void cleanup(CacheConfiguration cfg, @Nullable Object rsrc, boolean near) { if (rsrc != null) { unregisterMbean(rsrc, cfg.getName(), near); try { cctx.kernalContext().resource().cleanupGeneric(rsrc); } catch (IgniteCheckedException e) { U.error(log, "Failed to cleanup resource: " + rsrc, e); } } }
/** * Adds local user event listener. * * @param lsnr User listener to add. * @param types Event types to subscribe listener for. */ public void addLocalEventListener(IgnitePredicate<? extends Event> lsnr, int[] types) { assert lsnr != null; try { ctx.resource().injectGeneric(lsnr); } catch (IgniteCheckedException e) { throw new IgniteException("Failed to inject resources to event listener: " + lsnr, e); } addEventListener(new UserListenerWrapper(lsnr), types); }
/** {@inheritDoc} */ @Override protected VisorContentionJobResult run(@Nullable VisorContentionTaskArg arg) throws IgniteException { try { ContentionClosure clo = new ContentionClosure(arg.minQueueSize(), arg.maxPrint()); ignite.context().resource().injectGeneric(clo); ContentionInfo info = clo.call(); return new VisorContentionJobResult(info); } catch (Exception e) { throw new IgniteException(e); } }
/** {@inheritDoc} */ @Override protected VisorValidateIndexesJobResult run(@Nullable VisorValidateIndexesTaskArg arg) throws IgniteException { try { ValidateIndexesClosure clo = new ValidateIndexesClosure(arg.getCaches(), arg.getCheckFirst(), arg.getCheckThrough()); ignite.context().resource().injectGeneric(clo); return clo.call(); } catch (Exception e) { throw new IgniteException(e); } }
/** {@inheritDoc} */ @Override protected VisorViewCacheTaskResult run(@Nullable VisorViewCacheTaskArg arg) throws IgniteException { try { ViewCacheClosure clo = new ViewCacheClosure(arg.regex(), arg.command()); ignite.context().resource().injectGeneric(clo); return new VisorViewCacheTaskResult(clo.call()); } catch (Exception e) { throw new IgniteException(e); } }
/** {@inheritDoc} */ @Override public T process(MutableEntry<K, V> entry, Object... arguments) throws EntryProcessorException { if (!injected) { GridCacheContext cctx = entry.unwrap(GridCacheContext.class); GridResourceProcessor rsrc = cctx.kernalContext().resource(); try { rsrc.inject(delegate, GridResourceIoc.AnnotationSet.ENTRY_PROCESSOR, cctx.name()); } catch (IgniteCheckedException e) { throw new IgniteException(e); } injected = true; } return delegate.process(entry, arguments); }
/** {@inheritDoc} */ @Override public ClusterGroup forPredicate(IgnitePredicate<ClusterNode> p) { A.notNull(p, "p"); guard(); try { if (p != null) ctx.resource().injectGeneric(p); return new ClusterGroupAdapter(ctx, subjId, this.p != null ? F.and(p, this.p) : p); } catch (IgniteCheckedException e) { throw U.convertException(e); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public ClusterGroup forPredicate(IgnitePredicate<ClusterNode> p) { A.notNull(p, "p"); guard(); try { if (p != null) ctx.resource().injectGeneric(p); return new ClusterGroupAdapter(ctx, this.subjId, new GroupPredicate(this, p)); } catch (IgniteCheckedException e) { throw U.convertException(e); } finally { unguard(); } }