[java-support] branch main updated: JSPT-108 ServiceableComponent should implement AutoClose

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


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

rdw pushed a commit to branch main
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=511dbd813d257633a656f2911ee68556eb60968d

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

commit 511dbd813d257633a656f2911ee68556eb60968d
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Jul 22 15:22:44 2022 +0100

    JSPT-108 ServiceableComponent should implement AutoClose
    
    https://shibboleth.atlassian.net/browse/JSPT-108
---
 .../security/impl/DelegatingAccessControlService.java     |  9 ++-------
 .../java/support/service/ServiceableComponent.java        | 15 +++++++++++----
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/impl/DelegatingAccessControlService.java b/src/main/java/net/shibboleth/utilities/java/support/security/impl/DelegatingAccessControlService.java
index 5d76065..aaa2b7b 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/impl/DelegatingAccessControlService.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/impl/DelegatingAccessControlService.java
@@ -59,9 +59,8 @@ public class DelegatingAccessControlService extends AbstractIdentifiableInitiali
     @Override
     @Nonnull public AccessControl getInstance(@Nonnull final String name) {
         checkComponentActive();
-        ServiceableComponent<AccessControlService> component = null;
-        try {
-            component = service.getServiceableComponent();
+
+        try (final ServiceableComponent<AccessControlService> component = service.getServiceableComponent()){
             if (null == component) {
                 log.error("AccessControlService '{}': Error accessing underlying component: Invalid configuration.",
                         getId());
@@ -69,10 +68,6 @@ public class DelegatingAccessControlService extends AbstractIdentifiableInitiali
                 final AccessControlService svc = component.getComponent();
                 return svc.getInstance(name);
             }
-        } finally {
-            if (null != component) {
-                component.unpinComponent();
-            }
         }
 
         return new AccessControl() {
diff --git a/src/main/java/net/shibboleth/utilities/java/support/service/ServiceableComponent.java b/src/main/java/net/shibboleth/utilities/java/support/service/ServiceableComponent.java
index d290ee1..d9b1211 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/service/ServiceableComponent.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/service/ServiceableComponent.java
@@ -31,7 +31,7 @@ import javax.annotation.Nonnull;
  *  
  * @param <T> The underlying type of the component.
  */
-public interface ServiceableComponent<T> {
+public interface ServiceableComponent<T> extends AutoCloseable {
 
     /**
      * Extract the component that does the actual work.  Callers <em>MUST</em> have the ServiceableComponent
@@ -55,13 +55,20 @@ public interface ServiceableComponent<T> {
      * This undoes the work that is done by {@link #pinComponent()}.
      */
     void unpinComponent();
-    
 
     /**
      * This call will wait for all transient operations to complete and then
-     * calls dispose on the components.
+     * calls dispose/destroy on the component.
      *
      * <p>Implementations should avoid calling this with locks held.</p>
      */
     void unloadComponent();
-}
\ No newline at end of file
+
+    /** {@inheritDoc}
+     * Although this method is the same as {@link #unpinComponent()} this is targeted at places where
+     * {@link ReloadableService#getServiceableComponent()} was called.
+     */
+     default void close() {
+        unpinComponent();
+     }
+}

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


More information about the commits mailing list