6 Replies Latest reply on Jun 17, 2013 10:38 AM by arun2arunraj

    Can I pass values from parent to child , If child is Manually discovered ? ? ?

    arun2arunraj

      Hi Developers,

       

          As per My Use Case, I would like to use manual discovery option to my child. In this case, My child resource has to collect value based on the parent resource. Is that possible to pass the values from the parent resource to the child resource.

       

      Regards,

      ArunRaj

        • 1. Re: Can I pass values from parent to child , If child is Manually discovered ? ? ?
          lkrejci

          The child component has access to the parent component so you can access the parent from the child. See for example here: https://community.jboss.org/message/802880#802880.

          • 2. Re: Can I pass values from parent to child , If child is Manually discovered ? ? ?
            arun2arunraj

            Dude, I have followed this only. This is working for auto discovered child. But the code is not working for manually imported or discovered childs.

             

            In the child discovery,

             

             

            public class ChildDiscovery implements ResourceDiscoveryComponent<ParentComponent>, ManualAddFacet {
            
               public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context) throws InvalidPluginConfigurationException,
                    Exception {
                    return Collections.emptySet();//For not auto discovered.
                }
            
                public DiscoveredResourceDetails discoverResource(Configuration pluginConfig, ResourceDiscoveryContext context) throws InvalidPluginConfigurationException {
                      //Collect and return the child resource
                }
            

             

            In the Child Component,

             

             

            public class ChildComponent implements ResourceComponent<ParentComponent>, MeasurementFacet {
            
            public void start(Resource Context<ParentComponent> Context)
            {
            this.Context     =     Context;
            }
            public int dataFromParent() {
             return Context.getParentComponent().getParentFunction();
            }
            }
            

            This is what I have coded. But the child is not getting the parent values. Is this a correct way of accessing the parent class via manual import option.

             

            Regards,

            ArunRaj

            • 3. Re: Can I pass values from parent to child , If child is Manually discovered ? ? ?
              lkrejci

              What is not working in that scenario?

               

              does Context.getParentComponent() return null? Or does the getParentFunction() not return data you need?

              1 of 1 people found this helpful
              • 4. Re: Can I pass values from parent to child , If child is Manually discovered ? ? ?
                arun2arunraj

                Problem 1 : getParentComponent() returns two objects for each import....

                 

                               eg:

                     when I have tried to do read the object hashvalue i got the following result.                   

                     Demo NINE : org.rhq.plugins.demo.ParentComponent@51f46b95 ( System.out.println("Demo NINE : "+Context.getParentComponent())

                     Demo NINE : org.rhq.plugins.demo.ParentComponent@51f46b95

                 

                 

                Problem 2 : getParentFunction() is not returning data.

                • 5. Re: Can I pass values from parent to child , If child is Manually discovered ? ? ?
                  arun2arunraj

                  Hi Lukas,

                   

                      I have found the reason for Problem 1:

                   

                      Reason :

                                   Plugin Lifecycle played a main roll here. Problem is with the method invokation. The Method invoking order 1) Start() 2) Stop 3) Start(). I dont know Why stop is called for , after the start method. In the stop method, I am initializing the object as null. Again, The ChildComponent is calling start() method. That is why I am getting two objects.

                   

                  Regards,

                  ArunRaj

                  • 6. Re: Can I pass values from parent to child , If child is Manually discovered ? ? ?
                    arun2arunraj

                    Hi Lukas,

                     

                        Solved the problem. I have commited a mistakes in my code like mismatching metric properties and Mismatching method initialization. Now Its working. Thank you so much guys for your support.

                     

                    Regards,

                    ArunRaj