Search in sources :

Example 1 with ConnectionManager

use of org.jboss.jca.core.connectionmanager.ConnectionManager in project wildfly by wildfly.

the class JcaTestsUtil method extractManagedConnectionPool.

/**
     * Extract ManagedConnectionPool from ConnectionFactory by using reflection
     *
     * @param connectionFactory
     * @return ManagedConnectionPool instance. <code>null</code> if not found
     */
public static ManagedConnectionPool extractManagedConnectionPool(Object connectionFactory) {
    ConnectionManager cm = extractConnectionManager(connectionFactory);
    // org.jboss.jca.core.connectionmanager.pool.strategy.OnePool
    Object onePool = cm.getPool();
    Class<?> clz = onePool.getClass();
    // org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool
    clz = clz.getSuperclass();
    // org.jboss.jca.core.connectionmanager.pool.AbstractPool
    clz = clz.getSuperclass();
    try {
        Method getManagedConnectionPools = clz.getDeclaredMethod("getManagedConnectionPools");
        getManagedConnectionPools.setAccessible(true);
        ConcurrentMap<Object, ManagedConnectionPool> mcps = (ConcurrentMap<Object, ManagedConnectionPool>) getManagedConnectionPools.invoke(onePool);
        return mcps.values().iterator().next();
    } catch (Throwable t) {
        fail(t.getMessage());
    }
    return null;
}
Also used : ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) ConcurrentMap(java.util.concurrent.ConcurrentMap) Method(java.lang.reflect.Method) ManagedConnectionPool(org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool)

Example 2 with ConnectionManager

use of org.jboss.jca.core.connectionmanager.ConnectionManager in project wildfly by wildfly.

the class IronJacamarActivationResourceService method start.

