Skip to content

Commit

Permalink
Cleanup related to CDI bean destruction
Browse files Browse the repository at this point in the history
Signed-off-by: Laird Nelson <[email protected]>
  • Loading branch information
ljnelson committed May 11, 2019
1 parent 3019cf4 commit 7243a8c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ public final Config create(final CreationalContext<Config> cc) {

@Override
public void destroy(final Config config, final CreationalContext<Config> cc) {
if (config != null) {
ConfigProviderResolver.instance().releaseConfig(config);
}
if (cc != null) {
cc.release();
try {
if (config != null) {
ConfigProviderResolver.instance().releaseConfig(config);
}
} finally {
if (cc != null) {
cc.release();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,23 @@ public final T create(final CreationalContext<T> context) {

@Override
public final void destroy(final T configurationValue, final CreationalContext<T> creationalContext) {

try {
if (configurationValue instanceof AutoCloseable) {
try {
((AutoCloseable)configurationValue).close();
} catch (final InterruptedException interruptedException) {
Thread.currentThread().interrupt();
} catch (final RuntimeException throwMe) {
throw throwMe;
} catch (final Exception exception) {
throw new RuntimeException(exception.getMessage(), exception);
}
}
} finally {
if (creationalContext != null) {
creationalContext.release();
}
}
}

@Override
Expand Down Expand Up @@ -227,7 +243,7 @@ private static final String getValue(final Config config, final InjectionPoint i
return returnValue;
}

private static class ConfigPropertyLiteral extends AnnotationLiteral<ConfigProperty> implements ConfigProperty {
private static final class ConfigPropertyLiteral extends AnnotationLiteral<ConfigProperty> implements ConfigProperty {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -256,52 +272,40 @@ private CurrentInjectionPoint(final Type type) {
}

@Override
public Type getType() {
public final Type getType() {
return this.type;
}

@Override
public Set<Annotation> getQualifiers() {
public final Set<Annotation> getQualifiers() {
return Collections.singleton(DefaultLiteral.INSTANCE);
}

@Override
public Bean<?> getBean() {
public final Bean<?> getBean() {
return null;
}

@Override
public Member getMember() {
public final Member getMember() {
return null;
}

@Override
public Annotated getAnnotated() {
public final Annotated getAnnotated() {
return null;
}

@Override
public boolean isDelegate() {
public final boolean isDelegate() {
return false;
}

@Override
public boolean isTransient() {
public final boolean isTransient() {
return false;
}

}

private static final class DefaultLiteral extends AnnotationLiteral<Default> implements Default {

private static final long serialVersionUID = 1L;

private static final Default INSTANCE = new DefaultLiteral();

private DefaultLiteral() {
super();
}

}

}

0 comments on commit 7243a8c

Please sign in to comment.