Search in sources :

Example 1 with SimpleAttributeDefinitionBuilder

use of org.jboss.as.controller.SimpleAttributeDefinitionBuilder in project wildfly by wildfly.

the class ManagementResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    for (final String statisticName : statistics.getNames()) {
        final ModelType modelType = getModelType(statistics.getType(statisticName));
        if (statistics.isOperation(statisticName)) {
            AttributeDefinition attributeDefinition = new SimpleAttributeDefinitionBuilder(statisticName, modelType, true).setXmlName(statisticName).setAllowExpression(true).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
            OperationStepHandler operationHandler = new AbstractMetricsHandler() {

                @Override
                void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
                    Object result = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                    if (result != null) {
                        setResponse(response, result, modelType);
                    }
                }
            };
            SimpleOperationDefinition definition = new SimpleOperationDefinition(statisticName, descriptionResolver, attributeDefinition);
            resourceRegistration.registerOperationHandler(definition, operationHandler);
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ModelType(org.jboss.dmr.ModelType) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinition(org.jboss.as.controller.SimpleOperationDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder)

Example 2 with SimpleAttributeDefinitionBuilder

use of org.jboss.as.controller.SimpleAttributeDefinitionBuilder in project wildfly by wildfly.

the class ManagementResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    for (final String statisticName : statistics.getNames()) {
        final ModelType modelType = getModelType(statistics.getType(statisticName));
        final SimpleAttributeDefinitionBuilder simpleAttributeDefinitionBuilder = new SimpleAttributeDefinitionBuilder(statisticName, modelType, true).setXmlName(statisticName).setAllowExpression(true).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME);
        if (statistics.isAttribute(statisticName)) {
            // WFLY-561 improves usability by using "statistics-enabled" instead of "enabled"
            if (ENABLED_ATTRIBUTE.equals(statisticName)) {
                simpleAttributeDefinitionBuilder.setDeprecated(ENABLED_ATTRIBUTE_DEPRECATED_MODEL_VERSION);
            }
            OperationStepHandler readHandler = new AbstractMetricsHandler() {

                @Override
                void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
                    Object result = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                    if (result != null) {
                        setResponse(response, result, modelType);
                    }
                }
            };
            // handle writeable attributes
            if (statistics.isWriteable(statisticName)) {
                OperationStepHandler writeHandler = new AbstractMetricsHandler() {

                    @Override
                    void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
                        Object oldSetting = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                        {
                            final ModelNode value = operation.get(ModelDescriptionConstants.VALUE).resolve();
                            if (Boolean.class.equals(statistics.getType(statisticName))) {
                                statistics.setValue(statisticName, value.asBoolean(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            } else if (Integer.class.equals(statistics.getType(statisticName))) {
                                statistics.setValue(statisticName, value.asInt(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            } else if (Long.class.equals(statistics.getType(statisticName))) {
                                statistics.setValue(statisticName, value.asLong(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            } else {
                                statistics.setValue(statisticName, value.asString(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            }
                        }
                        final Object rollBackValue = oldSetting;
                        context.completeStep(new OperationContext.RollbackHandler() {

                            @Override
                            public void handleRollback(OperationContext context, ModelNode operation) {
                                statistics.setValue(statisticName, rollBackValue, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            }
                        });
                    }
                };
                resourceRegistration.registerReadWriteAttribute(simpleAttributeDefinitionBuilder.build(), readHandler, writeHandler);
            } else {
                resourceRegistration.registerMetric(simpleAttributeDefinitionBuilder.build(), readHandler);
            }
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder)

Example 3 with SimpleAttributeDefinitionBuilder

use of org.jboss.as.controller.SimpleAttributeDefinitionBuilder in project wildfly by wildfly.

the class PooledConnectionFactoryDefinition method copy.

private static AttributeDefinition copy(AttributeDefinition attribute, AttributeAccess.Flag flag) {
    AbstractAttributeDefinitionBuilder builder;
    if (attribute instanceof SimpleListAttributeDefinition) {
        builder = new SimpleListAttributeDefinition.Builder((SimpleListAttributeDefinition) attribute);
        // TODO remove once WFCORE-95 is fixed
        ((SimpleListAttributeDefinition.Builder) builder).setListValidator(attribute.getValidator());
    } else if (attribute instanceof SimpleMapAttributeDefinition) {
        builder = new SimpleMapAttributeDefinition.Builder((SimpleMapAttributeDefinition) attribute);
    } else if (attribute instanceof PrimitiveListAttributeDefinition) {
        builder = new PrimitiveListAttributeDefinition.Builder((PrimitiveListAttributeDefinition) attribute);
        // TODO remove once WFCORE-95 is fixed
        ((PrimitiveListAttributeDefinition.Builder) builder).setListValidator(attribute.getValidator());
    } else {
        builder = new SimpleAttributeDefinitionBuilder((SimpleAttributeDefinition) attribute);
    }
    builder.setFlags(flag);
    return builder.build();
}
Also used : SimpleListAttributeDefinition(org.jboss.as.controller.SimpleListAttributeDefinition) AbstractAttributeDefinitionBuilder(org.jboss.as.controller.AbstractAttributeDefinitionBuilder) AbstractAttributeDefinitionBuilder(org.jboss.as.controller.AbstractAttributeDefinitionBuilder) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) SimpleMapAttributeDefinition(org.jboss.as.controller.SimpleMapAttributeDefinition) PrimitiveListAttributeDefinition(org.jboss.as.controller.PrimitiveListAttributeDefinition)

Example 4 with SimpleAttributeDefinitionBuilder

use of org.jboss.as.controller.SimpleAttributeDefinitionBuilder in project wildfly by wildfly.

the class StatisticsResourceDefinition method getAttributesFromPlugin.

public static List<AttributeDefinition> getAttributesFromPlugin(StatisticsPlugin plugin) {
    LinkedList<AttributeDefinition> result = new LinkedList<>();
    for (String name : plugin.getNames()) {
        ModelType modelType = ModelType.STRING;
        if (plugin.getType(name) == int.class) {
            modelType = ModelType.INT;
        }
        if (plugin.getType(name) == long.class) {
            modelType = ModelType.LONG;
        }
        SimpleAttributeDefinition attribute = new SimpleAttributeDefinitionBuilder(name, modelType).setAllowNull(true).setStorageRuntime().build();
        result.add(attribute);
    }
    return result;
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelType(org.jboss.dmr.ModelType) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) LinkedList(java.util.LinkedList)

Example 5 with SimpleAttributeDefinitionBuilder

use of org.jboss.as.controller.SimpleAttributeDefinitionBuilder in project wildfly by wildfly.

the class PooledConnectionFactoryDefinition method copy.

private static AttributeDefinition copy(AttributeDefinition attribute, AttributeAccess.Flag flag) {
    AbstractAttributeDefinitionBuilder builder;
    if (attribute instanceof SimpleListAttributeDefinition) {
        builder = new SimpleListAttributeDefinition.Builder((SimpleListAttributeDefinition) attribute);
        // TODO remove once WFCORE-95 is fixed
        ((SimpleListAttributeDefinition.Builder) builder).setListValidator(attribute.getValidator());
    } else if (attribute instanceof SimpleMapAttributeDefinition) {
        builder = new SimpleMapAttributeDefinition.Builder((SimpleMapAttributeDefinition) attribute);
    } else if (attribute instanceof PrimitiveListAttributeDefinition) {
        builder = new PrimitiveListAttributeDefinition.Builder((PrimitiveListAttributeDefinition) attribute);
        // TODO remove once WFCORE-95 is fixed
        ((PrimitiveListAttributeDefinition.Builder) builder).setListValidator(attribute.getValidator());
    } else {
        builder = new SimpleAttributeDefinitionBuilder((SimpleAttributeDefinition) attribute);
    }
    builder.setFlags(flag);
    return builder.build();
}
Also used : SimpleListAttributeDefinition(org.jboss.as.controller.SimpleListAttributeDefinition) AbstractAttributeDefinitionBuilder(org.jboss.as.controller.AbstractAttributeDefinitionBuilder) AbstractAttributeDefinitionBuilder(org.jboss.as.controller.AbstractAttributeDefinitionBuilder) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) SimpleMapAttributeDefinition(org.jboss.as.controller.SimpleMapAttributeDefinition) PrimitiveListAttributeDefinition(org.jboss.as.controller.PrimitiveListAttributeDefinition)

Aggregations

SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)11 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)7 ModelNode (org.jboss.dmr.ModelNode)3 ModelType (org.jboss.dmr.ModelType)3 Attribute (org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.Attribute)2 FieldType (org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.FieldType)2 AbstractAttributeDefinitionBuilder (org.jboss.as.controller.AbstractAttributeDefinitionBuilder)2 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)2 OperationContext (org.jboss.as.controller.OperationContext)2 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)2 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)2 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)2 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)2 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)2 SimpleMapAttributeDefinition (org.jboss.as.controller.SimpleMapAttributeDefinition)2 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Map (java.util.Map)1