[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Checking DeploymentContext for failures

adrian@jboss.org do-not-reply at jboss.com
Wed Nov 14 11:33:26 EST 2007


I answered this on the dev-list since the forums were down,
copied to here:

You don't need to do anything so complicated.

You just need the relevant deployers to record the context names in some
well defined place, e.g. the Deployment{Unit|Context}

It's probably important enough to use a special method rather than
an attachment.

e.g.


  | public class BeanMetaDataDeployer extends
  | AbstractSimpleRealDeployer<BeanMetaData>
  | {
  |    /** The kernel controller */
  |    private final KernelController controller;
  |    
  |    /**
  |     * Create a new BeanDeployer.
  |     * 
  |     * @param kernel the kernel
  |     * @throws IllegalArgumentException for a null kernel
  |     */
  |    public BeanMetaDataDeployer(Kernel kernel)
  |    {
  |       super(BeanMetaData.class);
  |       if (kernel == null)
  |          throw new IllegalArgumentException("Null kernel");
  |       controller = kernel.getController();
  |       setComponentsOnly(true);
  |    }
  | 
  |    @Override
  |    public void deploy(DeploymentUnit unit, BeanMetaData deployment)
  | throws DeploymentException
  |    {
  |       KernelControllerContext context = new
  | AbstractKernelControllerContext(null, deployment, null);
  |       try
  |       {
  |          controller.install(context);
  | +       unit.addControllerContextName(deployment.getName());
  |       }
  |       catch (Throwable t)
  |       {
  |          throw DeploymentException.rethrowAsDeploymentException("Error
  | deploying: " + deployment.getName(), t);
  |       }
  |    }
  | 
  |    @Override
  |    public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
  |    {
  | +     unit.removeControllerContextName(deployment.getName());
  |       controller.uninstall(deployment.getName());
  |    }
  | }
  | 

In practice, the component deployment unit name should be the context
name.
This is at least true for the POJO and Service deployers.

So you could just add it as some kind of easy declaration in the
constructor:


  |    public BeanMetaDataDeployer(Kernel kernel)
  |    {
  |       super(BeanMetaData.class);
  |       if (kernel == null)
  |          throw new IllegalArgumentException("Null kernel");
  |       controller = kernel.getController();
  |       setComponentsOnly(true);
  |       // obviously some shorter property name ;-)
  |       setComponentDeploymentNameIsControllerContextName(true);
  |    }
  | 

and handle it in the abstract classes:


  |    deploy(...); // will throw an error if not registered in the
  | controller
  |    if (unit.isComponent() &&
  | isComponentDeploymentNameControllerContextName())
  |       addComponentContextName(unit.getSimpleName());
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4104680#4104680

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4104680



More information about the jboss-dev-forums mailing list