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);
}
}
}
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);
}
}
}
}
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();
}
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;
}
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();
}
Aggregations