[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Scoped Kernels

adrian@jboss.org do-not-reply at jboss.com
Mon Feb 12 09:12:11 EST 2007


Now let's look at a concrete example I was thinking about over the weekend.

We want to define a "subsystem". This is  a scoped kernel such that
nobody else can play with our beans. i.e. it is a private implementation deployment.
A simple case would be the old JBossJTA subsystem.


  | <deployment>
  |    <scope level="subsystem" qualifier="JBoss JTA"/>
  | 
  |    <bean name="XIDFactory">
  |         ...
  |    </bean>
  | 
  |    <bean name="TransactionManager">
  |       <property name="xidFactory><inject bean="XIDFactory"/></property>
  |       ...
  |    </bean>
  | </deployment>
  | 

So far so good. Nobody else can see our XIDFactory, it is private to our scope.

BUT others want to use the TransactionManager.

In practice of course, they should be using the TransactionManagerLocator
class, since we want to integrate in other places where we don't
construct the TM. So this example is a bit academic.

This could be formalised as having a root deployment:

  | <deployment>
  |    <bean name="TransactionManager"
  |       <constructor factoryClass="TransactionManagerLocator" factoryMethod="getInstance"/>
  |     </bean>
  | </deployment>
  | 

This is good because it will work in all environments the transaction manager locator 
class supports, it allows IOC injection again, and the locator class
knows how to find the TransactionManager defined in the "JBoss JTA" scope
using a private factory method when run inside JBoss.

It does however have one drawback.
The dependencies are not really being checked/satisifed.

Since we are using a private factory method in the TransactionManagerLocator
somebody could forget to deploy the "JBoss JTA" scope deployment and it
will still work. It will just use a default configuration for the TransactionManager.

Maybe this is what we want? But probably only in this use cases.
Although, in a lot of other use cases, the binding is not really coming
from direct POJO injection, but from jndi bindings, etc.
e.g. DataSources.

If we tweak the example a bit and assume we do want people to be
able to directly inject the TransactionManager (and there is nothing
like the TransactionManagerLocator) then we need a mechanism to
promote the TransactionManager into the default scope.

One mechanism would be to do an "export". i.e. I define the bean
in a scoped kernel, but I also want it available in the global scope.

  | <bean name="TransactionManager" export="true">
  | 

There would be two ways to implement this.

1) The context really exists in the global scope, but for the sake of 
dependencies it uses the "JBoss JTA" scope.

2) We register and "alias" in the global scope.

I think (2) will be a lot simpler to implement.

Essentially, the alias would just act as a "proxy/delegate" to the real
context in the scoped kernel. The root kernel would recognise the
context as a proxy and not try to manage it.

And Scott has been asking for a generic alias mechanism anyway. :-)

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

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



More information about the jboss-dev-forums mailing list