Skip to content

Commit

Permalink
add NoAutoStartUtil.shouldBeStarted method
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Mar 2, 2024
1 parent 40bc1c2 commit 6998e81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package ch.qos.logback.core.joran.spi;

import ch.qos.logback.core.spi.LifeCycle;

public class NoAutoStartUtil {

/**
Expand All @@ -23,12 +25,23 @@ public class NoAutoStartUtil {
* @return true for classes not marked with the NoAutoStart annotation
*/
static public boolean notMarkedWithNoAutoStart(Object o) {
if (o == null) {
return false;
}
Class<?> clazz = o.getClass();
NoAutoStart a = clazz.getAnnotation(NoAutoStart.class);
return a == null;
}

/**
* Is the object a {@link LifeCycle} and is it marked not marked with
* the NoAutoStart annotation.
* @param o
* @return
* @ since 1.5.2
*/
static public boolean shouldBeStarted(Object o) {
if(o instanceof LifeCycle) {
return notMarkedWithNoAutoStart(o);
} else
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ private void postHandleComplex(ModelInterpretationContext mic, Model model,
// start the nested complex property if it implements LifeCycle and is not
// marked with a @NoAutoStart annotation
Object nestedComplexProperty = imdComplex.getNestedComplexProperty();
if (nestedComplexProperty instanceof LifeCycle
&& NoAutoStartUtil.notMarkedWithNoAutoStart(nestedComplexProperty)) {
if (NoAutoStartUtil.shouldBeStarted(nestedComplexProperty)) {
((LifeCycle) nestedComplexProperty).start();
}

Expand Down

0 comments on commit 6998e81

Please sign in to comment.