Skip to content

Commit

Permalink
Remove Initializable iface
Browse files Browse the repository at this point in the history
  • Loading branch information
ogesaku committed May 9, 2024
1 parent 5a41033 commit 78b17d7
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 46 deletions.
13 changes: 0 additions & 13 deletions src/main/java/com/coditory/quark/context/BeanInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ private BeanInitializer() {
}

static void initializeBean(Object bean, BeanDescriptor<?> descriptor, ResolutionContext context) {
if (bean instanceof Initializable) {
initializeBean((Initializable) bean, descriptor);
}
for (Method method : bean.getClass().getDeclaredMethods()) {
if (method.isAnnotationPresent(Init.class)) {
method.setAccessible(true);
Expand All @@ -38,14 +35,4 @@ private static void initializeBean(Object bean, BeanDescriptor<?> descriptor, Me
}
log.debug("Initialized bean {} using method {} in {}", descriptor.toShortString(), simplifyMethodName(method), timer.measureAndFormat());
}

private static void initializeBean(Initializable bean, BeanDescriptor<?> descriptor) {
Timer timer = Timer.start();
try {
bean.init();
} catch (Exception e) {
throw new BeanInitializationException("Could not initialize bean: " + descriptor.toShortString(), e);
}
log.debug("Initialized bean {} in {}", descriptor.toShortString(), timer.measureAndFormat());
}
}
13 changes: 0 additions & 13 deletions src/main/java/com/coditory/quark/context/BeanPostInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ private BeanPostInitializer() {
}

static void postInitializeBean(Object bean, BeanDescriptor<?> descriptor, ResolutionContext context) {
if (bean instanceof PostInitializable) {
postInitializeBean((PostInitializable) bean, descriptor);
}
for (Method method : bean.getClass().getDeclaredMethods()) {
if (method.isAnnotationPresent(PostInit.class)) {
method.setAccessible(true);
Expand All @@ -38,14 +35,4 @@ private static void postInitializeBean(Object bean, BeanDescriptor<?> descriptor
}
log.debug("Post initialized bean {} using method {} in {}", descriptor.toShortString(), simplifyMethodName(method), timer.measureAndFormat());
}

private static void postInitializeBean(PostInitializable bean, BeanDescriptor<?> descriptor) {
Timer timer = Timer.start();
try {
bean.postInit();
} catch (Exception e) {
throw new BeanInitializationException("Could not post initialize bean: " + descriptor.toShortString(), e);
}
log.debug("Post initialized bean {} in {}", descriptor.toShortString(), timer.measureAndFormat());
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/coditory/quark/context/Initializable.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class BeanLifecycleSpec extends Specification {
when:
LifecycleImplemented lifecycleImplemented = context.get(LifecycleImplemented)
then:
lifecycleImplemented.initialized
!lifecycleImplemented.finalized
}

Expand Down Expand Up @@ -57,7 +56,6 @@ class BeanLifecycleSpec extends Specification {
context.close()
then:
lifecycleAnnotated.initialized
lifecycleImplemented.initialized
}

def "should not initialize lazy beans that were not retrieved from the context"() {
Expand All @@ -73,7 +71,6 @@ class BeanLifecycleSpec extends Specification {
context.close()
then:
!lifecycleAnnotated.initialized
!lifecycleImplemented.initialized
}

def "should inject dependencies to lifecycle annotated methods"() {
Expand Down Expand Up @@ -146,15 +143,9 @@ class BeanLifecycleSpec extends Specification {
}
}

static class LifecycleImplemented implements Initializable, Closeable {
boolean initialized = false
static class LifecycleImplemented implements Closeable {
boolean finalized = false

@Override
void init() {
initialized = true
}

@Override
void close() {
finalized = true
Expand Down

0 comments on commit 78b17d7

Please sign in to comment.