4 Replies Latest reply on Apr 26, 2010 7:08 AM by emuckenhuber

    controller.uninstall() fails when overriding the KernelControllerContext name

    emuckenhuber

      When i manully set a name for a KernelControllerContext the uninstallation of contexts does not work properly.

       

      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("test", Object.class.getName());
            
      ObjectName name = new ObjectName("org.jboss:service=test");
            
      KernelControllerContext ctx = new AbstractKernelControllerContext(null, builder.getBeanMetaData(), new Object());
      ctx.setName(name);
      
      getController().install(ctx);
      getController().uninstall(name);
            
      assertNull(getController().getContext(name, null));
      

       

      In this case the context does not get properly uninstalled and ends up in the ERROR state (without any error message - which IMHO is also a bit weird). The name change happens in the "InstallAction" which uses the original name of the BeanMetaData to register the context in the KernelRegistry:

       

      BeanMetaData metaData = context.getBeanMetaData();
      Object name = metaData.getName();
      registry.registerEntry(name, context);
      

       

      Which then changes the controllerContexts back to the name which was defined in the BeanMetaData. Basically you can lookup the correct context, however the context cannot be remove from allContexts in the controller - since the name it got registers now is different from the context name:

       

      controller.uninstall(objectName)
      ...
      ControllerContext context = getRegisteredContextAndInterruptAsynchronousInstall(objectName);
      ....
      unregisterControllerContext(context);
      ....
      Object beanMetaDataName = context.getName();
      allContext.remove(beanMetaDataName);
      

       

      Obviously when i set the original context name before uninstalling this works fine.

        • 1. Re: controller.uninstall() fails when overriding the KernelControllerContext name
          alesj

          Why don't you rather use alias then change original name in the middle of bean's lifecycle?

          Imo, the name should actually be made immutable, specially after the context is installed.

          • 2. Re: controller.uninstall() fails when overriding the KernelControllerContext name
            emuckenhuber

            Ales Justin wrote:

             

            Why don't you rather use alias then change original name in the middle of bean's lifecycle?

            Imo, the name should actually be made immutable, specially after the context is installed.

            Well the thing is that i'm not changing the name during the lifecycle - it's the kernel InstallAction, which does that. I just override the original context name before i call install(), since BMD only allows Strings as a name.

            • 3. Re: controller.uninstall() fails when overriding the KernelControllerContext name
              alesj
              Well the thing is that i'm not changing the name during the lifecycle - it's the kernel InstallAction, which does that. I just override the original context name before i call install(), since BMD only allows Strings as a name.

              OK, I see a bit of inconsistency there -- since we only allow BMD for KernelContextController,

              we should make sure setName throws some exception or lists a warning that setName is ignored.

               

              In your case, you should put in a canonical name into BMD.

              • 4. Re: controller.uninstall() fails when overriding the KernelControllerContext name
                emuckenhuber

                Ales Justin wrote:


                OK, I see a bit of inconsistency there -- since we only allow BMD for KernelContextController,

                we should make sure setName throws some exception or lists a warning that setName is ignored.

                Hmm, wouldn't it make more sense to use the context name instead of the BMD to register the context in the InstallAction? I mean the only reason i was using setName() was to not use the name defined in the BMD - since it only allows a String.

                 

                Now i'm just using a hash for the context name and add aliases - so not allowing to override the ctx name would work for me as well.