diff --git a/controller/src/main/java/org/jboss/as/controller/DelegatingResourceDefinition.java b/controller/src/main/java/org/jboss/as/controller/DelegatingResourceDefinition.java index a715ef3a7bf..0e67f5c130e 100644 --- a/controller/src/main/java/org/jboss/as/controller/DelegatingResourceDefinition.java +++ b/controller/src/main/java/org/jboss/as/controller/DelegatingResourceDefinition.java @@ -5,102 +5,52 @@ package org.jboss.as.controller; -import java.util.Collections; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import org.jboss.as.controller.access.management.AccessConstraintDefinition; -import org.jboss.as.controller.descriptions.DescriptionProvider; -import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; -import org.jboss.as.controller.registry.ManagementResourceRegistration; +import org.jboss.as.version.Stability; /** * @author Tomaz Cerar (c) 2015 Red Hat Inc. */ -public class DelegatingResourceDefinition implements ResourceDefinition { - protected volatile ResourceDefinition delegate; +public class DelegatingResourceDefinition extends ProvidedResourceDefinition { + private final AtomicReference reference; - protected void setDelegate(ResourceDefinition delegate) { - this.delegate = delegate; - } - - @Override - public void registerOperations(ManagementResourceRegistration resourceRegistration) { - delegate.registerOperations(resourceRegistration); - } - - @Override - public void registerChildren(ManagementResourceRegistration resourceRegistration) { - delegate.registerChildren(resourceRegistration); - } - - @Override - public void registerAttributes(ManagementResourceRegistration resourceRegistration) { - delegate.registerAttributes(resourceRegistration); - } - - @Override - public void registerNotifications(ManagementResourceRegistration resourceRegistration) { - delegate.registerNotifications(resourceRegistration); - } - - @Override - public void registerCapabilities(ManagementResourceRegistration resourceRegistration) { - delegate.registerCapabilities(resourceRegistration); - } - - @Override - public void registerAdditionalRuntimePackages(ManagementResourceRegistration resourceRegistration) { - delegate.registerAdditionalRuntimePackages(resourceRegistration); - } - - @Override - public boolean isFeature() { - return delegate.isFeature(); - } - - @Override - public int getMinOccurs() { - return delegate.getMinOccurs(); - } - - @Override - public int getMaxOccurs() { - return delegate.getMaxOccurs(); + public DelegatingResourceDefinition() { + this(new AtomicReference<>()); } - @Override - public PathElement getPathElement() { - return delegate.getPathElement(); + private DelegatingResourceDefinition(AtomicReference reference) { + super(reference::get); + this.reference = reference; } - @Override - public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration) { - return delegate.getDescriptionProvider(resourceRegistration); + protected void setDelegate(ResourceDefinition delegate) { + this.reference.set(delegate); } @Override public List getAccessConstraints() { - if (delegate == null) { - return Collections.emptyList(); - } - return delegate.getAccessConstraints(); + ResourceDefinition delegate = this.reference.get(); + return (delegate != null) ? delegate.getAccessConstraints() : List.of(); } @Override public boolean isRuntime() { - if (delegate!=null) { - return delegate.isRuntime(); - } - return false; + ResourceDefinition delegate = this.reference.get(); + return (delegate != null) ? delegate.isRuntime() : false; } @Override public boolean isOrderedChild() { - if (delegate != null) { - return delegate.isOrderedChild(); - } - return false; + ResourceDefinition delegate = this.reference.get(); + return (delegate != null) ? delegate.isOrderedChild() : false; } -} - + @Override + public Stability getStability() { + ResourceDefinition delegate = this.reference.get(); + return (delegate != null) ? delegate.getStability() : Stability.DEFAULT; + } +} diff --git a/controller/src/main/java/org/jboss/as/controller/ProvidedResourceDefinition.java b/controller/src/main/java/org/jboss/as/controller/ProvidedResourceDefinition.java new file mode 100644 index 00000000000..2fb20fc1fab --- /dev/null +++ b/controller/src/main/java/org/jboss/as/controller/ProvidedResourceDefinition.java @@ -0,0 +1,107 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.jboss.as.controller; + +import java.util.List; +import java.util.function.Supplier; + +import org.jboss.as.controller.access.management.AccessConstraintDefinition; +import org.jboss.as.controller.descriptions.DescriptionProvider; +import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; +import org.jboss.as.controller.registry.ManagementResourceRegistration; +import org.jboss.as.version.Stability; +import org.wildfly.common.function.Functions; + +/** + * Generalized {@link ResourceDefinition} decorator. + */ +public class ProvidedResourceDefinition implements ResourceDefinition { + + private final Supplier provider; + + public ProvidedResourceDefinition(ResourceDefinition definition) { + this(Functions.constantSupplier(definition)); + } + + public ProvidedResourceDefinition(Supplier provider) { + this.provider = provider; + } + + @Override + public PathElement getPathElement() { + return this.provider.get().getPathElement(); + } + + @Override + public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration registration) { + return this.provider.get().getDescriptionProvider(registration); + } + + @Override + public void registerOperations(ManagementResourceRegistration registration) { + this.provider.get().registerOperations(registration); + } + + @Override + public void registerAttributes(ManagementResourceRegistration registration) { + this.provider.get().registerAttributes(registration); + } + + @Override + public void registerNotifications(ManagementResourceRegistration registration) { + this.provider.get().registerNotifications(registration); + } + + @Override + public void registerChildren(ManagementResourceRegistration registration) { + this.provider.get().registerChildren(registration); + } + + @Override + public void registerCapabilities(ManagementResourceRegistration registration) { + this.provider.get().registerCapabilities(registration); + } + + @Override + public void registerAdditionalRuntimePackages(ManagementResourceRegistration registration) { + this.provider.get().registerAdditionalRuntimePackages(registration); + } + + @Override + public boolean isFeature() { + return this.provider.get().isFeature(); + } + + @Override + public boolean isOrderedChild() { + return this.provider.get().isOrderedChild(); + } + + @Override + public boolean isRuntime() { + return this.provider.get().isRuntime(); + } + + @Override + public List getAccessConstraints() { + return this.provider.get().getAccessConstraints(); + } + + @Override + public int getMaxOccurs() { + return this.provider.get().getMaxOccurs(); + } + + @Override + public int getMinOccurs() { + return this.provider.get().getMinOccurs(); + } + + @Override + public Stability getStability() { + return this.provider.get().getStability(); + } +}