/** * @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); } }
/** {@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); } } }
/** * @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; } }
ctx.resource().inject(ctx.deploy().getDeployment(c.getClass().getName()), c.getClass(), c);
ctx.resource().inject(ctx.deploy().getDeployment(c.getClass().getName()), c.getClass(), c);
ctx.resource().inject(dep, taskCls, job, ses, jobCtx);
/** * Unmarshalls transfer object from remote node within a given context. * * @param ctx Grid kernal context that provides deployment and marshalling services. * @param sndNodeId {@link UUID} of the sender node. * @param msg Transfer object that contains original serialized object and deployment information. * @return Unmarshalled object. * @throws GridException If node cannot obtain deployment. */ static Object unmarshall(GridKernalContext ctx, UUID sndNodeId, GridAffinityMessage msg) throws GridException { GridDeployment dep = ctx.deploy().getGlobalDeployment( msg.deploymentMode(), msg.sourceClassName(), msg.sourceClassName(), msg.userVersion(), sndNodeId, msg.classLoaderId(), msg.loaderParticipants(), null); if (dep == null) throw new GridDeploymentException("Failed to obtain affinity object (is peer class loading turned on?): " + msg); Object src = ctx.config().getMarshaller().unmarshal(msg.source(), dep.classLoader()); // Resource injection. ctx.resource().inject(dep, dep.deployedClass(msg.sourceClassName()), src); return src; }
ctx.resource().inject(dep, task, ses, balancer, mapper);
ctx.resource().inject(dep, dep.deployedClass(req.filterClassName()), filter);
for (GridLifecycleBean bean : cfg.getLifecycleBeans()) if (bean != null) rsrcProc.inject(bean);
ctx.resource().inject(dep, dep.deployedClass(ioMsg.deploymentClassName()), msgBody);