@Override
public void start(StartContext context) throws StartException {
    ManagementResourceRegistration subRegistration;
    final CommonDeployment deploymentMD = deployment.getValue().getDeployment();
    ROOT_LOGGER.debugf("Starting IronJacamarActivationResourceService %s", deploymentMD.getDeploymentName());
    try {
        ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(SUBSYSTEM_PATH_ELEMENT, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
        subRegistration = registration.registerSubModel(resourceBuilder.build());
    } catch (IllegalArgumentException iae) {
        subRegistration = registration.getSubModel(PathAddress.pathAddress(SUBSYSTEM_PATH_ELEMENT));
    }
    ManagementResourceRegistration ijRegistration;
    try {
        ijRegistration = subRegistration.registerSubModel(new IronJacamarResourceDefinition());
    } catch (IllegalArgumentException iae) {
        ijRegistration = subRegistration.getSubModel(PathAddress.pathAddress(Constants.IRONJACAMAR_NAME, Constants.IRONJACAMAR_NAME));
    }
    try {
        if (deploymentResource != null) {
            PathElement peLocalStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
            if (deploymentMD.getConnector() != null && deploymentMD.getConnector().getResourceAdapter() != null) {
                ManagementResourceRegistration raRegistration = ijRegistration.getSubModel(PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(Constants.RESOURCEADAPTER_NAME))).registerOverrideModel(deploymentMD.getDeploymentName(), new OverrideDescriptionProvider() {

                    @Override
                    public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
                        return Collections.emptyMap();
                    }

                    @Override
                    public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                        return Collections.emptyMap();
                    }
                });
                ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(peLocalStats, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
                ManagementResourceRegistration raStatsSubRegistration = raRegistration.registerSubModel(resourceBuilder.build());
                if (deploymentMD.getConnector().getResourceAdapter().getStatistics() != null) {
                    StatisticsPlugin raStats = deploymentMD.getConnector().getResourceAdapter().getStatistics();
                    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));
                }
                if (deploymentMD.getConnector() != null && deploymentMD.getConnector().getConnectionFactories() != null) {
                    for (ConnectionFactory cf : deploymentMD.getConnector().getConnectionFactories()) {
                        if (cf.getManagedConnectionFactory() != null && cf.getManagedConnectionFactory().getStatistics() != null) {
                            PathElement peCD = PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME, cf.getJndiName());
                            PathElement peCdStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
                            StatisticsPlugin extendStats = cf.getManagedConnectionFactory().getStatistics();
                            extendStats.setEnabled(statsEnabled);
                            if (extendStats.getNames().size() != 0) {
                                if (extendStats.getNames().size() != 0) {
                                    ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(PathAddress.pathAddress(peCD));
                                    ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(cf.getJndiName(), new OverrideDescriptionProvider() {

                                        @Override
                                        public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
                                            return Collections.emptyMap();
                                        }

                                        @Override
                                        public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                                            return Collections.emptyMap();
                                        }
                                    });
                                    if (extendStats.getNames().size() != 0 && overrideCdRegistration.getSubModel(PathAddress.pathAddress(peCdStats)) == null) {
                                        overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(peCdStats, CommonAttributes.RESOURCE_NAME, extendStats));
                                    }
                                }
                            }
                        }
                    }
                }
                if (deploymentMD.getConnectionManagers() != null) {
                    for (ConnectionManager cm : deploymentMD.getConnectionManagers()) {
                        if (cm.getPool() != null) {
                            PathElement peCD = PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME, cm.getJndiName());
                            PathElement peCdStats = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
                            StatisticsPlugin poolStats = cm.getPool().getStatistics();
                            poolStats.setEnabled(statsEnabled);
                            if (poolStats.getNames().size() != 0) {
                                ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(PathAddress.pathAddress(peCD));
                                ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(cm.getJndiName(), new OverrideDescriptionProvider() {

                                    @Override
                                    public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
                                        return Collections.emptyMap();
                                    }

                                    @Override
                                    public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                                        return Collections.emptyMap();
                                    }
                                });
                                if (poolStats.getNames().size() != 0 && overrideCdRegistration.getSubModel(PathAddress.pathAddress(peCdStats)) == null) {
                                    overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(peCdStats, CommonAttributes.RESOURCE_NAME, poolStats));
                                }
                            }
                        }
                    }
                }
                if (deploymentMD.getConnector() != null && deploymentMD.getConnector().getAdminObjects() != null) {
                    for (AdminObject ao : deploymentMD.getConnector().getAdminObjects()) {
                        if (ao.getStatistics() != null) {
                            PathElement peCD = PathElement.pathElement(Constants.ADMIN_OBJECTS_NAME, ao.getJndiName());
                            PathElement peCdStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
                            StatisticsPlugin extendStats = ao.getStatistics();
                            extendStats.setEnabled(statsEnabled);
                            if (extendStats.getNames().size() != 0) {
                                if (extendStats.getNames().size() != 0) {
                                    ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(PathAddress.pathAddress(peCD));
                                    ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(ao.getJndiName(), new OverrideDescriptionProvider() {

                                        @Override
                                        public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
                                            return Collections.emptyMap();
                                        }

                                        @Override
                                        public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                                            return Collections.emptyMap();
                                        }
                                    });
                                    if (extendStats.getNames().size() != 0 && overrideCdRegistration.getSubModel(PathAddress.pathAddress(peCdStats)) == null) {
                                        overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(peCdStats, 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());
}
Also used : Locale(java.util.Locale) StatisticsResourceDefinition(org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition) ResourceBuilder(org.jboss.as.controller.ResourceBuilder) IronJacamarResourceDefinition(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResourceDefinition) StatisticsPlugin(org.jboss.jca.core.spi.statistics.StatisticsPlugin) Resource(org.jboss.as.controller.registry.Resource) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) PoolMetrics(org.jboss.as.connector.subsystems.common.pool.PoolMetrics) CommonDeployment(org.jboss.jca.deployers.common.CommonDeployment) ConnectionFactory(org.jboss.jca.core.api.management.ConnectionFactory) ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) PathElement(org.jboss.as.controller.PathElement) ClearStatisticsHandler(org.jboss.as.connector.dynamicresource.ClearStatisticsHandler) Map(java.util.Map) AdminObject(org.jboss.jca.core.api.management.AdminObject)

Example 3 with ConnectionManager

use of org.jboss.jca.core.connectionmanager.ConnectionManager in project wildfly by wildfly.

the class AbstractResourceAdapterDeploymentService method unregisterAll.

public void unregisterAll(String deploymentName) {
    if (value != null) {
        DEPLOYMENT_CONNECTOR_LOGGER.debugf("Unregistering: %s", deploymentName);
        if (registry != null && registry.getValue() != null) {
            registry.getValue().unregisterResourceAdapterDeployment(value);
        }
        if (managementRepository != null && managementRepository.getValue() != null && value.getDeployment() != null && value.getDeployment().getConnector() != null) {
            managementRepository.getValue().getConnectors().remove(value.getDeployment().getConnector());
        }
        if (mdr != null && mdr.getValue() != null && value.getDeployment() != null && value.getDeployment().getCfs() != null && value.getDeployment().getCfJndiNames() != null) {
            for (int i = 0; i < value.getDeployment().getCfs().length; i++) {
                try {
                    String cf = value.getDeployment().getCfs()[i].getClass().getName();
                    String jndi = value.getDeployment().getCfJndiNames()[i];
                    mdr.getValue().unregisterJndiMapping(value.getDeployment().getURL().toExternalForm(), cf, jndi);
                } catch (Throwable nfe) {
                    DEPLOYMENT_CONNECTOR_LOGGER.debug("Exception during JNDI unbinding", nfe);
                }
            }
        }
        if (mdr != null && mdr.getValue() != null && value.getDeployment().getAos() != null && value.getDeployment().getAoJndiNames() != null) {
            for (int i = 0; i < value.getDeployment().getAos().length; i++) {
                try {
                    String ao = value.getDeployment().getAos()[i].getClass().getName();
                    String jndi = value.getDeployment().getAoJndiNames()[i];
                    mdr.getValue().unregisterJndiMapping(value.getDeployment().getURL().toExternalForm(), ao, jndi);
                } catch (Throwable nfe) {
                    DEPLOYMENT_CONNECTOR_LOGGER.debug("Exception during JNDI unbinding", nfe);
                }
            }
        }
        if (value != null && value.getDeployment() != null && value.getDeployment().getRecovery() != null && txInt != null && txInt.getValue() != null) {
            XAResourceRecoveryRegistry rr = txInt.getValue().getRecoveryRegistry();
            if (rr != null) {
                for (XAResourceRecovery recovery : value.getDeployment().getRecovery()) {
                    if (recovery != null) {
                        try {
                            recovery.shutdown();
                        } catch (Exception e) {
                            DEPLOYMENT_CONNECTOR_LOGGER.errorDuringRecoveryShutdown(e);
                        } finally {
                            rr.removeXAResourceRecovery(recovery);
                        }
                    }
                }
            }
        }
        if (value.getDeployment() != null && value.getDeployment().getConnectionManagers() != null) {
            for (ConnectionManager cm : value.getDeployment().getConnectionManagers()) {
                cm.shutdown();
            }
        }
        if (value.getDeployment() != null && value.getDeployment().getResourceAdapter() != null) {
            ClassLoader old = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(value.getDeployment().getResourceAdapter().getClass().getClassLoader());
                value.getDeployment().getResourceAdapter().stop();
            } catch (Throwable nfe) {
                DEPLOYMENT_CONNECTOR_LOGGER.errorStoppingRA(nfe);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old);
            }
        }
        if (value.getDeployment() != null && value.getDeployment().getBootstrapContextIdentifier() != null) {
            BootstrapContextCoordinator.getInstance().removeBootstrapContext(value.getDeployment().getBootstrapContextIdentifier());
        }
    }
    if (raRepositoryRegistrationId != null && raRepository != null && raRepository.getValue() != null) {
        try {
            raRepository.getValue().unregisterResourceAdapter(raRepositoryRegistrationId);
        } catch (Throwable e) {
            DEPLOYMENT_CONNECTOR_LOGGER.debug("Failed to unregister RA from RA Repository", e);
        }
    }
    if (connectorServicesRegistrationName != null) {
        try {
            ConnectorServices.unregisterResourceAdapterIdentifier(connectorServicesRegistrationName);
        } catch (Throwable e) {
            DEPLOYMENT_CONNECTOR_LOGGER.debug("Failed to unregister RA from ConnectorServices", e);
        }
    }
    if (mdrRegistrationName != null && mdr != null && mdr.getValue() != null) {
        try {
            mdr.getValue().unregisterResourceAdapter(mdrRegistrationName);
        } catch (Throwable e) {
            DEPLOYMENT_CONNECTOR_LOGGER.debug("Failed to unregister RA from MDR", e);
        }
    }
}
Also used : CachedConnectionManager(org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager) ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) XAResourceRecovery(org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery) XAResourceRecoveryRegistry(org.jboss.jca.core.spi.transaction.recovery.XAResourceRecoveryRegistry) XsdString(org.jboss.jca.common.api.metadata.spec.XsdString) URISyntaxException(java.net.URISyntaxException) AlreadyExistsException(org.jboss.jca.core.spi.mdr.AlreadyExistsException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) DeployException(org.jboss.jca.deployers.common.DeployException)

