jaikiran pai [http://community.jboss.org/people/jaikiran] created the discussion

"AbstractRealDeployerWithInput fails to call undeploy() on deployer, for failed 
deployments"

To view the discussion, visit: http://community.jboss.org/message/555208#555208

--------------------------------------------------------------
While investigating this issue  
http://community.jboss.org/message/555195#555195 
http://community.jboss.org/message/555195#555195, I have stumbled upon a MC 
deployer bug. Here's an simplified version of what's happening:

public class MyDeployer extends 
AbstractRealDeployerWithInput<JBossEnterpriseBeanMetaData>
      implements
         DeploymentVisitor<JBossEnterpriseBeanMetaData>
         
{
 
...
   @Override
   public void deploy(DeploymentUnit unit, JBossEnterpriseBeanMetaData 
beanMetaData) throws DeploymentException
   {
     doStepOne(); // like register component to some service name
     
     doStepTwo(); // can be any operation which ends up throwing an runtime 
exception
 
   }         
   
   @Override
   public void undeploy(DeploymentUnit unit, JBossEnterpriseBeanMetaData 
enterpriseBean)
   {
      undoStepOne(); // i.e. unregister the service
   }
   
}
 
As can be seen, the deploy() involves more than one step. The first step does 
registering of services (or some functionality internal to my deployer). The 
second step of deploy() does some other thing but ends up throwing an 
exception. I would expect that the undeploy() method
would be called on MyDeployer for this (failed) deployment unit, so that I can 
undo/cleanup whatever was done in doStepOne() of deploy() operation.



However, the undeploy() never gets called. Looking at MC's 
AbstractRealDeployerWithInput.deploy() method:

  protected <U> void deploy(DeploymentUnit unit, DeploymentVisitor<U> visitor) 
throws DeploymentException
   {
      if (visitor == null)
         throw new IllegalArgumentException("Null visitor.");
 
      List<U> visited = new ArrayList<U>();
      try
      {
         Set<? extends U> deployments = 
unit.getAllMetaData(visitor.getVisitorType());
         for (U deployment : deployments)
         {
            visitor.deploy(unit, deployment);
            visited.add(deployment);
         }
      }
      catch (Throwable t)
      {
         for (int i = visited.size()-1; i >= 0; --i)
         {
            try
            {
               visitor.undeploy(unit, visited.get(i));
            }
            catch (Throwable ignored)
            {
               log.warn("Error during undeploy: " + unit.getName(), ignored);
            }
         }
         throw DeploymentException.rethrowAsDeploymentException("Error 
deploying: " + unit.getName(), t);
      }
   }
   
 


More specifically:

            
            visitor.deploy(unit, deployment);
            visited.add(deployment);
 


visitor.deploy(...) throws the exception and hence the deployment is never 
added to "visited" which effectively means that in the catch block:

for (int i = visited.size()-1; i >= 0; --i)
{
        try
        {
           visitor.undeploy(unit, visited.get(i));
        }
        catch (Throwable ignored)
        {
           log.warn("Error during undeploy: " + unit.getName(), ignored);
        }
}
 


The "visited" will never contain this failed deployment. Ultimately, the 
undeploy() will never get called for that failed deployment unit.

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/555208#555208]

Start a new discussion in JBoss Microcontainer at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2114]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to