ResourceAdapterAdminServiceImplpublic class ResourceAdapterAdminServiceImpl extends ConnectorServiceImpl implements ConnectorAdminServiceThis is resource adapter admin service. It creates, deletes Resource adapter
and also the resource adapter configuration updation. |
Fields Summary |
---|
private JmsRaMapping | ramap | private int | resource_adapter_shutdown_timeout | private final Hashtable | raShutdownStatusTable |
Constructors Summary |
---|
public ResourceAdapterAdminServiceImpl()Default constructor
super();
ramap= new JmsRaMapping();
|
Methods Summary |
---|
public void | addResourceAdapterConfig(java.lang.String rarName, ResourceAdapterConfig raConfig)
if (rarName != null && raConfig != null) {
_registry.addResourceAdapterConfig(rarName, raConfig);
reCreateActiveResourceAdapter(rarName);
}
| public synchronized void | createActiveResourceAdapter(ConnectorDescriptor connectorDescriptor, java.lang.String moduleName, java.lang.String moduleDir)Creates Active resource Adapter which abstracts the rar module. During
the creation of ActiveResourceAdapter, default pools and resources also
are created.
_logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA "
+ moduleName + " at " + moduleDir );
ActiveResourceAdapter activeResourceAdapter=
_registry.getActiveResourceAdapter(moduleName);
if (activeResourceAdapter != null) {
_logger.log(
Level.FINE,
"rardeployment.resourceadapter.already.started",
moduleName);
return;
}
ClassLoader loader= null;
try {
loader= connectorDescriptor.getClassLoader();
} catch (Exception ex) {
_logger.log(
Level.FINE,
"No classloader available with connector descriptor");
loader= null;
}
ModuleDescriptor moduleDescriptor= null;
Application application = null;
_logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA "
+ moduleName + " at " + moduleDir + " loader :: " + loader);
if (loader == null) {
if (environment == SERVER) {
ConnectorClassLoader.getInstance().addResourceAdapter(moduleName, moduleDir);
loader = ConnectorClassLoader.getInstance();
if (loader == null) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Failed to obtain the class loader");
_logger.log(
Level.SEVERE,
"rardeployment.failed_toget_classloader");
_logger.log(Level.SEVERE, "", cre);
throw cre;
}
}
} else {
connectorDescriptor.setClassLoader(null);
moduleDescriptor= connectorDescriptor.getModuleDescriptor();
application = connectorDescriptor.getApplication();
connectorDescriptor.setModuleDescriptor(null);
connectorDescriptor.setApplication(null);
}
try {
activeResourceAdapter=
ActiveRAFactory.createActiveResourceAdapter(
connectorDescriptor,
moduleName,
loader);
_logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " +
moduleName + " at " + moduleDir +
" ADDING to registry " + activeResourceAdapter);
_registry.addActiveResourceAdapter(
moduleName,
activeResourceAdapter);
_logger.fine("ResourceAdapterAdminServiceImpl:: createActiveRA " +
moduleName + " at " + moduleDir
+ " env =server ? " + (environment==SERVER));
if (environment == SERVER) {
activeResourceAdapter.setup();
String descriptorJNDIName = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForDescriptor(moduleName);
_logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA "
+ moduleName + " at " + moduleDir
+ " publishing descriptor " + descriptorJNDIName);
//Update RAConfig in Connector Descriptor and bind in JNDI
//so that ACC clients could use RAConfig
updateRAConfigInDescriptor(connectorDescriptor, moduleName);
Switch.getSwitch().getNamingManager().publishObject(
descriptorJNDIName, connectorDescriptor, true);
String securityWarningMessage=
getRuntime().getSecurityPermissionSpec(moduleName);
// To i18N.
if (securityWarningMessage != null) {
_logger.log(Level.WARNING, securityWarningMessage);
}
}
} catch (NullPointerException npEx) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Error in creating active RAR");
cre.initCause(npEx);
_logger.log(
Level.SEVERE,
"rardeployment.nullPointerException",
moduleName);
_logger.log(Level.SEVERE, "", cre);
throw cre;
} catch (NamingException ne) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Error in creating active RAR");
cre.initCause(ne);
_logger.log(Level.SEVERE, "rardeployment.jndi_publish_failure");
_logger.log(Level.SEVERE, "", cre);
throw cre;
} finally {
if (moduleDescriptor != null) {
connectorDescriptor.setModuleDescriptor(moduleDescriptor);
connectorDescriptor.setApplication(application);
connectorDescriptor.setClassLoader(loader);
}
}
| public synchronized void | createActiveResourceAdapter(java.lang.String moduleDir, java.lang.String moduleName)Creates Active resource Adapter which abstracts the rar module. During
the creation of ActiveResourceAdapter, default pools and resources also
are created.
ActiveResourceAdapter activeResourceAdapter=
_registry.getActiveResourceAdapter(moduleName);
if (activeResourceAdapter != null) {
_logger.log(
Level.FINE,
"rardeployment.resourceadapter.already.started",
moduleName);
return;
}
if (ResourcesUtil.createInstance().belongToSystemRar(moduleName)) {
moduleDir = Switch.getSwitch().getResourceInstaller().
getSystemModuleLocation(moduleName);
}
ConnectorDescriptor connectorDescriptor= null;
connectorDescriptor=
ConnectorDDTransformUtils.getConnectorDescriptor(moduleDir);
if (connectorDescriptor == null) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Failed to obtain the connectorDescriptor");
_logger.log(
Level.SEVERE,
"rardeployment.connector_descriptor_notfound",
moduleName);
_logger.log(Level.SEVERE, "", cre);
throw cre;
}
createActiveResourceAdapter(
connectorDescriptor,
moduleName,
moduleDir);
| public void | deleteResourceAdapterConfig(java.lang.String rarName)Delete the resource adapter configuration to the connector registry
if (rarName != null) {
_registry.removeResourceAdapterConfig(rarName);
}
| public void | destroyActiveResourceAdapter(java.lang.String moduleName)Destroys/deletes the Active resource adapter object from the connector
container. Active resource adapter abstracts the rar deployed. It checks
whether any resources (pools and connector resources) are still present.
If they are present the deletion fails and all the objects and
datastructures pertaining to to the resource adapter are left untouched.
destroyActiveResourceAdapter(moduleName, false);
| public void | destroyActiveResourceAdapter(java.lang.String moduleName, boolean cascade)Destroys/deletes the Active resource adapter object from the connector
container. Active resource adapter abstracts the rar deployed. It checks
whether any resources (pools and connector resources) are still present.
If they are present and cascade option is false the deletion fails and
all the objects and datastructures pertaining to the resource adapter
are left untouched. If cascade option is true, even if resources are
still present, they are also destroyed with the active resource adapter
ResourcesUtil resutil= ResourcesUtil.createInstance();
if (resutil == null) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Failed to get ResourcesUtil object");
_logger.log(Level.SEVERE, "resourcesutil_get_failure", moduleName);
_logger.log(Level.SEVERE, "", cre);
throw cre;
}
Object[][] resources= null;
try {
resources= resutil.getAllConnectorResourcesForRar(moduleName);
} catch (ConfigException ce) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Failed to get Resources from domain.xml");
ce.initCause(ce);
_logger.log(
Level.SEVERE,
"rardeployment.resources_list_error",
cre);
throw cre;
}
boolean errrorOccured= false;
com.sun.enterprise.config.serverbeans.ConnectorConnectionPool ccp= null;
if (cascade == true && resources != null) {
for (int i= 0;
resources[0] != null && i < resources[0].length;
++i) {
ccp=
(com
.sun
.enterprise
.config
.serverbeans
.ConnectorConnectionPool) resources[0][i];
try {
getRuntime().deleteConnectorConnectionPool(
ccp.getName(),
cascade);
} catch (ConnectorRuntimeException cre) {
errrorOccured= true;
}
}
for (int i= 0;
resources[2] != null && i < resources[2].length;
++i) {
try {
AdminObjectResource aor=
(AdminObjectResource) resources[2][i];
getRuntime().deleteAdminObject(aor.getJndiName());
} catch (ConnectorRuntimeException cre) {
errrorOccured= true;
}
}
} else if (
(resources[0] != null && resources[0].length != 0)
|| (resources[1] != null && resources[1].length != 0)
|| (resources[2] != null && resources[2].length != 0)) {
_logger.log(
Level.SEVERE,
"rardeployment.pools_and_resources_exist",
moduleName);
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Error: Connector Connection Pools/resources exist.");
_logger.log(Level.SEVERE, "", cre);
throw cre;
}
if (!stopAndRemoveActiveResourceAdapter(moduleName)) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Failed to remove Active Resource Adapter");
_logger.log(
Level.SEVERE,
"rardeployment.ra_removal_registry_failure",
moduleName);
_logger.log(Level.SEVERE, "", cre);
throw cre;
}
//Embedded RARs are handled by the application classloader
if (!(ResourcesUtil.createInstance().belongToEmbeddedRar(moduleName))) {
ConnectorClassLoader.getInstance().removeResourceAdapter(moduleName);
}
if (errrorOccured == true) {
ConnectorRuntimeException cre=
new ConnectorRuntimeException("Failed to remove all connector resources/pools");
_logger.log(
Level.SEVERE,
"rardeployment.ra_resource_removal",
moduleName);
_logger.log(Level.SEVERE, "", cre);
throw cre;
}
| public JmsRaMapping | getJmsRaMapping()
return ramap;
| public static boolean | isJmsRa()
//return System.getProperty("jms.ra").equals("true");
return true;
| public boolean | isRarDeployed(java.lang.String moduleName)Checks if the rar module is already reployed.
ActiveResourceAdapter activeResourceAdapter=
_registry.getActiveResourceAdapter(moduleName);
if (activeResourceAdapter != null) {
return true;
} else {
return false;
}
| public void | reCreateActiveResourceAdapter(java.lang.String moduleName)The ActiveResourceAdapter object which abstract the rar module is
recreated in the connector container/registry. All the pools and
resources are killed. But the infrastructure to create the pools and and
resources is untouched. Only the actual pool is killed.
String moduleDir= null;
if (isRarDeployed(moduleName)) {
getRuntime().killAllPools(moduleName);
stopAndRemoveActiveResourceAdapter(moduleName);
moduleDir= ResourcesUtil.createInstance().getLocation(moduleName);
createActiveResourceAdapter(moduleDir, moduleName);
} else {
moduleDir= ResourcesUtil.createInstance().getLocation(moduleName);
if (moduleDir != null) {
createActiveResourceAdapter(moduleDir, moduleName);
}
}
| private void | sendStopToAllResourceAdapters(ActiveResourceAdapter[] resourceAdaptersToStop)Calls the stop method for all J2EE Connector 1.5 spec compliant RARs
//Only J2EE Connector 1.5 compliant RAs needs to be stopped
int numberOfResourceAdaptersToStop = 0;
numberOfResourceAdaptersToStop = resourceAdaptersToStop.length;
Thread[] raShutDownThreads = new Thread[numberOfResourceAdaptersToStop];
Thread[] joinerThreads = new Thread[numberOfResourceAdaptersToStop];
//Start ResourceAdapter shutdownthreads and then
//Start Threads to join the resource adapter shutdownThreads
for (int i = 0; i < numberOfResourceAdaptersToStop; i++) {
_logger.log(Level.FINE, "Starting RA shutdown thread for "
+ ( (ActiveInboundResourceAdapter)resourceAdaptersToStop[i] )
.getModuleName() );
Thread rast = new RAShutdownThread(
(ActiveInboundResourceAdapter)resourceAdaptersToStop[i]);
raShutDownThreads[i] = rast;
rast.start();
_logger.log(Level.FINE, "Starting Thread to join time-out " +
"shutdown of " +
( ( ActiveInboundResourceAdapter )resourceAdaptersToStop[i]).getModuleName() );
Thread joiner = new JoinerThread(raShutDownThreads[i]);
joinerThreads[i] = joiner;
joiner.start();
}
//Join all the Joiner threads
for (int i = 0; i < joinerThreads.length; i++) {
try {
_logger.log(Level.FINE, "Joining joiner thread of "
+ ((ActiveResourceAdapter)resourceAdaptersToStop[i])
.getModuleName() );
joinerThreads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_logger.log(Level.FINE, "stop() Complete for all " +
"active 1.5 compliant RARs");
//Log the status of the stop() call
if (resourceAdaptersToStop.length != 0) {
_logger.log(Level.FINE, "resource_adapter_stop_status");
}
for (Iterator iter = raShutdownStatusTable.keySet().iterator();
iter.hasNext();) {
String raName = (String) iter.next();
if(((Boolean)raShutdownStatusTable.get(raName)).booleanValue()) {
_logger.log(Level.INFO, "ra.stop-successful", raName);
} else {
_logger.log(Level.WARNING, "ra.stop-unsuccessful", raName);
}
}
| public void | stopAllActiveResourceAdapters()Calls the stop method for all J2EE Connector 1.5 spec compliant RARs
try {
resource_adapter_shutdown_timeout =
ResourcesUtil.createInstance().getShutdownTimeout();
} catch (ConnectorRuntimeException e) {
_logger.log(Level.WARNING, "error_reading_connectorservice_elt", e);
//Going ahead with the default timeout value
resource_adapter_shutdown_timeout
= ConnectorConstants.DEFAULT_RESOURCE_ADAPTER_SHUTDOWN_TIMEOUT;
}
ActiveResourceAdapter[] resourceAdapters =
ConnectorRegistry.getInstance().getAllActiveResourceAdapters();
//find all Connector 1.5 Spec Compliant resource adapters
ArrayList resourceAdaptersToStop = new ArrayList();
for (int i = 0; i < resourceAdapters.length; i++) {
if (resourceAdapters[i] instanceof ActiveInboundResourceAdapter){
_logger.log(Level.FINE, "Connector 1.5 spec compliant RA",
resourceAdapters[i].getModuleName());
raShutdownStatusTable.put(
resourceAdapters[i].getModuleName(), new Boolean(false));
resourceAdaptersToStop.add(resourceAdapters[i]);
} else {
_logger.log(Level.FINE, "Connector 1.0 spec compliant RA",
resourceAdapters[i].getModuleName());
}
}
ActiveResourceAdapter[] raToStop = (ActiveResourceAdapter[])
resourceAdaptersToStop.toArray(new ActiveResourceAdapter[]{});
sendStopToAllResourceAdapters(raToStop);
| public boolean | stopAndRemoveActiveResourceAdapter(java.lang.String moduleName)Stops the resourceAdapter and removes it from connector container/
registry.
ActiveResourceAdapter acr= null;
if (moduleName != null) {
acr= _registry.getActiveResourceAdapter(moduleName);
}
if (acr != null) {
acr.destroy();
boolean ret= _registry.removeActiveResourceAdapter(moduleName);
return ret;
}
return false;
| private void | updateRAConfigInDescriptor(ConnectorDescriptor connectorDescriptor, java.lang.String moduleName)
ResourceAdapterConfig raConfig =
ConnectorRegistry.getInstance().getResourceAdapterConfig(moduleName);
ElementProperty[] raConfigProps = null;
if(raConfig != null) {
raConfigProps = raConfig.getElementProperty();
}
_logger.fine("current RAConfig In Descriptor " + connectorDescriptor.getConfigProperties());
if(raConfigProps != null) {
Set mergedProps = ConnectorDDTransformUtils.mergeProps(
raConfigProps, connectorDescriptor.getConfigProperties());
Set actualProps = connectorDescriptor.getConfigProperties();
actualProps.clear();
actualProps.addAll(mergedProps);
_logger.fine("updated RAConfig In Descriptor " + connectorDescriptor.getConfigProperties());
}
|
|