[jboss-dev-forums] [Design the new POJO MicroContainer] - Uninstall OnDemand context if there are no more dependencies
kabir.khan@jboss.com
do-not-reply at jboss.com
Wed Jul 15 04:30:00 EDT 2009
I have knocked up a prototype for https://jira.jboss.org/jira/browse/JBKERNEL-4. A few of the existing tests fail since the order of uninstall has changed. What I am doing is:
| protected void uninstallContext(ControllerContext context, boolean trace)
| {
| //Existing code
|
| 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();
| ControllerContext other = getContext(name, null);
| if (other == null)
| {
| log.warn("Could not find dependency 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(item.getName(), null);
| if (dependsContext == null)
| {
| log.warn("Could not find dependency while uninstalling on demand contexts for " + item);
| continue;
| }
|
| int requiredIndex = states.indexOf(item.getWhenRequired());
| int actualIndex = states.indexOf(dependsContext.getState());
| if (requiredIndex <= actualIndex)
| {
| isRequired = true;
| break;
| }
| }
| if (!isRequired)
| {
| //For some reason uninstallContext() uninstalls to the state below the passed in one, add one
| int index = states.indexOf(ControllerMode.ON_DEMAND.getRequiredState());
| index++;
| ControllerState state = states.get(index);
| uninstallContext(other, state, trace);
| }
| }
| }
| }
| }
| }
|
I'll look into the failing tests and fix those, which might mean needing to change the tests themselves in trunk. The JIRA issue mentions that the uninstall of the OnDemand context should happen asynchronously, which will complicate things, but will be possible if a real requirement, I'll try to fix the tests first though.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243667#4243667
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243667
More information about the jboss-dev-forums
mailing list