use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class AppSpecificConnectorClassLoaderUtil method getApplicationScopedResource.
private <T> Resource getApplicationScopedResource(String name, 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) {
resources = appInfo.getTransientAppMetaData(app.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_APP_SCOPE_PREFIX))) {
resourceName = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + resourceName;
}
if (!(name.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
name = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + name;
}
if (name.equals(resourceName)) {
foundRes = res;
break;
}
}
}
}
}
return foundRes;
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class JdbcResourcesUtil method getResourcesOfPool.
public static Collection<BindableResource> getResourcesOfPool(Resources resources, String connectionPoolName) {
Set<BindableResource> resourcesReferringPool = new HashSet<BindableResource>();
ResourcePool pool = (ResourcePool) getResourceByName(resources, ResourcePool.class, connectionPoolName);
if (pool != null) {
Collection<BindableResource> bindableResources = resources.getResources(BindableResource.class);
for (BindableResource resource : bindableResources) {
if (JdbcResource.class.isAssignableFrom(resource.getClass())) {
if ((((JdbcResource) resource).getPoolName()).equals(connectionPoolName)) {
resourcesReferringPool.add(resource);
}
}
}
}
return resourcesReferringPool;
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class RegistrationSupport method processResourceRef.
/**
* Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
* and if so, register a JSR 77 MBean for it.
*/
public ObjectName processResourceRef(final ResourceRef ref) {
if (ref == null) {
throw new IllegalArgumentException("resource-ref is null");
}
if (!mServer.getName().equals(ref.getParent(Server.class).getName())) {
cdebug("ResourceRef is not a child of server " + getObjectName(mServer));
return null;
}
// find the referenced resource
Resource res = null;
List<Resource> resources = getDomain().getResources().getResources();
for (Resource resource : resources) {
String name = null;
if (resource instanceof BindableResource) {
name = ((BindableResource) resource).getJndiName();
}
if (resource instanceof Named) {
name = ((Named) resource).getName();
}
if (resource instanceof ResourcePool) {
name = ((ResourcePool) resource).getName();
}
if (name != null && name.equals(ref.getRef()))
res = resource;
}
if (res == null) {
throw new IllegalArgumentException("ResourceRef refers to non-existent resource: " + ref);
}
final String configType = Util.getTypeProp(getObjectName(res));
final Class<J2EEManagedObjectImplBase> implClass = CONFIG_RESOURCE_TYPES.get(configType);
if (implClass == null) {
mLogger.fine("Unrecognized resource type for JSR 77 purposes: " + getObjectName(res));
return null;
}
final Class<J2EEManagedObject> intf = (Class) ClassUtil.getFieldValue(implClass, "INTF");
ObjectName mbean77 = null;
try {
final MetadataImpl meta = new MetadataImpl();
meta.setCorrespondingRef(getObjectName(ref));
meta.setCorrespondingConfig(getObjectName(res));
mbean77 = registerJ2EEChild(mJ2EEServer.objectName(), meta, intf, implClass, Util.getNameProp(getObjectName(res)));
synchronized (mConfigRefTo77) {
mConfigRefTo77.put(getObjectName(ref), mbean77);
}
} catch (final Exception e) {
mLogger.log(Level.INFO, AMXEELoggerInfo.cantRegisterMbean, new Object[] { getObjectName(ref), e });
}
// cdebug( "Registered " + child + " for config resource " + amx.objectName() );
return mbean77;
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class ConnectorConnectionPoolAdminServiceImpl method getUnpooledConnection.
/**
* This method is used to provide backend functionality for the
* ping-connection-pool asadmin command. Briefly the design is as
* follows:<br>
* 1. obtainManagedConnectionFactory for the poolname<br>
* 2. lookup ConnectorDescriptorInfo from InitialContext using poolname<br>
* 3. from cdi get username and password<br>
* 4. create ResourcePrincipal using default username and password<br>
* 5. create a Subject from this (doPriveleged)<br>
* 6. createManagedConnection using above subject<br>
* 7. add a dummy ConnectionEventListener to the mc that simply handles connectionClosed
* 8. getConnection from the ManagedConnection with above subject<br>
*
* @param poolInfo The poolname from whose MCF to obtain the unpooled mc
* @param principal The ResourcePrincipal to use for authenticating the request if not null.
* If null, the pool's default authentication mechanism is used
* @param returnConnectionHandle If true will return the logical connection handle
* derived from the Managed Connection, else will only return mc
* @return an unPooled connection
* @throws ResourceException for various error conditions
*/
public Object getUnpooledConnection(PoolInfo poolInfo, ResourcePrincipal principal, boolean returnConnectionHandle) throws ResourceException {
ManagedConnectionFactory mcf = null;
ResourcePool poolToDeploy = null;
boolean needToUndeployPool = false;
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
try {
// START CR 6597868
if (!isPoolReferredByResource(poolInfo)) {
if (_registry.isMCFCreated(poolInfo)) {
unloadAndKillPool(poolInfo);
}
}
// END CR 6597868
mcf = obtainManagedConnectionFactory(poolInfo, new Hashtable());
} catch (ConnectorRuntimeException re) {
logFine("getUnpooledConnection :: obtainManagedConnectionFactory " + "threw exception. So doing checkAndLoadPoolResource");
if (checkAndLoadPool(poolInfo)) {
logFine("getUnpooledConnection:: checkAndLoadPoolResource is true");
try {
// remote instance, the pool will not have been created
if (!isConnectorConnectionPoolDeployed(poolInfo)) {
logFine("getUnpooledConnection :: isConnectorConnectionPoolDeployed is false");
try {
poolToDeploy = (ResourcePool) ConnectorsUtil.getResourceByName(runtime.getResources(poolInfo), ResourcePool.class, poolInfo.getName());
runtime.getResourceDeployer(poolToDeploy).deployResource(poolToDeploy);
logFine("getUnpooledConnection :: force deployed the ConnectionPool : " + poolInfo);
needToUndeployPool = true;
} catch (Exception e) {
_logger.log(Level.SEVERE, "jdbc.could_not_do_actual_deploy for : ", poolInfo);
throw new ResourceException(e);
}
}
logFine("getUnpooledConnection :: Now calling obtainManagedConnectionFactory again");
mcf = obtainManagedConnectionFactory(poolInfo);
logFine("getUnpooledConnection:: done obtainManagedConnectionFactory again");
} catch (ConnectorRuntimeException creAgain) {
String l10nMsg = localStrings.getString("pingpool.cannot_obtain_mcf", poolInfo);
_logger.log(Level.WARNING, "jdbc.pool_not_reachable", l10nMsg);
ResourceException e = new ResourceException(l10nMsg);
e.initCause(creAgain);
throw e;
}
} else {
_logger.log(Level.WARNING, "jdbc.pool_not_reachable", re.getMessage());
String l10nMsg = localStrings.getString("pingpool.cannot_obtain_mcf", poolInfo);
ResourceException e = new ResourceException(l10nMsg);
e.initCause(re);
throw e;
}
}
ResourcePrincipal resourcePrincipal = null;
if (principal == null) {
try {
resourcePrincipal = getDefaultResourcePrincipal(poolInfo, mcf);
} catch (NamingException ne) {
_logger.log(Level.WARNING, "jdbc.pool_not_reachable", ne.getMessage());
String l10nMsg = localStrings.getString("pingpool.name_not_bound", poolInfo);
ResourceException e = new ResourceException(l10nMsg + poolInfo);
e.initCause(ne);
throw e;
}
} else {
resourcePrincipal = principal;
}
final Subject defaultSubject = ConnectionPoolObjectsUtils.createSubject(mcf, resourcePrincipal);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("using subject: " + defaultSubject);
}
// Create the ManagedConnection
ManagedConnection mc = mcf.createManagedConnection(defaultSubject, null);
// it here
if (needToUndeployPool) {
if (poolToDeploy != null) {
logFine("getUnpooledConnection :: need to force undeploy pool");
try {
runtime.getResourceDeployer(poolToDeploy).undeployResource(poolToDeploy);
} catch (Exception e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("getUnpooledConnection: error undeploying pool");
}
}
logFine("getUnpooledConnection :: done.. force undeploy of pool");
}
}
// Add our dummy ConnectionEventListener impl.
// This impl only knows how to handle connectionClosed events
mc.addConnectionEventListener(new UnpooledConnectionEventListener());
return returnConnectionHandle ? mc.getConnection(defaultSubject, null) : mc;
}
use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.
the class ConnectorService method checkAndLoadPool.
public boolean checkAndLoadPool(PoolInfo poolInfo) {
boolean status = false;
try {
ResourcePool pool = _runtime.getConnectionPoolConfig(poolInfo);
// DeferredResourceConfig defResConfig = resutil.getDeferredPoolConfig(poolName);
DeferredResourceConfig defResConfig = getResourcesUtil().getDeferredResourceConfig(null, pool, null, null);
status = loadResourcesAndItsRar(defResConfig);
} catch (ConnectorRuntimeException cre) {
Object[] params = new Object[] { poolInfo, cre };
_logger.log(Level.WARNING, "unable.to.load.connection.pool", params);
}
return status;
}
Aggregations