use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.
the class PingConnectionPool method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
boolean status = false;
Resources resources = domain.getResources();
String scope = "";
if (moduleName != null) {
if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
return;
}
Application application = applications.getApplication(applicationName);
Module module = application.getModule(moduleName);
resources = module.getResources();
scope = "java:module/";
} else if (applicationName != null) {
if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
return;
}
Application application = applications.getApplication(applicationName);
resources = application.getResources();
scope = "java:app/";
}
if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
return;
}
PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
try {
status = connRuntime.pingConnectionPool(poolInfo);
if (status) {
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} else {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
}
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.
the class ConnectorConnPoolStatsProvider method decrementNumConnFreeEvent.
/**
* Decrement numconnfree event
* @param poolName
*/
@ProbeListener(JCA_PROBE_LISTENER + "decrementNumConnFreeEvent")
public void decrementNumConnFreeEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName, @ProbeParam("moduleName") String moduleName) {
// handle the num conn free decrement event
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
if (this.poolInfo.equals(poolInfo)) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Decrement Num Connections Free event received - poolName = " + poolName);
}
// Decrement counter
synchronized (numConnFree) {
long numConnFreeSafe = (numConnFree.getCurrent() - 1 >= 0) ? numConnFree.getCurrent() - 1 : 0;
numConnFree.setCurrent(numConnFreeSafe);
}
}
}
use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.
the class ConnectorConnPoolStatsProvider method connectionRequestServedEvent.
/**
* Event that a connection request is served in timeTakenInMillis.
*
* @param poolName
* @param timeTakenInMillis
*/
@ProbeListener(JCA_PROBE_LISTENER + "connectionRequestServedEvent")
public void connectionRequestServedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName, @ProbeParam("moduleName") String moduleName, @ProbeParam("timeTakenInMillis") long timeTakenInMillis) {
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
if (this.poolInfo.equals(poolInfo)) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Connection request served event received - " + "poolName = " + poolName);
}
connRequestWaitTime.setCurrent(timeTakenInMillis);
totalConnRequestWaitTime.increment(timeTakenInMillis);
}
}
use of org.glassfish.resourcebase.resources.api.PoolInfo 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 org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.
the class PoolManagerImpl method killFreeConnectionsInPools.
public void killFreeConnectionsInPools() {
Iterator pools = poolTable.values().iterator();
logFine("Killing all free connections in pools");
while (pools.hasNext()) {
ResourcePool pool = (ResourcePool) pools.next();
if (pool != null) {
PoolInfo poolInfo = pool.getPoolStatus().getPoolInfo();
try {
if (poolInfo != null) {
ResourcePool poolToKill = poolTable.get(poolInfo);
if (poolToKill != null) {
pool.emptyFreeConnectionsInPool();
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Now killing free connections in pool : " + poolInfo);
}
}
} catch (Exception e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Error killing pool : " + poolInfo + " :: " + (e.getMessage() != null ? e.getMessage() : " "));
}
}
}
}
}
Aggregations