use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class JdbcPoolMonitoringExtension method registerConnectionPool.
/**
* Register the jdbc connection pool Stats Provider object to the
* monitoring framework under the specific application name monitoring
* sub tree.
*
* @param appName
* @return
*/
@Override
public ConnectionPoolAppProbeProvider registerConnectionPool(PoolInfo poolInfo, String appName) {
ConnectionPoolAppProbeProvider probeAppProvider = null;
ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
if (pool instanceof JdbcConnectionPool) {
probeAppProvider = new JdbcConnPoolAppProbeProvider();
JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider = new JdbcConnPoolAppStatsProvider(poolInfo, appName);
StatsProviderManager.register("jdbc-connection-pool", PluginPoint.SERVER, "resources/" + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName()) + "/" + appName, jdbcPoolAppStatsProvider);
jdbcPoolAppStatsProviders.add(jdbcPoolAppStatsProvider);
}
return probeAppProvider;
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class ConnectionPoolStatsProviderBootstrap method poolCreated.
/**
* When a pool is created (or initialized) the pool should be registered
* to the StatsProviderManager. Also, the pool lifecycle
* listener needs to be registered for this pool to track events on change
* of any monitoring attributes.
* @param poolInfo
*/
public void poolCreated(PoolInfo poolInfo) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Pool created : " + poolInfo);
}
if (runtime.isServer()) {
ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
Collection<ConnectionPoolMonitoringExtension> extensions = habitat.getAllServices(ConnectionPoolMonitoringExtension.class);
for (ConnectionPoolMonitoringExtension extension : extensions) {
extension.registerPool(poolInfo);
}
if (pool instanceof ConnectorConnectionPool) {
registerCcPool(poolInfo);
}
/*else if (poolInfo.getName().contains(ConnectorConstants.DATASOURCE_DEFINITION_JNDINAME_PREFIX)){
registerJdbcPool(poolInfo);
}*/
}
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class ConnectionPoolStatsProviderBootstrap method registerCcPool.
/**
* Register connector connection pool to the StatsProviderManager.
* Add the pool lifecycle listeners for the pool to receive events on
* change of any of the monitoring attribute values.
* Finally, add this provider to the list of connector connection pool
* providers maintained.
* @param poolInfo
*/
private void registerCcPool(PoolInfo poolInfo) {
if (poolManager.getPool(poolInfo) != null) {
getProbeProviderUtil().createJcaProbeProvider();
// Found in the pool table (pool has been initialized/created)
ConnectorConnPoolStatsProvider ccPoolStatsProvider = new ConnectorConnPoolStatsProvider(poolInfo, logger);
StatsProviderManager.register("connector-connection-pool", PluginPoint.SERVER, ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true), ccPoolStatsProvider);
PoolLifeCycleListenerRegistry registry = registerPool(poolInfo, getProbeProviderUtil().getJcaProbeProvider());
ccPoolStatsProvider.setPoolRegistry(registry);
ccStatsProviders.add(ccPoolStatsProvider);
if (!ConnectorsUtil.isApplicationScopedResource(poolInfo)) {
ResourcesUtil resourcesUtil = ResourcesUtil.createInstance();
ResourcePool pool = resourcesUtil.getPoolConfig(poolInfo);
Resources resources = resourcesUtil.getResources(poolInfo);
String raName = resourcesUtil.getRarNameOfResource(pool, resources);
ConnectorConnPoolStatsProvider connectorServicePoolStatsProvider = new ConnectorConnPoolStatsProvider(poolInfo, logger);
String dottedNamesHierarchy = null;
String monitoringModuleName = null;
if (ConnectorsUtil.isJMSRA(raName)) {
monitoringModuleName = ConnectorConstants.MONITORING_JMS_SERVICE_MODULE_NAME;
dottedNamesHierarchy = ConnectorConstants.MONITORING_JMS_SERVICE + ConnectorConstants.MONITORING_SEPARATOR + ConnectorConstants.MONITORING_CONNECTION_FACTORIES + ConnectorConstants.MONITORING_SEPARATOR + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName());
} else {
monitoringModuleName = ConnectorConstants.MONITORING_CONNECTOR_SERVICE_MODULE_NAME;
dottedNamesHierarchy = ConnectorConstants.MONITORING_CONNECTOR_SERVICE_MODULE_NAME + ConnectorConstants.MONITORING_SEPARATOR + raName + ConnectorConstants.MONITORING_SEPARATOR + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName());
}
StatsProviderManager.register(monitoringModuleName, PluginPoint.SERVER, dottedNamesHierarchy, connectorServicePoolStatsProvider);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Registered pool-monitoring stats [ " + dottedNamesHierarchy + " ] " + "for [ " + raName + " ] with monitoring-stats-registry.");
}
/* no need to create multiple probe provider instances, one per pool will
work for multiple stats providers
PoolLifeCycleListenerRegistry poolLifeCycleListenerRegistry = registerPool(
poolInfo, getProbeProviderUtil().getJcaProbeProvider());
*/
connectorServicePoolStatsProvider.setPoolRegistry(registry);
ccStatsProviders.add(connectorServicePoolStatsProvider);
}
}
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class ConnectorObjectFactory method getObjectInstance.
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception {
Reference ref = (Reference) obj;
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ConnectorObjectFactory: " + ref + " Name:" + name);
}
PoolInfo poolInfo = (PoolInfo) ref.get(0).getContent();
String moduleName = (String) ref.get(1).getContent();
ResourceInfo resourceInfo = (ResourceInfo) ref.get(2).getContent();
if (getRuntime().isACCRuntime() || getRuntime().isNonACCRuntime()) {
ConnectorDescriptor connectorDescriptor = null;
String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
Context ic = new InitialContext(env);
connectorDescriptor = (ConnectorDescriptor) ic.lookup(descriptorJNDIName);
try {
getRuntime().createActiveResourceAdapter(connectorDescriptor, moduleName, null);
} catch (ConnectorRuntimeException e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Failed to look up ConnectorDescriptor from JNDI", moduleName);
}
NamingException ne = new NamingException("Failed to look up ConnectorDescriptor from JNDI");
ne.setRootCause(e);
throw ne;
}
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (!getRuntime().checkAccessibility(moduleName, loader)) {
String msg = localStrings.getString("cof.no_access_to_embedded_rar", moduleName);
throw new NamingException(msg);
}
Object cf = null;
try {
ManagedConnectionFactory mcf = getRuntime().obtainManagedConnectionFactory(poolInfo, env);
if (mcf == null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Failed to create MCF ", poolInfo);
}
throw new ConnectorRuntimeException("Failed to create MCF");
}
boolean forceNoLazyAssoc = false;
String jndiName = name.toString();
if (jndiName.endsWith(ConnectorConstants.PM_JNDI_SUFFIX)) {
forceNoLazyAssoc = true;
}
String derivedJndiName = ConnectorsUtil.deriveJndiName(jndiName, env);
ConnectionManagerImpl mgr = (ConnectionManagerImpl) getRuntime().obtainConnectionManager(poolInfo, forceNoLazyAssoc, resourceInfo);
mgr.setJndiName(derivedJndiName);
mgr.setRarName(moduleName);
String logicalName = (String) env.get(GlassfishNamingManager.LOGICAL_NAME);
if (logicalName != null) {
mgr.setLogicalName(logicalName);
}
mgr.initialize();
cf = mcf.createConnectionFactory(mgr);
if (cf == null) {
String msg = localStrings.getString("cof.no.resource.adapter");
throw new RuntimeException(new ConfigurationException(msg));
}
if (getRuntime().isServer() || getRuntime().isEmbedded()) {
ConnectorRegistry registry = ConnectorRegistry.getInstance();
if (registry.isTransparentDynamicReconfigPool(poolInfo)) {
Resources resources = getRuntime().getResources(poolInfo);
ResourcePool resourcePool = null;
if (resources != null) {
resourcePool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolInfo.getName());
if (resourcePool != null) {
ResourceDeployer deployer = getRuntime().getResourceDeployer(resourcePool);
if (deployer != null && deployer.supportsDynamicReconfiguration() && ConnectorsUtil.isDynamicReconfigurationEnabled(resourcePool)) {
Object o = env.get(ConnectorConstants.DYNAMIC_RECONFIGURATION_PROXY_CALL);
if (o == null || Boolean.valueOf(o.toString()).equals(false)) {
// TODO use list ? (even in the ResourceDeployer API)
Class[] classes = deployer.getProxyClassesForDynamicReconfiguration();
Class[] proxyClasses = new Class[classes.length + 1];
for (int i = 0; i < classes.length; i++) {
proxyClasses[i] = classes[i];
}
proxyClasses[proxyClasses.length - 1] = DynamicallyReconfigurableResource.class;
cf = getProxyObject(cf, proxyClasses, resourceInfo);
}
}
}
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Connection Factory:" + cf);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return cf;
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class AppSpecificConnectorClassLoaderUtil method getModuleScopedResource.
private <T> Resource getModuleScopedResource(String name, String moduleName, Class<T> type, ApplicationInfo appInfo) {
Resource foundRes = null;
if (appInfo != null) {
com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
Resources resources = null;
if (app != null) {
Module module = null;
List<Module> modules = app.getModule();
for (Module m : modules) {
if (ConnectorsUtil.getActualModuleName(m.getName()).equals(moduleName)) {
module = m;
break;
}
}
if (module != null) {
resources = appInfo.getTransientAppMetaData(module.getName() + "-resources", Resources.class);
}
}
if (resources != null) {
boolean bindableResource = BindableResource.class.isAssignableFrom(type);
boolean poolResource = ResourcePool.class.isAssignableFrom(type);
boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
Iterator itr = resources.getResources().iterator();
while (itr.hasNext()) {
String resourceName = null;
Resource res = (Resource) itr.next();
if (bindableResource && res instanceof BindableResource) {
resourceName = ((BindableResource) res).getJndiName();
} else if (poolResource && res instanceof ResourcePool) {
resourceName = ((ResourcePool) res).getName();
} else if (rac && res instanceof ResourceAdapterConfig) {
resourceName = ((ResourceAdapterConfig) res).getName();
} else if (workSecurityMap && res instanceof WorkSecurityMap) {
resourceName = ((WorkSecurityMap) res).getName();
}
if (resourceName != null) {
if (!(resourceName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
resourceName = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + resourceName;
}
if (!(name.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
name = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + name;
}
if (name.equals(resourceName)) {
foundRes = res;
break;
}
}
}
}
}
return foundRes;
}
Aggregations