Skip to content

Commit

Permalink
Generalize DelegatingResourceDefinition to accomodate non-lazy decora…
Browse files Browse the repository at this point in the history
…tors.
  • Loading branch information
pferraro committed Jan 31, 2024
1 parent de988e2 commit bcb4489
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceDefinition> 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<ResourceDefinition> 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<AccessConstraintDefinition> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ResourceDefinition> provider;

public ProvidedResourceDefinition(ResourceDefinition definition) {
this(Functions.constantSupplier(definition));
}

public ProvidedResourceDefinition(Supplier<ResourceDefinition> 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<AccessConstraintDefinition> 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();
}
}

0 comments on commit bcb4489

Please sign in to comment.