use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class MessagingXMLWriter method writeJmsBridge.
private void writeJmsBridge(XMLExtendedStreamWriter writer, String bridgeName, ModelNode value) throws XMLStreamException {
writer.writeStartElement(Element.JMS_BRIDGE.getLocalName());
if (!DEFAULT.equals(bridgeName)) {
writer.writeAttribute(Attribute.NAME.getLocalName(), bridgeName);
}
JMSBridgeDefinition.MODULE.marshallAsAttribute(value, writer);
writer.writeStartElement(SOURCE.getLocalName());
for (AttributeDefinition attr : JMSBridgeDefinition.JMS_SOURCE_ATTRIBUTES) {
attr.marshallAsElement(value, writer);
}
writer.writeEndElement();
writer.writeStartElement(TARGET.getLocalName());
for (AttributeDefinition attr : JMSBridgeDefinition.JMS_TARGET_ATTRIBUTES) {
attr.marshallAsElement(value, writer);
}
writer.writeEndElement();
for (AttributeDefinition attr : JMSBridgeDefinition.JMS_BRIDGE_ATTRIBUTES) {
if (attr == JMSBridgeDefinition.MODULE) {
// handled as a XML attribute
continue;
}
attr.marshallAsElement(value, writer);
}
writer.writeEndElement();
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class MessagingXMLWriter method writeConnectionFactories.
private static void writeConnectionFactories(final XMLExtendedStreamWriter writer, final ModelNode node) throws XMLStreamException {
if (!node.isDefined()) {
return;
}
if (node.asInt() > 0) {
for (String name : node.keys()) {
final ModelNode factory = node.get(name);
if (factory.isDefined()) {
writer.writeStartElement(Element.CONNECTION_FACTORY.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), name);
for (AttributeDefinition attribute : ConnectionFactoryDefinition.ATTRIBUTES) {
attribute.marshallAsElement(factory, writer);
}
writer.writeEndElement();
}
}
}
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class ExternalPooledConnectionFactoryDefinition method define.
// the generation of the Pooled CF attributes is a bit ugly but it is with purpose:
// * factorize the attributes which are common between the regular CF and the pooled CF
// * keep in a single place the subtle differences (e.g. different default values for reconnect-attempts between
// the regular and pooled CF
private static ConnectionFactoryAttribute[] define(ConnectionFactoryAttribute[] specific, ConnectionFactoryAttribute... common) {
int size = common.length + specific.length + 1;
ConnectionFactoryAttribute[] result = new ConnectionFactoryAttribute[size];
for (int i = 0; i < specific.length; i++) {
ConnectionFactoryAttribute attr = specific[i];
AttributeDefinition definition = attr.getDefinition();
if (definition == ConnectionFactoryAttributes.Pooled.INITIAL_CONNECT_ATTEMPTS) {
result[i] = ConnectionFactoryAttribute.create(SimpleAttributeDefinitionBuilder.create(ConnectionFactoryAttributes.Pooled.INITIAL_CONNECT_ATTEMPTS).setDefaultValue(new ModelNode(-1)).build(), attr.getPropertyName(), true);
} else {
result[i] = attr;
}
}
for (int i = 0; i < common.length; i++) {
ConnectionFactoryAttribute attr = common[i];
AttributeDefinition definition = attr.getDefinition();
ConnectionFactoryAttribute newAttr;
// replace the reconnect-attempts attribute to use a different default value for pooled CF
if (definition == Common.RECONNECT_ATTEMPTS) {
AttributeDefinition copy = copy(Pooled.RECONNECT_ATTEMPTS, AttributeAccess.Flag.RESTART_ALL_SERVICES);
newAttr = ConnectionFactoryAttribute.create(copy, Pooled.RECONNECT_ATTEMPTS_PROP_NAME, true);
} else if (definition == CommonAttributes.HA) {
newAttr = ConnectionFactoryAttribute.create(SimpleAttributeDefinitionBuilder.create(CommonAttributes.HA).setDefaultValue(ModelNode.TRUE).setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES).build(), attr.getPropertyName(), true);
} else if (definition == Common.CONNECTORS) {
StringListAttributeDefinition copy = new StringListAttributeDefinition.Builder(Common.CONNECTORS).setAlternatives(CommonAttributes.DISCOVERY_GROUP).setRequired(true).setAttributeParser(AttributeParser.STRING_LIST).setAttributeMarshaller(AttributeMarshaller.STRING_LIST).setCapabilityReference(new AbstractTransportDefinition.TransportCapabilityReferenceRecorder(CAPABILITY_NAME, CONNECTOR_CAPABILITY_NAME, true)).setRestartAllServices().build();
newAttr = ConnectionFactoryAttribute.create(copy, attr.getPropertyName(), attr.isResourceAdapterProperty(), attr.getConfigType());
} else {
AttributeDefinition copy = copy(definition, AttributeAccess.Flag.RESTART_ALL_SERVICES);
newAttr = ConnectionFactoryAttribute.create(copy, attr.getPropertyName(), attr.isResourceAdapterProperty(), attr.getConfigType());
}
result[specific.length + i] = newAttr;
}
result[size - 1] = ConnectionFactoryAttribute.create(External.ENABLE_AMQ1_PREFIX, "enable1xPrefixes", true);
return result;
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class PooledConnectionFactoryAdd method getAdapterParams.
static List<PooledConnectionFactoryConfigProperties> getAdapterParams(ModelNode model, OperationContext context, ConnectionFactoryAttribute[] attributes) throws OperationFailedException {
List<PooledConnectionFactoryConfigProperties> configs = new ArrayList<PooledConnectionFactoryConfigProperties>();
for (ConnectionFactoryAttribute nodeAttribute : attributes) {
if (!nodeAttribute.isResourceAdapterProperty())
continue;
AttributeDefinition definition = nodeAttribute.getDefinition();
ModelNode node = definition.resolveModelAttribute(context, model);
if (node.isDefined()) {
String attributeName = definition.getName();
final String value;
if (attributeName.equals(Common.DESERIALIZATION_BLACKLIST.getName())) {
value = String.join(",", Common.DESERIALIZATION_BLACKLIST.unwrap(context, model));
} else if (attributeName.equals(Common.DESERIALIZATION_WHITELIST.getName())) {
value = String.join(",", Common.DESERIALIZATION_WHITELIST.unwrap(context, model));
} else {
value = node.asString();
}
configs.add(new PooledConnectionFactoryConfigProperties(nodeAttribute.getPropertyName(), value, nodeAttribute.getClassType(), nodeAttribute.getConfigType()));
}
}
return configs;
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class PooledConnectionFactoryAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
PathAddress address = context.getCurrentAddress();
final String name = context.getCurrentAddressValue();
final ModelNode resolvedModel = model.clone();
for (final AttributeDefinition attribute : attributes) {
resolvedModel.get(attribute.getName()).set(attribute.resolveModelAttribute(context, resolvedModel));
}
// We validated that jndiName part of the model in populateModel
final List<String> jndiNames = new ArrayList<>();
for (ModelNode node : resolvedModel.get(Common.ENTRIES.getName()).asList()) {
jndiNames.add(node.asString());
}
final BindInfo bindInfo = ContextNames.bindInfoFor(jndiNames.get(0));
List<String> jndiAliases;
if (jndiNames.size() > 1) {
jndiAliases = new ArrayList<>(jndiNames.subList(1, jndiNames.size()));
} else {
jndiAliases = Collections.emptyList();
}
String managedConnectionPoolClassName = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName()).asStringOrNull();
final int minPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MIN_POOL_SIZE.getName()).asInt();
final int maxPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MAX_POOL_SIZE.getName()).asInt();
Boolean enlistmentTrace = resolvedModel.get(ConnectionFactoryAttributes.Pooled.ENLISTMENT_TRACE.getName()).asBooleanOrNull();
String txSupport = getTxSupport(resolvedModel);
List<String> connectors = Common.CONNECTORS.unwrap(context, model);
String discoveryGroupName = getDiscoveryGroup(resolvedModel);
String jgroupClusterName = null;
final PathAddress serverAddress = MessagingServices.getActiveMQServerPathAddress(address);
if (discoveryGroupName != null) {
Resource dgResource;
try {
dgResource = context.readResourceFromRoot(serverAddress.append(CommonAttributes.SOCKET_DISCOVERY_GROUP, discoveryGroupName), false);
} catch (Resource.NoSuchResourceException ex) {
dgResource = context.readResourceFromRoot(serverAddress.append(CommonAttributes.JGROUPS_DISCOVERY_GROUP, discoveryGroupName), false);
}
ModelNode dgModel = dgResource.getModel();
ModelNode jgroupCluster = JGROUPS_CLUSTER.resolveModelAttribute(context, dgModel);
if (jgroupCluster.isDefined()) {
jgroupClusterName = jgroupCluster.asString();
}
}
List<PooledConnectionFactoryConfigProperties> adapterParams = getAdapterParams(resolvedModel, context, PooledConnectionFactoryDefinition.ATTRIBUTES);
String serverName = serverAddress.getLastElement().getValue();
PooledConnectionFactoryService.installService(context, name, serverName, connectors, discoveryGroupName, jgroupClusterName, adapterParams, bindInfo, jndiAliases, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
boolean statsEnabled = ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
if (statsEnabled) {
// Add the stats resource. This is kind of a hack as we are modifying the resource
// in runtime, but oh well. We don't use readResourceForUpdate for this reason.
// This only runs in this add op anyway, and because it's an add we know readResource
// is going to be returning the current write snapshot of the model, i.e. the one we want
PooledConnectionFactoryStatisticsService.registerStatisticsResources(resource);
installStatistics(context, name);
}
}
Aggregations