[java-shib-shared] branch main updated: JSSH-5 ServiceableComponent should implement AutoClose
Rod Widdowson
rdw at steadingsoftware.com
Fri Sep 30 10:00:41 UTC 2022
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=16bab306b8209960bf0de1e3ee10ff7944f6b541
The following commit(s) were added to refs/heads/main by this push:
new 16bab306 JSSH-5 ServiceableComponent should implement AutoClose
16bab306 is described below
commit 16bab306b8209960bf0de1e3ee10ff7944f6b541
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Sep 30 10:50:13 2022 +0100
JSSH-5 ServiceableComponent should implement AutoClose
https://shibboleth.atlassian.net/browse/JSSH-5
ServiceableComponent no long requires pin, unpin or unload
---
.../shared/service/ReloadableService.java | 5 ++--
.../shared/service/ServiceableComponent.java | 32 +++-------------------
.../impl/ReloadingAccessControlService.java | 2 +-
.../service/AbstractServiceableComponent.java | 19 ++++++++-----
.../spring/service/ReloadableSpringService.java | 2 +-
.../service/ReloadableSpringServiceTest.java | 2 +-
.../shared/testing/MockReloadableService.java | 5 ++--
7 files changed, 24 insertions(+), 43 deletions(-)
diff --git a/shib-service/src/main/java/net/shibboleth/shared/service/ReloadableService.java b/shib-service/src/main/java/net/shibboleth/shared/service/ReloadableService.java
index 11fb6e81..331324f6 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/service/ReloadableService.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/service/ReloadableService.java
@@ -64,9 +64,8 @@ public interface ReloadableService<T> extends InitializableComponent {
/**
* Get the serviceable component that this service supports. If the component hasn't been successfully
* loaded yet or if this service does not support a ServiceableComponent, null is returned. On a non-null
- * value, the returned component will be pinned and <em>MUST</em> be unpinned. This can be done
- * by exploting the fact that a ServiceableComponent implements {@link AutoCloseable} or explicitly via
- * a call to {@link ServiceableComponent#unpinComponent()}
+ * value, the returned component will be pinned and <em>MUST</em> be closed. This can be done
+ * by exploiting the fact that a ServiceableComponent implements {@link AutoCloseable}
*
* @return the component, if appropriate.
*/
diff --git a/shib-service/src/main/java/net/shibboleth/shared/service/ServiceableComponent.java b/shib-service/src/main/java/net/shibboleth/shared/service/ServiceableComponent.java
index 1854fb35..b9262e75 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/service/ServiceableComponent.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/service/ServiceableComponent.java
@@ -17,6 +17,8 @@
package net.shibboleth.shared.service;
+import java.io.IOException;
+
import javax.annotation.Nonnull;
/**
@@ -41,34 +43,8 @@ public interface ServiceableComponent<T> extends AutoCloseable {
*/
@Nonnull T getComponent();
- /**
- * This function takes a lock on the component which guarantees that it will not be disposed until the unpin call
- * is made.
- *
- * <p>This method is typically <em>only</em> used during initialization of the component.</p>
- *
- * <p><em>Every call to {@link #pinComponent()} must be matched by a call to {@link #unpinComponent()}</em>.</p>
- */
- void pinComponent();
-
- /**
- * 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/destroy on the component.
- *
- * <p>Implementations should avoid calling this with locks held.</p>
- */
- void unloadComponent();
-
/** {@inheritDoc}
- * Although this method is the same as {@link #unpinComponent()} this is targeted at places where
- * {@link ReloadableService#getServiceableComponent()} was called.
+ * Note that this is explicitly declared to <em>not</em> throw an {@link IOException}
*/
- default void close() {
- unpinComponent();
- }
+ void close();
}
diff --git a/shib-service/src/main/java/net/shibboleth/shared/service/security/impl/ReloadingAccessControlService.java b/shib-service/src/main/java/net/shibboleth/shared/service/security/impl/ReloadingAccessControlService.java
index d9592819..5de357ab 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/service/security/impl/ReloadingAccessControlService.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/service/security/impl/ReloadingAccessControlService.java
@@ -63,5 +63,5 @@ public class ReloadingAccessControlService extends AbstractServiceableComponent<
public AccessControlService getComponent() {
return this;
}
-
+
}
\ No newline at end of file
diff --git a/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java b/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java
index c7f5d380..35cf38b7 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java
@@ -79,19 +79,24 @@ public abstract class AbstractServiceableComponent<T> extends AbstractIdentifiab
@Override @Nonnull public abstract T getComponent();
/**
- * {@inheritDoc} Grab the service lock shared. This will block unloads until {@link #unpinComponent()} is called.
+ * Grab the service lock shared. This will block unloads until {@link #unpinComponent()} is called.
*/
- @Override public void pinComponent() {
+ public void pinComponent() {
serviceLock.readLock().lock();
}
- /** {@inheritDoc} drop the shared lock. */
- @Override public void unpinComponent() {
+ /** Drop the shared lock. */
+ public void unpinComponent() {
serviceLock.readLock().unlock();
}
- /** {@inheritDoc}. Grab the service lock ex and then call spring to tear everything down. */
- @Override public void unloadComponent() {
+ @Override
+ public void close() {
+ unpinComponent();
+ }
+
+ /** Grab the service lock ex (which means noone else is active) and then call spring to tear everything down. */
+ public void unloadComponent() {
if (null == applicationContext) {
log.debug("Component '{}': Component already unloaded", getId());
return;
@@ -140,4 +145,4 @@ public abstract class AbstractServiceableComponent<T> extends AbstractIdentifiab
}
}
-}
\ No newline at end of file
+}
diff --git a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java
index d4723d91..2bab9754 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java
@@ -440,7 +440,7 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
*
* @return the <em>pinned</em> component.
*/
- @Override public synchronized ServiceableComponent<T> getServiceableComponent() {
+ @Override public synchronized AbstractServiceableComponent<T> getServiceableComponent() {
if (null == cachedComponent) {
return null;
}
diff --git a/shib-service/src/test/java/net/shibboleth/shared/spring/service/ReloadableSpringServiceTest.java b/shib-service/src/test/java/net/shibboleth/shared/spring/service/ReloadableSpringServiceTest.java
index d0ae391f..a44e0540 100644
--- a/shib-service/src/test/java/net/shibboleth/shared/spring/service/ReloadableSpringServiceTest.java
+++ b/shib-service/src/test/java/net/shibboleth/shared/spring/service/ReloadableSpringServiceTest.java
@@ -84,7 +84,7 @@ public class ReloadableSpringServiceTest {
service.start();
- ServiceableComponent<TestServiceableComponent> serviceableComponent = service.getServiceableComponent();
+ AbstractServiceableComponent<TestServiceableComponent> serviceableComponent = service.getServiceableComponent();
final TestServiceableComponent component = serviceableComponent.getComponent();
Assert.assertEquals("One", component.getTheValue());
diff --git a/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java
index 62fb2259..9c46a44a 100644
--- a/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java
+++ b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java
@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
import net.shibboleth.shared.service.AbstractReloadableService;
import net.shibboleth.shared.service.ServiceableComponent;
+import net.shibboleth.shared.spring.service.AbstractServiceableComponent;
/**
* Utility class for wrapping a serviceable component in a dummy reloadable service.
@@ -31,14 +32,14 @@ import net.shibboleth.shared.service.ServiceableComponent;
public class MockReloadableService<T> extends AbstractReloadableService<T> {
/** The component we are presenting to provide. */
- @Nonnull private final ServiceableComponent<T> component;
+ @Nonnull private final AbstractServiceableComponent<T> component;
/**
* Constructor.
*
* @param what component
*/
- public MockReloadableService(@Nullable final ServiceableComponent<T> what) {
+ public MockReloadableService(@Nullable final AbstractServiceableComponent<T> what) {
component = what;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list