/** * @param spi SPI whose internal objects need to be injected. * @throws GridException If injection failed. */ private void cleanup(GridSpi spi) throws GridException { if (spi instanceof GridSpiAdapter) { Collection<Object> injectables = ((GridSpiAdapter)spi).injectables(); if (!F.isEmpty(injectables)) for (Object o : injectables) ctx.resource().cleanupGeneric(o); } }
/** * @param topic User topic. * @param predLsnr Predicate listener. * @throws GridException If failed to inject resources to predicates. */ GridUserMessageListener(@Nullable Object topic, @Nullable GridBiPredicate<UUID, Object> predLsnr) throws GridException { this.topic = topic; this.predLsnr = predLsnr; if (predLsnr != null) ctx.resource().injectGeneric(predLsnr); }
/** * @param dep Deployment. * @param target Target object. * @param annCls Annotation class. * @throws GridException If failed to execute annotated methods. */ public void invokeAnnotated(GridDeployment dep, Object target, Class<? extends Annotation> annCls) throws GridException { if (target != null) { Collection<Method> mtds = getMethodsWithAnnotation(dep, target.getClass(), annCls); if (mtds != null) { for (Method mtd : mtds) { try { mtd.setAccessible(true); mtd.invoke(target); } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { throw new GridException("Failed to invoke annotated method [job=" + target + ", mtd=" + mtd + ", ann=" + annCls + ']', e); } } } } }
/** * Injects held resources into given {@code job}. * * @param dep Deployment. * @param taskCls Task class. * @param job Grid job to inject resources to. * @param ses Current task session. * @param jobCtx Job context. * @throws GridException Thrown in case of any errors. */ public void inject(GridDeployment dep, Class<?> taskCls, GridComputeJob job, GridComputeTaskSession ses, GridJobContextImpl jobCtx) throws GridException { if (log.isDebugEnabled()) log.debug("Injecting resources: " + job); // Unwrap Proxy object. Object obj = unwrapTarget(unwrapJob(job)); injectToJob(dep, taskCls, obj, ses, jobCtx); if (obj instanceof GridInternalWrapper) { Object usrObj = ((GridInternalWrapper)obj).userObject(); if (usrObj != null) injectToJob(dep, taskCls, usrObj, ses, jobCtx); } }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. * @throws GridException If failed. */ private void prepare(GridCacheConfiguration cfg, @Nullable Object rsrc, boolean near) throws GridException { if (rsrc != null) { ctx.resource().injectGeneric(rsrc); ctx.resource().injectCacheName(rsrc, cfg.getName()); registerMbean(rsrc, cfg.getName(), near); } }
GridResourceProcessor rsrcProc = new GridResourceProcessor(ctx); rsrcProc.setSpringContext(rsrcCtx); for (GridLifecycleBean bean : cfg.getLifecycleBeans()) if (bean != null) rsrcProc.inject(bean);
/** * @param o Object to inject resources to. * @throws GridException If failure occurred while injecting resources. */ private void injectResources(@Nullable Object o) throws GridException { 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); } }
Object obj = unwrapTarget(task); injectBasicResource(obj, GridTaskSessionResource.class, ses, dep, taskCls); else if (annCls == GridLoadBalancerResource.class) injectBasicResource(obj, GridLoadBalancerResource.class, balancer, dep, taskCls); else if (annCls == GridTaskContinuousMapperResource.class) injectBasicResource(obj, GridTaskContinuousMapperResource.class, mapper, dep, taskCls); else if (annCls == GridInstanceResource.class) ioc.inject(obj, GridInstanceResource.class, gridInjector, dep, taskCls);
continuous = ctx.resource().isAnnotationPresent(dep, task, GridTaskContinuousMapperResource.class); ctx.resource().inject(dep, task, ses, balancer, mapper);
ctx.resource().invokeAnnotated(dep, jobRes.getJob(), GridComputeJobBeforeFailover.class);
/** * Stops wrapped SPI. * * @throws GridException If underlying SPI could not be stopped. */ protected final void stopSpi() throws GridException { for (T spi : spis) { if (log.isDebugEnabled()) log.debug("Stopping SPI: " + spi); try { spi.spiStop(); if (log.isDebugEnabled()) log.debug("SPI module stopped OK: " + spi.getClass().getName()); } catch (GridSpiException e) { throw new GridException("Failed to stop SPI: " + spi, e); } try { cleanup(spi); ctx.resource().cleanup(spi); } catch (GridException e) { U.error(log, "Failed to remove injected resources from SPI (ignoring): " + spi, e); } } }
for (Class<? extends Annotation> annCls : filtered) { if (annCls == GridTaskSessionResource.class) injectBasicResource(job, GridTaskSessionResource.class, ses, dep, taskCls); else if (annCls == GridJobContextResource.class) ioc.inject(job, GridJobContextResource.class, new GridResourceJobContextInjector(jobCtx),
/** {@inheritDoc} */ @Override public final void addSpiAttributes(Map<String, Object> attrs) throws GridException { for (T spi : spis) { // Inject all spi resources. ctx.resource().inject(spi); // Inject SPI internal objects. inject(spi); try { Map<String, Object> retval = spi.getNodeAttributes(); if (retval != null) { for (Map.Entry<String, Object> e : retval.entrySet()) { if (attrs.containsKey(e.getKey())) throw new GridException("SPI attribute collision for attribute [spi=" + spi + ", attr=" + e.getKey() + ']' + ". Attribute set by one SPI implementation has the same name (name collision) as " + "attribute set by other SPI implementation. Such overriding is not allowed. " + "Please check your GridGain configuration and/or SPI implementation to avoid " + "attribute name collisions."); attrs.put(e.getKey(), e.getValue()); } } } catch (GridSpiException e) { throw new GridException("Failed to get SPI attributes.", e); } } }
ctx.resource().invokeAnnotated(dep, jobRes.getJob(), GridComputeJobAfterSend.class);
ctx.resource().cleanup(cp);
/** * Injects resources into streamer components. * * @throws GridException If failed. */ private void prepareResources() throws GridException { for (GridStreamerStage s : c.getStages()) ctx.resource().injectGeneric(s); if (router == null) router = new GridStreamerLocalEventRouter(); ctx.resource().injectGeneric(router); for (GridStreamerWindow w : c.getWindows()) ctx.resource().injectGeneric(w); }
/** * @param cfg Cache configuration. * @param rsrc Resource. * @param near Near flag. */ private void cleanup(GridCacheConfiguration cfg, @Nullable Object rsrc, boolean near) { if (rsrc != null) { unregisterMbean(rsrc, cfg.getName(), near); try { ctx.resource().cleanupGeneric(rsrc); } catch (GridException e) { U.error(log, "Failed to cleanup resource: " + rsrc, e); } } }
/** * @param svc Service. * @return Copy of service. */ private GridService copyAndInject(GridService svc) { GridMarshaller m = ctx.config().getMarshaller(); try { byte[] bytes = m.marshal(svc); GridService cp = m.unmarshal(bytes, svc.getClass().getClassLoader()); ctx.resource().inject(cp); return cp; } catch (GridException e) { log.error("Failed to copy service (will reuse same instance): " + svc.getClass(), e); return svc; } }
", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); ctx.resource().invokeAnnotated(dep, res.getJob(), GridComputeJobAfterSend.class); ctx.resource().invokeAnnotated(dep, res.getJob(), GridComputeJobAfterSend.class);
/** * @param spi SPI whose internal objects need to be injected. * @throws GridException If injection failed. */ private void inject(GridSpi spi) throws GridException { if (spi instanceof GridSpiAdapter) { Collection<Object> injectables = ((GridSpiAdapter)spi).injectables(); if (!F.isEmpty(injectables)) for (Object o : injectables) ctx.resource().injectGeneric(o); } }