[jboss-user] [Microcontainer] - Re: Attachments eligible for being passed to the deployers?

jaikiran do-not-reply at jboss.com
Thu Mar 5 04:11:22 EST 2009


So here's the real question :)

Do attachments to component contexts of an unit get treated the same way? Do these attachments to component contexts get passed onto the deployers? From what i see this is not the case.

Here's the example:

// This one doesn't do much and is not of much relevance in this
  | // example. It just creates a component which can be consumed
  | // by our component deployer (MyComponentDeployer - see next)
  | public class TestDeployer extends AbstractDeployer
  | {
  | 
  |    public TestDeployer()
  |    {
  |       setStage(DeploymentStages.POST_CLASSLOADER);
  | 	// this is our output which is consumed by MyComponentDeployer
  |       setOutput(TestAttachment.class);
  | 	// some input - not relevant in this example
  |       setInput(JBossMetaData.class);
  |    }
  | 
  | // creates a component to the unit and adds an attachment to the component
  | // so that the MyComponentDeployer can consume it
  |    public void deploy(DeploymentUnit unit) throws DeploymentException
  |    {
  |       DeploymentUnit comp = unit.addComponent("something");
  |       comp.addAttachment(TestAttachment.class, new TestAttachment("hello"));
  |       logger.info("Added attachment to component in unit " + unit);
  |    }
  | }
  | 


// This one is important - this deployer is a component only deployer
  | // and works on the component that was created by our earlier TestDeployer
  | public class MyComponentDeployer extends AbstractDeployer
  | {
  | 
  | 
  |    public MyComponentDeployer()
  |    {
  |       setStage(DeploymentStages.REAL);
  | 	// the attachment that was added to the component by our earlier deployer
  | 	// will be our input
  |       setInput(TestAttachment.class);
  | 	// we work only on components
  |       setComponentsOnly(true);
  |    }
  | 
  | 	// Here we just add an attachment to the unit (which acutally is an component)
  | 	// Any further deployers (MyFinalDeployer - see next) will use this attachment 
  | 	// as input
  |    public void deploy(DeploymentUnit unit) throws DeploymentException
  |    {
  |       logger.info("Deploying unit : " + unit);
  |       // doesn't work
  |       unit.addAttachment(AnotherType.class, new AnotherType());
  |    }
  | 
  | }
  | 
  | 

// This one (tries to) consumes the attachment that was added by the component
  | // deployer (see above)
  | public class MyFinalDeployer extends AbstractDeployer
  | {
  |    private static Logger logger = Logger.getLogger(OneMoreDeployer.class);
  | 
  |    public MyFinalDeployer()
  |    {
  |       setStage(DeploymentStages.REAL);
  | 	// the attachment that was added by the component deployer
  |       setInput(AnotherType.class);
  | 
  |    }
  | 
  | 	// never reaches here.
  |    public void deploy(DeploymentUnit unit) throws DeploymentException
  |    {
  |       logger.info("Deploying another type " + unit);
  | 
  |    }
  | 
  | }
  | 
  | 
  | 

There are 3 deployers involved here:

1) The TestDeployer creates a component to an unit and also attaches an attachment to the component (works fine)
2) The MyComponentDeployer consumes this component context and additionally creates an attachment to it (works fine/or maybe not).
3) MyFinalDeployer is supposed to consume the attachment created in #2, but it never does. This deployer is considered "not relevant".

The only way i could get this to work was to add the attachment to the parent of the component context in #2. So:

public class MyComponentDeployer extends AbstractDeployer
  | {
  | 
  | 	// I don't know why i need to add the attachment to the
  | 	// parent. But it works, so let's for the time being do that
  |    public void deploy(DeploymentUnit unit) throws DeploymentException
  |    {
  |       logger.info("Deploying unit : " + unit);
  | 	// here - i'm clueless, the attachment needs to be added to parent for some reason
  | 	// Note, this is a component deployer and works on component context
  |       unit.getParent().addAttachment(AnotherType.class, new AnotherType());
  |    }
  | 
  | }
  | 

Doing this makes MyFinalDeployer (in #3) "relevant" and the unit is passed on the deploy method of MyFinalDeployer.

So the question is - what am i missing? :)

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

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



More information about the jboss-user mailing list