Example 4 with ConnectionManager

use of org.jboss.jca.core.connectionmanager.ConnectionManager in project wildfly by wildfly.

the class ConnectionDefinitionStatisticsService method start.

@Override
public void start(StartContext context) throws StartException {
    ROOT_LOGGER.debugf("Starting ConnectionDefinitionStatisticsService %s", jndiName);
    synchronized (this) {
        final CommonDeployment deploymentMD = deployment.getValue().getDeployment();
        PathElement pePoolStats = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
        PathElement peExtendedStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
        if (deploymentMD.getConnector() != null && deploymentMD.getConnector().getConnectionFactories() != null) {
            for (ConnectionFactory cf : deploymentMD.getConnector().getConnectionFactories()) {
                if (cf.getManagedConnectionFactory() != null && cf.getManagedConnectionFactory().getStatistics() != null) {
                    StatisticsPlugin extendStats = cf.getManagedConnectionFactory().getStatistics();
                    extendStats.setEnabled(statsEnabled);
                    if (extendStats.getNames().size() != 0) {
                        if (extendStats.getNames().size() != 0 && overrideRegistration.getSubModel(PathAddress.pathAddress(peExtendedStats)) == null) {
                            overrideRegistration.registerSubModel(new StatisticsResourceDefinition(peExtendedStats, CommonAttributes.RESOURCE_NAME, extendStats));
                        }
                    }
                }
            }
        }
        if (deploymentMD.getConnectionManagers() != null) {
            for (ConnectionManager cm : deploymentMD.getConnectionManagers()) {
                if (cm.getPool() != null && cm.getJndiName() != null && cm.getJndiName().equals(jndiName)) {
                    StatisticsPlugin poolStats = cm.getPool().getStatistics();
                    poolStats.setEnabled(statsEnabled);
                    if (poolStats.getNames().size() != 0) {
                        if (poolStats.getNames().size() != 0 && overrideRegistration.getSubModel(PathAddress.pathAddress(pePoolStats)) == null) {
                            overrideRegistration.registerSubModel(new StatisticsResourceDefinition(pePoolStats, CommonAttributes.RESOURCE_NAME, poolStats));
                        }
                    }
                }
            }
        }
    }
}
Also used : CommonDeployment(org.jboss.jca.deployers.common.CommonDeployment) StatisticsResourceDefinition(org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition) ConnectionFactory(org.jboss.jca.core.api.management.ConnectionFactory) ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) PathElement(org.jboss.as.controller.PathElement) StatisticsPlugin(org.jboss.jca.core.spi.statistics.StatisticsPlugin)

