Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,11 @@ private void cleanup(Object obj, GridResourceIoc.AnnotationSet annSet)
if (clsDesc.isAnnotated(annSet) == 0)
return;

for (GridResourceIoc.ResourceAnnotation ann : annSet.annotations)
clsDesc.inject(obj, ann, nullInjector, null, null);
for (GridResourceIoc.ResourceAnnotation ann : annSet.annotations) {
// We should not nullify loggers for prevention of NPEs at grid workers.
if (ann != GridResourceIoc.ResourceAnnotation.LOGGER)
clsDesc.inject(obj, ann, nullInjector, null, null);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* <li>{@link org.apache.ignite.lifecycle.LifecycleBean}</li>
* </ul>
* <p>
* <b>WARNING:</b> unlike other injectable resources, logger resources won't be cleaned on node stop!
* <p>
* Here is how injection would typically happen:
* <pre name="code" class="java">
* public class MyGridJob implements ComputeJob {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,63 @@ public void testInjectResourceInnerClasses() throws Exception {
assertEquals(testStr, outer.str7);
}

/** */
private static class TestClassWithGenericAnnotationSet {
/** */
@IgniteInstanceResource
private Ignite ignite;

/** */
private Ignite igniteBySetter;

/** */
@LoggerResource
private IgniteLogger log;

/** */
private IgniteLogger logBySetter;

/**
* @param ignite Ignite instance.
*/
@IgniteInstanceResource
public void setIgniteBySetter(Ignite ignite) {
igniteBySetter = ignite;
}

/**
* @param log Logger instance.
*/
@LoggerResource
public void setLogBySetter(IgniteLogger log) {
logBySetter = log;
}
}

/**
* @throws Exception If failed.
*/
@Test
public void testInjectAndCleanupGenericAnnotationSet() throws Exception {
TestClassWithGenericAnnotationSet target = new TestClassWithGenericAnnotationSet();

ctx.resource().injectGeneric(target);

assertNotNull(target.ignite);
assertNotNull(target.igniteBySetter);
assertNotNull(target.log);
assertNotNull(target.logBySetter);

ctx.resource().cleanupGeneric(target);

assertNull(target.ignite);
assertNull(target.igniteBySetter);

// Logger instances shouldn't be cleaned.
assertNotNull(target.log);
assertNotNull(target.logBySetter);
}

/**
* Test task.
*/
Expand Down