ResourceAdapterStopPhasepublic class ResourceAdapterStopPhase extends DeploymentPhase Phase that is responsible to send stop events when an application is undeployed or
disassociated |
Fields Summary |
---|
public static final Logger | sLoggerDeployment Logger object for this class | private static com.sun.enterprise.util.i18n.StringManager | localStringsstring manager | private static final String | LIST_ADMIN_OBJECTS | private static final String | DELETE_ADMIN_OBJECT | private static final String | LIST_CONNECTOR_CONNECTION_POOLS | private static final String | DELETE_CONNECTOR_CONNECTION_POOL | private static final String | LIST_RESOURCE_ADAPTER_CONFIGS | private static final String | DELETE_RESOURCE_ADAPTER_CONFIG |
Constructors Summary |
---|
public ResourceAdapterStopPhase(DeploymentContext deploymentCtx)Creates a new instance of Class
this.deploymentCtx = deploymentCtx;
this.name = RA_STOP;
|
Methods Summary |
---|
private void | deleteConnectorDependentResources(java.lang.String id, java.lang.String targetName)
try{
MBeanServer mbs = MBeanServerFactory.getMBeanServer();
ObjectName mbeanName =
new ObjectName("com.sun.appserv:type=resources,category=config");
Object[] params = new Object[] {};
String[] signature = new String[] {};
//delete admin objects
ObjectName[] adminObjs =
(ObjectName[]) mbs.invoke(mbeanName, LIST_ADMIN_OBJECTS,
params, signature);
String[] adminObjSignature = new String[]{
"java.lang.String", "java.lang.String"};
for(int i = 0 ; i< adminObjs.length;i++) {
String raName =
(String)mbs.getAttribute(adminObjs[i],"res_adapter");
if(id.equals(raName)) {
String adminObjName =
(String)mbs.getAttribute(adminObjs[i],"jndi_name");
Object[] deleteAdminParams =
new Object[]{adminObjName, (String)targetName};
mbs.invoke(mbeanName,
DELETE_ADMIN_OBJECT, deleteAdminParams,
adminObjSignature);
}
}
//end delete admin objects
//delete pools and resources
ObjectName[] poolNames = (ObjectName[])mbs.invoke(mbeanName,
LIST_CONNECTOR_CONNECTION_POOLS, params, signature);
String[] deletePoolSignature = new String[] {"java.lang.String",
"java.lang.Boolean", "java.lang.String"};
for(int i = 0 ; i < poolNames.length ; i++) {
String raName = (String)mbs.getAttribute(poolNames[i],
"resource_adapter_name");
if(id.equals(raName)) {
String poolName = (String)mbs.getAttribute(poolNames[i],
"name");
Object[] deletePoolParams = new Object[] {poolName,
Boolean.TRUE, (String)targetName};
mbs.invoke(mbeanName, DELETE_CONNECTOR_CONNECTION_POOL,
deletePoolParams, deletePoolSignature);
}
}
//end delete pools and resources
//delete resource adapter config
ObjectName[] resAdapterConfigs = (ObjectName[])mbs.invoke(
mbeanName, LIST_RESOURCE_ADAPTER_CONFIGS, params, signature);
String[] adapterConfigSignature = new String[]{
"java.lang.String", "java.lang.String"};
Object[] adapterConfigParams = new Object[]{id, (String)targetName};
for(int i = 0 ; i < resAdapterConfigs.length ; i++) {
String raName = (String)mbs.getAttribute(resAdapterConfigs[i],
"resource_adapter_name");
if(id.equals(raName)) {
mbs.invoke(mbeanName, DELETE_RESOURCE_ADAPTER_CONFIG,
adapterConfigParams, adapterConfigSignature);
}
}
//end delete resource adapter config
}catch(Exception e){
//FIXME i18n
throw new DeploymentPhaseException(getName(), "Exception occured while deleting dependent connector resources", e);
}
| protected com.sun.enterprise.deployment.backend.DeploymentEvent | getPostPhaseEvent(com.sun.enterprise.deployment.backend.DeploymentRequest req)Event that will be broadcasted at the end of the phase
return new DeploymentEvent(DeploymentEventType.POST_RA_STOP,new DeploymentEventInfo(req) );
| protected com.sun.enterprise.deployment.backend.DeploymentEvent | getPrePhaseEvent(com.sun.enterprise.deployment.backend.DeploymentRequest req)Event that will be broadcasted at the start of the phase
return new DeploymentEvent(DeploymentEventType.PRE_RA_STOP, new DeploymentEventInfo(req));
| public void | runPhase(DeploymentPhaseContext phaseCtx)Sends stop events to the required target
String type = null;
DeploymentRequest req = phaseCtx.getDeploymentRequest();
DeploymentTarget target = (DeploymentTarget)req.getTarget();
DeploymentStatus status = phaseCtx.getDeploymentStatus();
if (!DeploymentServiceUtils.containsResourceAdapter(req)) {
status.setStageStatus(DeploymentStatus.SUCCESS);
return;
}
if(!req.isApplication())
{
type = DeploymentServiceUtils.getModuleTypeString(req.getType());
}
try {
if (req.getCascade() && !req.isForced()){
deleteConnectorDependentResources(req.getName(),
target.getName());
deploymentCtx.getConfigContext().flush();
AdminContext adminContext =
AdminService.getAdminService().getAdminContext();
new AdminNotificationHelper(adminContext).sendNotification();
}
} catch(Throwable t){
status.setStageStatus(DeploymentStatus.WARNING);
status.setStageException(t);
status.setStageStatusMessage(t.getMessage());
return;
}
prePhaseNotify(getPrePhaseEvent(req));
boolean success;
try {
success = target.sendStopEvent(req.getActionCode(), req.getName(), type, req.getCascade(), req.isForced(), Constants.UNLOAD_RAR);
} catch(DeploymentTargetException dte) {
status.setStageStatus(DeploymentStatus.WARNING);
if (dte.getCause()!=null) {
status.setStageException(dte.getCause());
status.setStageStatusMessage(dte.getMessage());
}
return;
}
if (success) {
status.setStageStatus(DeploymentStatus.SUCCESS);
} else {
status.setStageStatus(DeploymentStatus.WARNING);
status.setStageStatusMessage("Application failed to stop");
}
postPhaseNotify(getPostPhaseEvent(req));
// if any exception is thrown. we let the stack unroll, it
// will be processed in the DeploymentService.
|
|