/** * @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); }
/** * 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. * @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); } }
/** * @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); } }
/** * @param dep Deployment to release. */ private void release(GridDeployment dep) { dep.release(); if (dep.obsolete()) ctx.resource().onUndeployed(dep); }
/** {@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 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); } }
/** * @param dep Deployment to release. */ private void release(GridDeployment dep) { assert dep != null; dep.release(); if (dep.obsolete()) ctx.resource().onUndeployed(dep); }
/** * @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 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; } }
if (dep.obsolete()) { ctx.resource().onUndeployed(dep);
/** * 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); } } }
ctx.resource().onUndeployed(this);
ggfsCtx.kernalContext().resource().injectGeneric(srvEndpoint);
ggfsCtx.kernalContext().resource().cleanupGeneric(srvEndpoint);
ggfsCtx.kernalContext().resource().cleanupGeneric(srvEndpoint);
ctx.resource().invokeAnnotated(dep, jobRes.getJob(), GridComputeJobBeforeFailover.class);
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; }