JBoss.org Community Documentation

22.5. Deployment dependencies

Sometimes a deployment may have dependencies on other deployments or on a runtime component such as a classloader. In these cases we need to be able to define the dependencies so that the state machine can decide whether or not to progress the deployment to the next stage. This is done using the following methods of the DeploymentUnit interface:


public interface DeploymentUnit extends MutableAttachments
{
    ...

   DependencyInfo getDependencyInfo();
   void addIDependOn(DependencyItem dependency);
   void removeIDependOn(DependencyItem dependency);
}

AbstractDeploymentUnit delegates these calls to the DeploymentContext implementation that it wraps:


public class AbstractDeploymentUnit extends AbstractMutableAttachments implements DeploymentUnit
{
   ...

   public void addIDependOn(DependencyItem dependency)
   {
      getDependencyInfo().addIDependOn(dependency);
   }

   public DependencyInfo getDependencyInfo()
   {
      return deploymentContext.getDependencyInfo();
   }

   public void removeIDependOn(DependencyItem dependency)
   {
      getDependencyInfo().removeIDependOn(dependency);
   }

   ...
}

This in turn delegates them to the corresponding ControllerContext implementation which is stored as an attachment:


public class AbstractDeploymentContext extends ManagedObjectsWithTransientAttachmentsImpl implements DeploymentContext
{
   ...

   public DependencyInfo getDependencyInfo()
   {
      ControllerContext controllerContext = getTransientAttachments().getAttachment(ControllerContext.class);
      if (controllerContext != null)
         return controllerContext.getDependencyInfo();
      else
      {
         DeploymentContext parent = getParent();
         if (parent == null)
            throw new IllegalStateException("Deployment ControllerContext has not been set");
         return parent.getDependencyInfo();
      }
   }

   ...
}

If a ControllerContext object is not found within the deployment's attachments then the parent deployment is tried. In this way DependencyItems are added/removed to the underlying ControllerContext implementation for the deployment.