From a17b3b0201288c931d468ce32ea568b217399185 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Thu, 21 Dec 2023 17:56:22 -0500 Subject: [PATCH] WFCORE-6347 Consolidate ResourceServiceValueRegistry and ServiceValueRegistry --- .../ResourceServiceValueExecutorRegistry.java | 50 ------------------- .../capture/ResourceServiceValueRegistry.java | 23 --------- .../service/capture/ServiceValueRegistry.java | 22 ++++++++ 3 files changed, 22 insertions(+), 73 deletions(-) delete mode 100644 subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueExecutorRegistry.java delete mode 100644 subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueRegistry.java diff --git a/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueExecutorRegistry.java b/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueExecutorRegistry.java deleted file mode 100644 index 0a5b29bd351..00000000000 --- a/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueExecutorRegistry.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.subsystem.service.capture; - -import java.util.function.Consumer; - -import org.wildfly.subsystem.service.ServiceDependency; -import org.wildfly.subsystem.service.ServiceInstaller; - -/** - * A registry of captured service value executors. - * @author Paul Ferraro - * @param the captured service value type - */ -public interface ResourceServiceValueExecutorRegistry extends ResourceServiceValueRegistry, FunctionExecutorRegistry { - - /** - * Creates a new {@link ResourceServiceValueExecutorRegistry}. - * @param the captured service value type - * @return a new service value executor registry - */ - static ResourceServiceValueExecutorRegistry create() { - ServiceValueExecutorRegistry registry = ServiceValueExecutorRegistry.create(); - return new ResourceServiceValueExecutorRegistry<>() { - @Override - public ServiceInstaller capture(ServiceDependency dependency) { - Consumer startTask = new Consumer<>() { - @Override - public void accept(V value) { - registry.add(dependency).accept(value); - } - }; - Consumer stopTask = new Consumer<>() { - @Override - public void accept(V value) { - registry.remove(dependency); - } - }; - return ServiceInstaller.builder(dependency).onStart(startTask).onStop(stopTask).asPassive().build(); - } - - @Override - public FunctionExecutor getExecutor(ServiceDependency dependency) { - return registry.getExecutor(dependency); - } - }; - } -} diff --git a/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueRegistry.java b/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueRegistry.java deleted file mode 100644 index 8638760efec..00000000000 --- a/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ResourceServiceValueRegistry.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.subsystem.service.capture; - -import org.wildfly.subsystem.service.ResourceServiceInstaller; -import org.wildfly.subsystem.service.ServiceDependency; - -/** - * A registry of service values. - * @author Paul Ferraro - * @param the captured service value type - */ -public interface ResourceServiceValueRegistry { - - /** - * Creates a service installer to capture the value provided by the specified service dependency. - * @param dependency a service dependency - * @return a service installer - */ - ResourceServiceInstaller capture(ServiceDependency dependency); -} diff --git a/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ServiceValueRegistry.java b/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ServiceValueRegistry.java index ceb1f778839..eecd63403a6 100644 --- a/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ServiceValueRegistry.java +++ b/subsystem/src/main/java/org/wildfly/subsystem/service/capture/ServiceValueRegistry.java @@ -7,6 +7,7 @@ import java.util.function.Consumer; import org.wildfly.subsystem.service.ServiceDependency; +import org.wildfly.subsystem.service.ServiceInstaller; /** * A registry of service values. @@ -27,4 +28,25 @@ public interface ServiceValueRegistry { * @param dependency a service dependency */ void remove(ServiceDependency dependency); + + /** + * Creates a service installer to capture and release the value provided by the specified service dependency. + * @param dependency a service dependency + * @return a service installer + */ + default ServiceInstaller capture(ServiceDependency dependency) { + Consumer startTask = new Consumer<>() { + @Override + public void accept(V value) { + ServiceValueRegistry.this.add(dependency).accept(value); + } + }; + Consumer stopTask = new Consumer<>() { + @Override + public void accept(V value) { + ServiceValueRegistry.this.remove(dependency); + } + }; + return ServiceInstaller.builder(dependency).onStart(startTask).onStop(stopTask).asPassive().build(); + } }