Skip to content

Commit

Permalink
Leverage ResourceDefinitionProvider to simplify thread pool resource …
Browse files Browse the repository at this point in the history
…enumerations.
  • Loading branch information
pferraro committed Oct 6, 2016
1 parent 460c1ff commit b416377
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 118 deletions.
Expand Up @@ -24,13 +24,11 @@


import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List;


import org.jboss.as.clustering.controller.AddStepHandler; import org.jboss.as.clustering.controller.AddStepHandler;
import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.clustering.controller.Registration;
import org.jboss.as.clustering.controller.RemoveStepHandler; import org.jboss.as.clustering.controller.RemoveStepHandler;
import org.jboss.as.clustering.controller.ResourceDefinitionProvider;
import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceHandler; import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SimpleAttribute; import org.jboss.as.clustering.controller.SimpleAttribute;
Expand All @@ -43,13 +41,9 @@
import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.management.AccessConstraintDefinition; import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.DefaultResourceDescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.description.DynamicDiscardPolicy; import org.jboss.as.controller.transform.description.DynamicDiscardPolicy;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
Expand All @@ -67,7 +61,7 @@
* @author Radoslav Husar * @author Radoslav Husar
* @version Mar 2015 * @version Mar 2015
*/ */
public enum ScheduledThreadPoolResourceDefinition implements ResourceDefinition, Registration<ManagementResourceRegistration>, ScheduledThreadPoolDefinition { public enum ScheduledThreadPoolResourceDefinition implements ResourceDefinitionProvider, ScheduledThreadPoolDefinition {


EXPIRATION("expiration", 1, 60000), // called eviction prior to Infinispan 8 EXPIRATION("expiration", 1, 60000), // called eviction prior to Infinispan 8
; ;
Expand All @@ -78,14 +72,13 @@ private static PathElement pathElement(String name) {
return PathElement.pathElement("thread-pool", name); return PathElement.pathElement("thread-pool", name);
} }


private final String name; private final SimpleResourceDefinition definition;
private final ResourceDescriptionResolver descriptionResolver; private final Attribute maxThreads;
private final SimpleAttribute maxThreads; private final Attribute keepAliveTime;
private final SimpleAttribute keepAliveTime;


ScheduledThreadPoolResourceDefinition(String name, int defaultMaxThreads, long defaultKeepaliveTime) { ScheduledThreadPoolResourceDefinition(String name, int defaultMaxThreads, long defaultKeepaliveTime) {
this.name = name; PathElement path = pathElement(name);
this.descriptionResolver = new InfinispanResourceDescriptionResolver(pathElement(name), pathElement(PathElement.WILDCARD_VALUE)); this.definition = new SimpleResourceDefinition(path, new InfinispanResourceDescriptionResolver(path, pathElement(PathElement.WILDCARD_VALUE)));
this.maxThreads = new SimpleAttribute(createBuilder("max-threads", ModelType.INT, new ModelNode(defaultMaxThreads), new IntRangeValidatorBuilder().min(0)).build()); this.maxThreads = new SimpleAttribute(createBuilder("max-threads", ModelType.INT, new ModelNode(defaultMaxThreads), new IntRangeValidatorBuilder().min(0)).build());
this.keepAliveTime = new SimpleAttribute(createBuilder("keepalive-time", ModelType.LONG, new ModelNode(defaultKeepaliveTime), new LongRangeValidatorBuilder().min(0)).build()); this.keepAliveTime = new SimpleAttribute(createBuilder("keepalive-time", ModelType.LONG, new ModelNode(defaultKeepaliveTime), new LongRangeValidatorBuilder().min(0)).build());
} }
Expand All @@ -102,58 +95,19 @@ private static SimpleAttributeDefinitionBuilder createBuilder(String name, Model
} }


@Override @Override
public PathElement getPathElement() { public ResourceDefinition getDefinition() {
return pathElement(this.name); return this.definition;
} }


