use of org.jboss.jca.core.api.management.ManagedConnectionFactory in project wildfly by wildfly.
the class IronJacamarActivationResourceService method start.
@Override
public void start(StartContext context) throws StartException {
final CommonDeployment deploymentMD = deployment.getValue().getDeployment();
final String deploymentName = deploymentMD.getDeploymentName();
ROOT_LOGGER.debugf("Starting IronJacamarActivationResourceService %s", deploymentName);
try {
Connector connector = deploymentMD.getConnector();
if (connector != null && connector.getResourceAdapter() != null) {
final OverrideDescriptionProvider OD_PROVIDER = new OverrideDescriptionProvider() {
@Override
public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
@Override
public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
};
final PathElement EXTENDED_STATS = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
final PathAddress EXTENDED_STATS_ADDR = PathAddress.pathAddress(EXTENDED_STATS);
final PathAddress CON_DEF_ADDR = PathAddress.EMPTY_ADDRESS.append(Constants.CONNECTIONDEFINITIONS_NAME);
ManagementResourceRegistration raRegistration = registration.getSubModel(RA_ADDRESS).registerOverrideModel(deploymentName, OD_PROVIDER);
ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(EXTENDED_STATS, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
ManagementResourceRegistration raStatsSubRegistration = raRegistration.registerSubModel(resourceBuilder.build());
StatisticsPlugin raStats = connector.getResourceAdapter().getStatistics();
if (raStats != null) {
raStats.setEnabled(statsEnabled);
PoolMetrics.ParametrizedPoolMetricsHandler handler = new PoolMetrics.ParametrizedPoolMetricsHandler(raStats);
for (AttributeDefinition attribute : StatisticsResourceDefinition.getAttributesFromPlugin(raStats)) {
raStatsSubRegistration.registerMetric(attribute, handler);
}
raStatsSubRegistration.registerOperationHandler(ClearStatisticsHandler.DEFINITION, new ClearStatisticsHandler(raStats));
}
List<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
if (connectionFactories != null) {
for (ConnectionFactory cf : connectionFactories) {
ManagedConnectionFactory mcf = cf.getManagedConnectionFactory();
StatisticsPlugin extendStats = mcf == null ? null : mcf.getStatistics();
if (extendStats != null) {
extendStats.setEnabled(statsEnabled);
if (!extendStats.getNames().isEmpty()) {
ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(CON_DEF_ADDR);
ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(cf.getJndiName(), OD_PROVIDER);
if (overrideCdRegistration.getSubModel(EXTENDED_STATS_ADDR) == null) {
overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(EXTENDED_STATS, CommonAttributes.RESOURCE_NAME, extendStats));
}
}
}
}
}
ConnectionManager[] connectionManagers = deploymentMD.getConnectionManagers();
if (connectionManagers != null) {
PathElement POOL_STATS = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
PathAddress POOL_STATS_ADDR = PathAddress.pathAddress(POOL_STATS);
for (ConnectionManager cm : connectionManagers) {
if (cm.getPool() != null) {
StatisticsPlugin poolStats = cm.getPool().getStatistics();
poolStats.setEnabled(statsEnabled);
if (!poolStats.getNames().isEmpty()) {
ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(CON_DEF_ADDR);
ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(cm.getJndiName(), OD_PROVIDER);
if (overrideCdRegistration.getSubModel(POOL_STATS_ADDR) == null) {
overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(POOL_STATS, CommonAttributes.RESOURCE_NAME, poolStats));
}
}
}
}
}
List<AdminObject> adminObjects = connector.getAdminObjects();
if (adminObjects != null) {
PathAddress AO_ADDR = PathAddress.EMPTY_ADDRESS.append(Constants.ADMIN_OBJECTS_NAME);
for (AdminObject ao : adminObjects) {
StatisticsPlugin extendStats = ao.getStatistics();
if (extendStats != null) {
extendStats.setEnabled(statsEnabled);
if (!extendStats.getNames().isEmpty()) {
ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(AO_ADDR);
ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(ao.getJndiName(), OD_PROVIDER);
if (overrideCdRegistration.getSubModel(EXTENDED_STATS_ADDR) == null) {
overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(EXTENDED_STATS, CommonAttributes.RESOURCE_NAME, extendStats));
}
}
}
}
}
}
} catch (IllegalArgumentException e) {
// ignore it, already restered
}
Resource subsystemResource;
if (!deploymentResource.hasChild(SUBSYSTEM_PATH_ELEMENT)) {
subsystemResource = new IronJacamarResource.IronJacamarRuntimeResource();
deploymentResource.registerChild(SUBSYSTEM_PATH_ELEMENT, subsystemResource);
} else {
subsystemResource = deploymentResource.getChild(SUBSYSTEM_PATH_ELEMENT);
}
IronJacamarResourceCreator.INSTANCE.execute(subsystemResource, mdr.getValue(), deployment.getValue().getRaName());
}
Aggregations