1 Reply Latest reply on Dec 9, 2008 10:29 AM by alesj

    JBAS-6297, mbean service optional injection

    starksm64

      I'm not understanding the current mc optional dependency implementation. I expected that I could simply leverage an optional notion from AbstractDependencyItem to update the ServiceInjectionValueMetaData.visit method to create an optional dependency like:

       public void visit(ServiceMetaDataVisitor visitor)
       {
       ServiceControllerContext context = visitor.getControllerContext();
       Object name = context.getName();
       ControllerState whenRequired = visitor.getContextState();
      
       boolean optional = isOptional();
       DependencyItem item = new AbstractDependencyItem(name, dependency, whenRequired, dependentState, optional);
       visitor.addDependency(item);
      
       visitor.visit(this);
       }
      


      But optionality does not exist in AbstractDependencyItem. It only exists in a protected OptionalDependencyItem which is an inner class of the AbstractDependencyValueMetaData class. Why isn't this a general DependencyItem notion?

      I guess I'll look at updating the ServiceInjectionValueMetaData.getValue to return null and see what additional changes are needed to deal with that.


        • 1. Re: JBAS-6297, mbean service optional injection
          alesj

          OptionalDependencyItem is only there to wire together beans that actually existed - to be properly unwinded on undeploy.

          But I guess similar dependency item could be added from the beginning.
          You would only need to override unresolved() method,
          to only return true when the dependent bean exists.

          I just didn't introduce it, as it would always return true on isResolved() call.
          Where we actually only need it when dependency exists.