Example 5 with ConnectionManager

use of org.jboss.jca.core.connectionmanager.ConnectionManager in project wildfly by wildfly.

the class JcaTestsUtil method exctractPoolConfiguration.

public static PoolConfiguration exctractPoolConfiguration(Object connectionFactory) {
    ConnectionManager cm = extractConnectionManager(connectionFactory);
    // org.jboss.jca.core.connectionmanager.pool.strategy.OnePool
    Pool pool = cm.getPool();
    Class<?> clz = pool.getClass();
    // org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool
    clz = clz.getSuperclass();
    // org.jboss.jca.core.connectionmanager.pool.AbstractPool
    clz = clz.getSuperclass();
    try {
        Method getPoolConfiguration = clz.getDeclaredMethod("getPoolConfiguration");
        getPoolConfiguration.setAccessible(true);
        return (PoolConfiguration) getPoolConfiguration.invoke(pool);
    } catch (Throwable t) {
        fail(t.getMessage());
    }
    return null;
}
Also used : PoolConfiguration(org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration) ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) Pool(org.jboss.jca.core.connectionmanager.pool.api.Pool) ManagedConnectionPool(org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool) Method(java.lang.reflect.Method)

Aggregations

ConnectionManager (org.jboss.jca.core.connectionmanager.ConnectionManager)5 Method (java.lang.reflect.Method)2 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)2 PathElement (org.jboss.as.controller.PathElement)2 ConnectionFactory (org.jboss.jca.core.api.management.ConnectionFactory)2 ManagedConnectionPool (org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool)2 StatisticsPlugin (org.jboss.jca.core.spi.statistics.StatisticsPlugin)2 CommonDeployment (org.jboss.jca.deployers.common.CommonDeployment)2 URISyntaxException (java.net.URISyntaxException)1 Locale (java.util.Locale)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ClearStatisticsHandler (org.jboss.as.connector.dynamicresource.ClearStatisticsHandler)1 PoolMetrics (org.jboss.as.connector.subsystems.common.pool.PoolMetrics)1 IronJacamarResource (org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource)1 IronJacamarResourceDefinition (org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResourceDefinition)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 ResourceBuilder (org.jboss.as.controller.ResourceBuilder)1 OverrideDescriptionProvider (org.jboss.as.controller.descriptions.OverrideDescriptionProvider)1