@Override @Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration registration) { public void register(ManagementResourceRegistration parent) {
return new DefaultResourceDescriptionProvider(registration, this.descriptionResolver); ManagementResourceRegistration registration = parent.registerSubModel(this);
} ResourceDescriptor descriptor = new ResourceDescriptor(this.definition.getResourceDescriptionResolver()).addAttributes(this.getAttributes());

@Override
public void registerOperations(ManagementResourceRegistration registration) {
ResourceDescriptor descriptor = new ResourceDescriptor(this.descriptionResolver).addAttributes(this.getAttributes());
ResourceServiceHandler handler = new SimpleResourceServiceHandler<>(new ScheduledThreadPoolBuilderFactory(this)); ResourceServiceHandler handler = new SimpleResourceServiceHandler<>(new ScheduledThreadPoolBuilderFactory(this));
new AddStepHandler(descriptor, handler).register(registration); new AddStepHandler(descriptor, handler).register(registration);
new RemoveStepHandler(descriptor, handler).register(registration); new RemoveStepHandler(descriptor, handler).register(registration);
} }


@Override
public void registerAttributes(ManagementResourceRegistration registration) {
// No-op.
}

@Override
public void registerNotifications(ManagementResourceRegistration registration) {
// No-op.
}

@Override
public void registerChildren(ManagementResourceRegistration registration) {
// No-op.
}

@Override
public List<AccessConstraintDefinition> getAccessConstraints() {
return Collections.emptyList();
}

@Override
public boolean isRuntime() {
return false;
}

@Override
public boolean isOrderedChild() {
return false;
}

@Override
public void register(ManagementResourceRegistration registration) {
registration.registerSubModel(this);
}

