It should be done on the calls to (un)getTarget()
Having the calling code do all this work would inefficient and error prone.
And besides a context may want to change the way this work, e.g. by providing
a specific ServiceTracker rather than using the one determined from the MDR.
You need a signature like I suggested above,
i.e. something like the following:
| // Mixin interface for service tracking
| public interface ServiceTracking
| {
| /**
| * Get the service tracker associated with this context
| *
| * @return the tracker or null if it doesn't have one
| */
| ServiceTracker getServiceTracker();
|
| /**
| * Get the target and update the service tracking
| *
| * @param me the controller context that will use the target
| * @return the object
| * @throws Exception for any error
| */
| Object getTarget(ControllerContext me) throws Exception;
|
| /**
| * Unget the target and update the service tracking
| *
| * @param me the controller context that used the target
| */
| void ungetTarget(ControllerContext me);
| }
|
| public Object ControllerContext::getTarget(ControllerContext me) throws Exception
| {
| Object result = getTarget();
| if (result != null)
| {
| ServiceTracker myTracker = getServiceTracker();
| if (myTracker != null)
| myTracker.incrementInUse(me, this);
| if (me instanceOf ServiceTracking)
| {
| ServiceTracker otherTracker = me.getServiceTracker();
| if (otherTracker != null)
| otherTracker.incrementUsing(this);
| }
| }
| return result;
| }
|
| public void ControllerContext::ungetTarget(ControllerContext me)
| {
| Object result = getTarget();
| if (result != null)
| {
| ServiceTracker myTracker = getServiceTracker();
| if (myTracker != null)
| myTracker.decrementInUse(me, this);
| if (me instanceOf ServiceTracking)
| {
| ServiceTracker otherTracker = me.getServiceTracker();
| if (otherTracker != null)
| otherTracker.decrementUsing(this);
| }
| }
| }
|
The instanceOf ServiceTracking is for backwards compatibilty in case
some old ControllerContext doesn't know about ServiceTracking.
You should make AbstractControllerContext implement the getServiceTracker() by
looking in the MDR (probably during the original install for performance and
consistency - or you could do it lazily on first request?).
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4267018#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...