[spring-extensions] branch main updated: JSPT-108 ServiceableComponent should implement AutoClose

Rod Widdowson rdw at steadingsoftware.com
Fri Jul 22 15:25:51 UTC 2022


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository spring-extensions.

View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=24bb2fe4ded1a70ad78e273281b6eb02af0b18b4

The following commit(s) were added to refs/heads/main by this push:
     new 24bb2fe  JSPT-108 ServiceableComponent should implement AutoClose
24bb2fe is described below

commit 24bb2fe4ded1a70ad78e273281b6eb02af0b18b4
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Jul 22 16:24:10 2022 +0100

    JSPT-108 ServiceableComponent should implement AutoClose
    
    https://shibboleth.atlassian.net/browse/JSPT-108
    
    Take advantage of AutoClose.
    Add explanatory comment to ReloadableSpringService about appContext
    life times
---
 .../net/shibboleth/ext/spring/config/ReloadableScope.java     |  5 +----
 .../net/shibboleth/ext/spring/factory/ProxiedFactoryBean.java | 11 ++++-------
 .../ext/spring/service/ReloadableSpringService.java           |  3 ++-
 .../ext/spring/service/ReloadableBeanServiceTest.java         |  6 +-----
 4 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/src/main/java/net/shibboleth/ext/spring/config/ReloadableScope.java b/src/main/java/net/shibboleth/ext/spring/config/ReloadableScope.java
index 27259ac..afdd0f5 100644
--- a/src/main/java/net/shibboleth/ext/spring/config/ReloadableScope.java
+++ b/src/main/java/net/shibboleth/ext/spring/config/ReloadableScope.java
@@ -60,11 +60,8 @@ public class ReloadableScope implements Scope {
     /** {@inheritDoc} */
     public Object get(final String name, final ObjectFactory<?> objectFactory) {
         log.debug("Accessing reloadable bean instance '{}'", name);
-        final ServiceableComponent<ApplicationContext> component = reloadableService.getServiceableComponent();
-        try {
+        try (final ServiceableComponent<ApplicationContext> component = reloadableService.getServiceableComponent()) {
             return component.getComponent().getBean(name);
-        } finally {
-            component.unpinComponent();
         }
     }
 
diff --git a/src/main/java/net/shibboleth/ext/spring/factory/ProxiedFactoryBean.java b/src/main/java/net/shibboleth/ext/spring/factory/ProxiedFactoryBean.java
index 737f022..02eb247 100644
--- a/src/main/java/net/shibboleth/ext/spring/factory/ProxiedFactoryBean.java
+++ b/src/main/java/net/shibboleth/ext/spring/factory/ProxiedFactoryBean.java
@@ -112,12 +112,11 @@ public class ProxiedFactoryBean<T> extends AbstractFactoryBean<T> {
     @Override
     protected T createInstance() throws Exception {
         
-        final ServiceableComponent<ApplicationContext> component = contextService.getServiceableComponent();
-        if (component == null) {
-            throw new BeanCreationException("ApplicationContext not available");
-        }
+        try (final ServiceableComponent<ApplicationContext> component = contextService.getServiceableComponent()) {
+            if (component == null) {
+                throw new BeanCreationException("ApplicationContext not available");
+            }
         
-        try {
             if (beanName != null) {
                 try {
                     final T bean = component.getComponent().getBean(beanName, beanType); 
@@ -137,8 +136,6 @@ public class ProxiedFactoryBean<T> extends AbstractFactoryBean<T> {
             }
             
             return component.getComponent().getBean(beanType);
-        } finally {
-            component.unpinComponent();
         }
     }
    
diff --git a/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java b/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java
index d754d62..cd9ed40 100644
--- a/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java
+++ b/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java
@@ -353,11 +353,12 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
     /** {@inheritDoc} */
     @Override protected void doReload() {
         super.doReload();
-
         log.debug("{} Creating new ApplicationContext for service '{}'", getLogPrefix(), getId());
         log.debug("{} Reloading from {}", getLogPrefix(), getServiceConfigurations());
         final GenericApplicationContext appContext;
         try {
+            // Ignore the AutoClosable warning.  This appContext is passed to the
+            // ServiceableComponent which takes care of the closing bit.
             appContext = new ApplicationContextBuilder()
                 .setName(getId()).setParentContext(getParentContext())
                 .setServiceConfigurations(getServiceConfigurations())
diff --git a/src/test/java/net/shibboleth/ext/spring/service/ReloadableBeanServiceTest.java b/src/test/java/net/shibboleth/ext/spring/service/ReloadableBeanServiceTest.java
index 484948e..235d49f 100644
--- a/src/test/java/net/shibboleth/ext/spring/service/ReloadableBeanServiceTest.java
+++ b/src/test/java/net/shibboleth/ext/spring/service/ReloadableBeanServiceTest.java
@@ -31,7 +31,6 @@ import org.springframework.core.io.Resource;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
- at SuppressWarnings("javadoc")
 public class ReloadableBeanServiceTest {
 
     @Test public void reloadableService() throws IOException, InterruptedException {
@@ -49,11 +48,8 @@ public class ReloadableBeanServiceTest {
             final ReloadableService<ApplicationContext> embedded =
                     appCtx.getBean("reloadableBeanService", ReloadableService.class);
             
-            final ServiceableComponent<ApplicationContext> component = embedded.getServiceableComponent();
-            try {
+            try (final ServiceableComponent<ApplicationContext> component = embedded.getServiceableComponent()) {
                 Assert.assertFalse(component.getComponent().containsLocalBean("reloadableBeanService"));
-            } finally {
-                component.unpinComponent();
             }
             
             embedded.reload();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list