JBoss development,
A new message was posted in the thread "Activating OnDemand beans from child
controller":
http://community.jboss.org/message/520168#520168
Author : Kabir Khan
Profile :
http://community.jboss.org/people/kabir.khan@jboss.com
Message:
--------------------------------------------------------------
The messages you added to avoid the errors shown in the dev list post now get triggered
for contexts that have been uninstalled. As you can see I modified them a bit. If I have
an OnDemand bean called Bean1 and Bean2 and Bean3 depend on it, then if I
-uninstall Bean2
-when uninstalling Bean3 I get an error message when checking Bean3's dependencies. It
finds Bean1 and then checks Bean1's DependsOnMe. The message I get is "Could not
find reverse dependency 'Name2' while uninstalling on demand contexts for
AbstractDependencyItem@6c3c9c31{name=Name3 dependsOn=Name1 whenRequired=Configured
resolved=true}"
protected void uninstallUnusedOnDemandContexts(ControllerContext context, boolean
trace)
{
lockWrite();
try
{
DependencyInfo dependencies = context.getDependencyInfo();
if (dependencies != null)
{
Set<DependencyItem> iDependOn = dependencies.getIDependOn(null);
if (iDependOn.isEmpty() == false)
{
for (DependencyItem item : iDependOn)
{
if (item.isResolved()) //TODO Is this check necessary
{
Object name = item.getIDependOn();
if (name == null)
continue;
ControllerContext other = getContext(name, null);
if (other == null)
{
log.warn("Could not find dependency '" + name +
"' while uninstalling on demand contexts for " + item);
continue;
}
if (other.getMode() != ControllerMode.ON_DEMAND)
continue;
DependencyInfo otherDependencies = other.getDependencyInfo();
if (otherDependencies == null)
continue;
Set<DependencyItem> dependsOnOther =
otherDependencies.getDependsOnMe(null);
boolean isRequired = false;
for (DependencyItem dependsOnOtherItem : dependsOnOther)
{
ControllerContext dependsContext =
getContext(dependsOnOtherItem.getName(), null);
if (dependsContext == null)
{
log.warn("Could not find reverse dependency '" +
dependsOnOtherItem.getName() + "' while uninstalling on demand contexts for
" + item);
continue;
}
ControllerState requiredState = item.getWhenRequired();
ControllerState actualState = dependsContext.getState();
if (requiredState.equals(actualState) ||
stateModel.isBeforeState(requiredState, actualState))
{
isRequired = true;
break;
}
}
if (!isRequired)
{
//For some reason uninstallContext() uninstalls to the state below
the passed in one, add one
ControllerState state =
stateModel.getNextState(ControllerMode.ON_DEMAND.getRequiredState());
uninstallContext(other, state, trace);
}
}
}
}
}
}
finally
{
unlockWrite();
}
}
This simple test shows that DependsOnMe never gets cleared:
public class DependsOnMeTestCase extends AbstractDependencyTest
{
public DependsOnMeTestCase(String name)
{
super(name);
}
public void testDependsOnMeCorrectOrder() throws Throwable
{
ControllerContext context1 = assertInstall(getDelegate1());
assertEmpty(context1.getDependencyInfo().getIDependOn(null));
assertEmpty(context1.getDependencyInfo().getDependsOnMe(null));
ControllerContext context2 = assertInstall(getDelegate2());
assertEmpty(context2.getDependencyInfo().getDependsOnMe(null));
assertEquals(1, context2.getDependencyInfo().getIDependOn(null).size());
assertEquals("Name1",
context2.getDependencyInfo().getIDependOn(null).iterator().next().getIDependOn());
assertEmpty(context1.getDependencyInfo().getIDependOn(null));
assertEquals(1, context1.getDependencyInfo().getDependsOnMe(null).size());
assertEquals("Name1",
context1.getDependencyInfo().getDependsOnMe(null).iterator().next().getIDependOn());
}
public void testDependsOnMeWrongOrder() throws Throwable
{
ControllerContext context2 = assertInstall(getDelegate2(),
ControllerState.PRE_INSTALL);
assertEmpty(context2.getDependencyInfo().getDependsOnMe(null));
assertEquals(1, context2.getDependencyInfo().getIDependOn(null).size());
assertEquals("Name1",
context2.getDependencyInfo().getIDependOn(null).iterator().next().getIDependOn());
ControllerContext context1 = assertInstall(getDelegate1());
assertEmpty(context1.getDependencyInfo().getIDependOn(null));
assertEquals(1, context1.getDependencyInfo().getDependsOnMe(null).size());
assertEquals("Name1",
context1.getDependencyInfo().getDependsOnMe(null).iterator().next().getIDependOn());
assertEmpty(context2.getDependencyInfo().getDependsOnMe(null));
assertEquals(1, context2.getDependencyInfo().getIDependOn(null).size());
assertEquals("Name1",
context2.getDependencyInfo().getIDependOn(null).iterator().next().getIDependOn());
}
public void testDependsOnMeUninstallRightOrder() throws Throwable
{
ControllerContext context1 = assertInstall(getDelegate1());
assertEmpty(context1.getDependencyInfo().getIDependOn(null));
assertEmpty(context1.getDependencyInfo().getDependsOnMe(null));
ControllerContext context2 = assertInstall(getDelegate2());
assertEmpty(context2.getDependencyInfo().getDependsOnMe(null));
assertEquals(1, context2.getDependencyInfo().getIDependOn(null).size());
assertEquals("Name1",
context2.getDependencyInfo().getIDependOn(null).iterator().next().getIDependOn());
assertEmpty(context1.getDependencyInfo().getIDependOn(null));
assertEquals(1, context1.getDependencyInfo().getDependsOnMe(null).size());
assertEquals("Name1",
context1.getDependencyInfo().getDependsOnMe(null).iterator().next().getIDependOn());
assertUninstall(context2);
assertEmpty(context2.getDependencyInfo().getDependsOnMe(null));
assertEquals(1, context2.getDependencyInfo().getIDependOn(null).size());
assertEquals("Name1",
context2.getDependencyInfo().getIDependOn(null).iterator().next().getIDependOn());
context1 = assertContext("Name1", ControllerState.INSTALLED);
assertEmpty(context1.getDependencyInfo().getIDependOn(null));
assertEmpty(context1.getDependencyInfo().getDependsOnMe(null)); // FAILS -
dependsOnMe still contains Name2
}
protected TestDelegate getDelegate1()
{
return new TestDelegate("Name1");
}
protected TestDelegate getDelegate2()
{
TestDelegate result = new TestDelegate("Name2");
result.addDependency(new AbstractDependencyItem("Name2",
"Name1", ControllerState.DESCRIBED, ControllerState.INSTALLED));
return result;
}
}
--------------------------------------------------------------
To reply to this message visit the message page:
http://community.jboss.org/message/520168#520168