use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.
the class JdbcConnectionPoolDeployer method handlePoolRecreation.
private void handlePoolRecreation(final ConnectorConnectionPool connConnPool) throws ConnectorRuntimeException {
debug("[DRC] Pool recreation required");
final long reconfigWaitTimeout = connConnPool.getDynamicReconfigWaitTimeout();
PoolInfo poolInfo = new PoolInfo(connConnPool.getName(), connConnPool.getApplicationName(), connConnPool.getModuleName());
final ResourcePool oldPool = runtime.getPoolManager().getPool(poolInfo);
if (reconfigWaitTimeout > 0) {
oldPool.blockRequests(reconfigWaitTimeout);
if (oldPool.getPoolWaitQueue().getQueueLength() > 0 || oldPool.getPoolStatus().getNumConnUsed() > 0) {
Runnable thread = new Runnable() {
@Override
public void run() {
try {
// poll every 5 seconds
long numSeconds = 5000L;
long steps = reconfigWaitTimeout / numSeconds;
if (steps == 0) {
waitForCompletion(steps, oldPool, reconfigWaitTimeout);
} else {
for (long i = 0; i < steps; i++) {
waitForCompletion(steps, oldPool, reconfigWaitTimeout);
if (oldPool.getPoolWaitQueue().getQueueLength() == 0 && oldPool.getPoolStatus().getNumConnUsed() == 0) {
debug("wait-queue is empty and num-con-used is 0");
break;
}
}
}
handlePoolRecreationForExistingProxies(connConnPool);
PoolWaitQueue reconfigWaitQueue = oldPool.getReconfigWaitQueue();
debug("checking reconfig-wait-queue for notification");
if (reconfigWaitQueue.getQueueContents().size() > 0) {
for (Object o : reconfigWaitQueue.getQueueContents()) {
debug("notifying reconfig-wait-queue object [ " + o + " ]");
synchronized (o) {
o.notify();
}
}
}
} catch (InterruptedException ie) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "Interrupted while waiting for all existing clients to return connections to pool", ie);
}
}
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("woke-up after giving time for in-use connections to return, " + "WaitQueue-Length : [" + oldPool.getPoolWaitQueue().getQueueContents() + "], " + "Num-Conn-Used : [" + oldPool.getPoolStatus().getNumConnUsed() + "]");
}
}
};
Callable c = Executors.callable(thread);
ArrayList list = new ArrayList();
list.add(c);
try {
execService.invokeAll(list);
} catch (Exception e) {
Object[] params = new Object[] { connConnPool.getName(), e };
_logger.log(Level.WARNING, "exception.redeploying.pool.transparently", params);
}
} else {
handlePoolRecreationForExistingProxies(connConnPool);
}
} else if (oldPool.getReconfigWaitTime() > 0) {
// reconfig is being switched off, invalidate proxies
Collection<BindableResource> resources = JdbcResourcesUtil.getResourcesOfPool(runtime.getResources(oldPool.getPoolInfo()), oldPool.getPoolInfo().getName());
ConnectorRegistry registry = ConnectorRegistry.getInstance();
for (BindableResource resource : resources) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
registry.removeResourceFactories(resourceInfo);
}
// recreate the pool now.
recreatePool(connConnPool);
} else {
recreatePool(connConnPool);
}
}
use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.
the class DeleteJndiResourceTest method testExecuteSuccessDefaultTarget.
/**
* Test of execute method, of class DeleteJndiResource.
* asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
* sample_jndi_resource
* delete-jndi-resource sample_jndi_resource
*/
@Test
public void testExecuteSuccessDefaultTarget() {
parameters.set("restype", "topic");
parameters.set("jndilookupname", "sample_jndi");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("jndi_name", "sample_jndi_resource");
org.glassfish.resources.admin.cli.CreateJndiResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
cr.getCommandInvocation("create-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
parameters = new ParameterMap();
parameters.set("jndi_name", "sample_jndi_resource");
org.glassfish.resources.admin.cli.DeleteJndiResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteJndiResource.class);
cr.getCommandInvocation("delete-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isDeleted = true;
for (Resource resource : resources.getResources()) {
if (resource instanceof BindableResource) {
BindableResource jr = (BindableResource) resource;
if (jr.getJndiName().equals("sample_jndi_resource")) {
isDeleted = false;
logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
break;
}
}
}
assertTrue(isDeleted);
logger.fine("msg: " + context.getActionReport().getMessage());
Servers servers = habitat.getService(Servers.class);
boolean isRefDeleted = true;
for (Server server : servers.getServer()) {
if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
for (ResourceRef ref : server.getResourceRef()) {
if (ref.getRef().equals("sample_jndi_resource")) {
isRefDeleted = false;
break;
}
}
}
}
assertTrue(isRefDeleted);
}
use of com.sun.enterprise.config.serverbeans.BindableResource 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;
}
use of com.sun.enterprise.config.serverbeans.BindableResource 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.BindableResource 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;
}
Aggregations