/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(field.getField(), target, resource((GridLoggerResource)field.getAnnotation(), target)); }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(mtd.getMethod(), target, resource((GridLoggerResource)mtd.getAnnotation(), target)); }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { assert dep != null; GridUserResource ann = (GridUserResource)mtd.getAnnotation(); if (mtd.getMethod().getParameterTypes().length != 1) throw new GridException("Method injection setter must have only one parameter: " + mtd.getMethod()); Class<?> rsrcCls = !ann.resourceClass().equals(Void.class) ? ann.resourceClass() : mtd.getMethod().getParameterTypes()[0]; String rsrcName = ann.resourceName(); GridResourceUtils.inject(mtd.getMethod(), target, getResource(dep, depCls, rsrcCls, rsrcName)); }
/** * Injects cache name into given object. * * @param obj Object. * @param cacheName Cache name to inject. * @throws GridException If failed to inject. */ public void injectCacheName(Object obj, String cacheName) throws GridException { assert obj != null; if (log.isDebugEnabled()) log.debug("Injecting cache name: " + obj); // Unwrap Proxy object. obj = unwrapTarget(obj); ioc.inject(obj, GridCacheNameResource.class, new GridResourceBasicInjector<>(cacheName), null, null); }
/** * This method is declared public as it is used from tests as well. * Note, that this method can be used only with unwrapped objects * (see {@link #unwrapTarget(Object)}). * * @param target Target object. * @param annCls Setter annotation. * @param rsrc Resource to inject. * @throws GridException If injection failed. */ public void injectBasicResource(Object target, Class<? extends Annotation> annCls, Object rsrc) throws GridException { // Safety. assert !(rsrc instanceof GridResourceInjector) : "Invalid injection."; // Basic injection don't cache anything. Use null as a key. ioc.inject(target, annCls, new GridResourceBasicInjector<>(rsrc), null, null); }
/** * @param springCtx Spring application context. */ public GridSpringResourceContextImpl(@Nullable ApplicationContext springCtx) { springCtxInjector = new GridResourceBasicInjector<>(springCtx); springBeanInjector = new GridResourceSpringBeanInjector(springCtx); }
@Override public Method apply(GridResourceMethod rsrcMtd) { return rsrcMtd.getMethod(); } });
/** * Sets Spring resource context. * * @param rsrcCtx Spring resource context. */ public void setSpringContext(@Nullable GridSpringResourceContext rsrcCtx) { this.rsrcCtx = rsrcCtx; springCtxInjector = rsrcCtx != null ? rsrcCtx.springContextInjector() : nullInjector; springBeanInjector = rsrcCtx != null ? rsrcCtx.springBeanInjector() : nullInjector; }
/** * Callback to be called when class loader is undeployed. * * @param dep Deployment to release resources for. */ public void onUndeployed(GridDeployment dep) { customInjector.undeploy(dep); ioc.onUndeployed(dep.classLoader()); }
/** * Cleanup object where resources was injected before. * * @param rsrc Object where resources should be cleaned. * @param annCls Annotation. */ private void cleanup(CachedResource rsrc, Class<? extends Annotation> annCls) { try { ioc.inject(rsrc.getResource(), annCls, nullInjector, null, null); } catch (GridException e) { U.error(log, "Failed to clean up resource [ann=" + annCls + ", rsrc=" + rsrc + ']', e); } }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws GridException { assert target != null; if (!(target instanceof GridComputeTask)) super.inject(field, target, depCls, dep); }
/** * Creates new bean. * * @param field Field where resource should be injected. * @param ann Resource annotation. */ GridResourceField(Field field, Annotation ann) { assert field != null; assert ann != null || GridResourceUtils.mayRequireResources(field); this.field = field; this.ann = ann; }
/** * Checks if annotation presents in specified object. * * @param dep Class deployment. * @param target Object to check. * @param annCls Annotation to find. * @return {@code true} if annotation is presented, {@code false} otherwise. */ public boolean isAnnotationPresent(GridDeployment dep, Object target, Class<? extends Annotation> annCls) { return ioc.isAnnotationPresent(target, annCls, dep); }
/** * Return original object if Spring AOP used with proxy objects. * * @param target Target object. * @return Original object wrapped by proxy. * @throws GridException If unwrap failed. */ private Object unwrapTarget(Object target) throws GridException { return rsrcCtx != null ? rsrcCtx.unwrapTarget(target) : target; }
/** * For tests only. * * @param cls Class for test. * @return {@code true} if cached, {@code false} otherwise. */ boolean isCached(Class<?> cls) { return isCached(cls.getName()); }
/** {@inheritDoc} */ @Override public void stop(boolean cancel) { ioc.undeployAll(); if (log.isDebugEnabled()) log.debug("Stopped resource processor."); }
/** * This method is declared public as it is used from tests as well. * Note, that this method can be used only with unwrapped objects * (see {@link #unwrapTarget(Object)}). * * @param target Target object. * @param annCls Setter annotation. * @param rsrc Resource to inject. * @param dep Deployment. * @param depCls Deployed class. * @throws GridException If injection failed. */ public void injectBasicResource(Object target, Class<? extends Annotation> annCls, Object rsrc, GridDeployment dep, Class<?> depCls) throws GridException { // Safety. assert !(rsrc instanceof GridResourceInjector) : "Invalid injection."; // Basic injection don't cache anything. Use null as a key. ioc.inject(target, annCls, new GridResourceBasicInjector<>(rsrc), dep, depCls); }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { assert target != null; if (!(target instanceof GridComputeTask)) super.inject(mtd, target, depCls, dep); } }