@Override @Override
public ServiceName getServiceName(String containerName) { public ServiceName getServiceName(String containerName) {
return CacheContainerServiceName.CONFIGURATION.getServiceName(containerName).append(this.getPathElement().getKeyValuePair()); return CacheContainerServiceName.CONFIGURATION.getServiceName(containerName).append(this.getPathElement().getKeyValuePair());
Expand All @@ -180,5 +134,4 @@ void buildTransformation(ModelVersion version, ResourceTransformationDescription
DynamicDiscardPolicy getDiscardPolicy() { DynamicDiscardPolicy getDiscardPolicy() {
return new UndefinedAttributesDiscardPolicy(this.getAttributes()); return new UndefinedAttributesDiscardPolicy(this.getAttributes());
} }

} }
Expand Up @@ -24,13 +24,11 @@


import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List;


import org.jboss.as.clustering.controller.AddStepHandler; import org.jboss.as.clustering.controller.AddStepHandler;
import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.clustering.controller.Registration;
import org.jboss.as.clustering.controller.RemoveStepHandler; import org.jboss.as.clustering.controller.RemoveStepHandler;
import org.jboss.as.clustering.controller.ResourceDefinitionProvider;
import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceHandler; import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SimpleAttribute; import org.jboss.as.clustering.controller.SimpleAttribute;
Expand All @@ -43,13 +41,9 @@
import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.management.AccessConstraintDefinition; import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.DefaultResourceDescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.description.DynamicDiscardPolicy; import org.jboss.as.controller.transform.description.DynamicDiscardPolicy;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
Expand All @@ -66,7 +60,7 @@
* @author Radoslav Husar * @author Radoslav Husar
* @version February 2015 * @version February 2015
*/ */
public enum ThreadPoolResourceDefinition implements ResourceDefinition, Registration<ManagementResourceRegistration>, ThreadPoolDefinition { public enum ThreadPoolResourceDefinition implements ResourceDefinitionProvider, ThreadPoolDefinition {


ASYNC_OPERATIONS("async-operations", 25, 25, 1000, 60000L), ASYNC_OPERATIONS("async-operations", 25, 25, 1000, 60000L),
LISTENER("listener", 1, 1, 100000, 60000L), LISTENER("listener", 1, 1, 100000, 60000L),
Expand All @@ -82,16 +76,15 @@ private static PathElement pathElement(String name) {
return PathElement.pathElement("thread-pool", name); return PathElement.pathElement("thread-pool", name);
} }


private final String name; private final SimpleResourceDefinition definition;
private final ResourceDescriptionResolver descriptionResolver;
private final Attribute minThreads; private final Attribute minThreads;
private final Attribute maxThreads; private final Attribute maxThreads;
private final Attribute queueLength; private final Attribute queueLength;
private final Attribute keepAliveTime; private final Attribute keepAliveTime;


ThreadPoolResourceDefinition(String name, int defaultMinThreads, int defaultMaxThreads, int defaultQueueLength, long defaultKeepaliveTime) { ThreadPoolResourceDefinition(String name, int defaultMinThreads, int defaultMaxThreads, int defaultQueueLength, long defaultKeepaliveTime) {
this.name = name; PathElement path = pathElement(name);
this.descriptionResolver = new InfinispanResourceDescriptionResolver(pathElement(name), pathElement(PathElement.WILDCARD_VALUE)); this.definition = new SimpleResourceDefinition(path, new InfinispanResourceDescriptionResolver(path, pathElement(PathElement.WILDCARD_VALUE)));
this.minThreads = new SimpleAttribute(createBuilder("min-threads", ModelType.INT, new ModelNode(defaultMinThreads), new IntRangeValidatorBuilder().min(0)).build()); this.minThreads = new SimpleAttribute(createBuilder("min-threads", ModelType.INT, new ModelNode(defaultMinThreads), new IntRangeValidatorBuilder().min(0)).build());
this.maxThreads = new SimpleAttribute(createBuilder("max-threads", ModelType.INT, new ModelNode(defaultMaxThreads), new IntRangeValidatorBuilder().min(0)).build()); this.maxThreads = new SimpleAttribute(createBuilder("max-threads", ModelType.INT, new ModelNode(defaultMaxThreads), new IntRangeValidatorBuilder().min(0)).build());
this.queueLength = new SimpleAttribute(createBuilder("queue-length", ModelType.INT, new ModelNode(defaultQueueLength), new IntRangeValidatorBuilder().min(0)).build()); this.queueLength = new SimpleAttribute(createBuilder("queue-length", ModelType.INT, new ModelNode(defaultQueueLength), new IntRangeValidatorBuilder().min(0)).build());
Expand All @@ -110,58 +103,19 @@ private static SimpleAttributeDefinitionBuilder createBuilder(String name, Model
} }


@Override @Override
public PathElement getPathElement() { public ResourceDefinition getDefinition() {
return pathElement(this.name); return this.definition;
} }


@Override @Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration registration) { public void register(ManagementResourceRegistration parent) {
return new DefaultResourceDescriptionProvider(registration, this.descriptionResolver); ManagementResourceRegistration registration = parent.registerSubModel(this);
} ResourceDescriptor descriptor = new ResourceDescriptor(this.definition.getResourceDescriptionResolver()).addAttributes(this.getAttributes());

@Override
public void registerOperations(ManagementResourceRegistration registration) {
ResourceDescriptor descriptor = new ResourceDescriptor(this.descriptionResolver).addAttributes(this.getAttributes());
ResourceServiceHandler handler = new SimpleResourceServiceHandler<>(new ThreadPoolBuilderFactory(this)); ResourceServiceHandler handler = new SimpleResourceServiceHandler<>(new ThreadPoolBuilderFactory(this));
new AddStepHandler(descriptor, handler).register(registration); new AddStepHandler(descriptor, handler).register(registration);
new RemoveStepHandler(descriptor, handler).register(registration); new RemoveStepHandler(descriptor, handler).register(registration);
} }


@Override
public void registerAttributes(ManagementResourceRegistration registration) {
// No-op.
}

@Override
public void registerNotifications(ManagementResourceRegistration registration) {
// No-op.
}

@Override
public void registerChildren(ManagementResourceRegistration registration) {
// No-op.
}

@Override
public List<AccessConstraintDefinition> getAccessConstraints() {
return Collections.emptyList();
}

@Override
public boolean isRuntime() {
return false;
}

@Override
public boolean isOrderedChild() {
return false;
}

@Override
public void register(ManagementResourceRegistration registration) {
registration.registerSubModel(this);
}

@Override @Override
public ServiceName getServiceName(String containerName) { public ServiceName getServiceName(String containerName) {
return CacheContainerServiceName.CONFIGURATION.getServiceName(containerName).append(this.getPathElement().getKeyValuePair()); return CacheContainerServiceName.CONFIGURATION.getServiceName(containerName).append(this.getPathElement().getKeyValuePair());
Expand Down Expand Up @@ -198,5 +152,4 @@ void buildTransformation(ModelVersion version, ResourceTransformationDescription
DynamicDiscardPolicy getDiscardPolicy() { DynamicDiscardPolicy getDiscardPolicy() {
return new UndefinedAttributesDiscardPolicy(this.getAttributes()); return new UndefinedAttributesDiscardPolicy(this.getAttributes());
} }

} }

0 comments on commit b416377

Please sign in to comment.