When is the @Initialized(ApplicationScoped.class) event sent in CDI?











up vote
3
down vote

favorite












I'm trying to understand the lifecycle/flow of the @Initialized() events within the context of the CDI Container's events thrown that are observable in an extension.



As per the WELD 2 docs, the Container lifecycle events are:





  • BeforeBeanDiscovery

  • ProcessAnnotatedType and ProcessSyntheticAnnotatedType

  • AfterTypeDiscovery

  • ProcessInjectionTarget and ProcessProducer

  • ProcessInjectionPoint

  • ProcessBeanAttributes

  • ProcessBean, ProcessManagedBean, ProcessSessionBean, ProcessProducerMethod and ProcessProducerField

  • ProcessObserverMethod

  • AfterBeanDiscovery

  • AfterDeploymentValidation

  • BeforeShutdown




What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact. Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.



For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed? Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?










share|improve this question




























    up vote
    3
    down vote

    favorite












    I'm trying to understand the lifecycle/flow of the @Initialized() events within the context of the CDI Container's events thrown that are observable in an extension.



    As per the WELD 2 docs, the Container lifecycle events are:





    • BeforeBeanDiscovery

    • ProcessAnnotatedType and ProcessSyntheticAnnotatedType

    • AfterTypeDiscovery

    • ProcessInjectionTarget and ProcessProducer

    • ProcessInjectionPoint

    • ProcessBeanAttributes

    • ProcessBean, ProcessManagedBean, ProcessSessionBean, ProcessProducerMethod and ProcessProducerField

    • ProcessObserverMethod

    • AfterBeanDiscovery

    • AfterDeploymentValidation

    • BeforeShutdown




    What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact. Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.



    For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed? Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I'm trying to understand the lifecycle/flow of the @Initialized() events within the context of the CDI Container's events thrown that are observable in an extension.



      As per the WELD 2 docs, the Container lifecycle events are:





      • BeforeBeanDiscovery

      • ProcessAnnotatedType and ProcessSyntheticAnnotatedType

      • AfterTypeDiscovery

      • ProcessInjectionTarget and ProcessProducer

      • ProcessInjectionPoint

      • ProcessBeanAttributes

      • ProcessBean, ProcessManagedBean, ProcessSessionBean, ProcessProducerMethod and ProcessProducerField

      • ProcessObserverMethod

      • AfterBeanDiscovery

      • AfterDeploymentValidation

      • BeforeShutdown




      What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact. Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.



      For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed? Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?










      share|improve this question















      I'm trying to understand the lifecycle/flow of the @Initialized() events within the context of the CDI Container's events thrown that are observable in an extension.



      As per the WELD 2 docs, the Container lifecycle events are:





      • BeforeBeanDiscovery

      • ProcessAnnotatedType and ProcessSyntheticAnnotatedType

      • AfterTypeDiscovery

      • ProcessInjectionTarget and ProcessProducer

      • ProcessInjectionPoint

      • ProcessBeanAttributes

      • ProcessBean, ProcessManagedBean, ProcessSessionBean, ProcessProducerMethod and ProcessProducerField

      • ProcessObserverMethod

      • AfterBeanDiscovery

      • AfterDeploymentValidation

      • BeforeShutdown




      What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact. Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.



      For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed? Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?







      java java-ee ejb cdi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 14:33

























      asked Nov 9 at 16:23









      Eric B.

      10.2k28105206




      10.2k28105206
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted











          Q1: What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact.




          As described in CDI 1.1 spec, section 11.5.4. AfterDeploymentValidation event:




          The container must fire an event after it has validated that there are no deployment problems and before creating contexts or processing requests.




          A1: As a consequence, events with qualifier @Initialized for any scope will be fired after AfterDeploymentValidation event.






          Q2: Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.




          A2: Section 6.7. Context management for built-in scopes describes behaviour for each built-in scope and provides recommendations for custom scopes implementations:




          Portable extensions are encouraged to fire an event with qualifier @Initialized(X.class) when a custom context is initialized
          ...

          An event with qualifier @Initialized(RequestScoped.class) is fired when the request context is initialized
          ...etc.







          Q3: For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed?




          As described in 6.7. Context management for built-in scopes:




          The request scope is active:

          - ...

          - during @PostConstruct callback of any bean.


          The application scope is active:

          - ...

          - during @PostConstruct callback of any bean.

          ...etc




          A3: For a scope to become active it needs to be initialized first. As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of any bean, but only for the scopes which must be active in a callback.






          Q4: Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?




          A4: EJBs are covered by a separate specification JSR 345: Enterprise JavaBeans TM ,Version 3.2 EJB Core Contracts and Requirements.



          According to section 4.8.1 Singleton Session Bean Initialization there:




          By default, the container is responsible for deciding when to initialize a singleton session bean instance. However, the Bean Provider can optionally configure the singleton session bean for eager initialization. If the Startup annotation appears on the singleton session bean class or if the singleton session bean has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the singleton session bean instance during the application startup sequence. The container must initialize all such startup-time singleton session beans before any external client requests (that is,
          client requests originating outside of the application) are delivered to any enterprise bean components in the application.

          ...

          In some cases, explicit initialization ordering dependencies exist between multiple singleton session bean components in an application. The DependsOn annotation is used to express these dependencies. A DependsOn dependency is used in cases where one singleton session bean must initialize before one or more other singleton session beans. The container ensures that all singleton session beans with which a singleton session bean has a DependsOn relationship have been initialized before the PostConstruct method is called.




          As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of EJB bean as well, but only for the scopes which must be active in a callback.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229576%2fwhen-is-the-initializedapplicationscoped-class-event-sent-in-cdi%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted











            Q1: What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact.




            As described in CDI 1.1 spec, section 11.5.4. AfterDeploymentValidation event:




            The container must fire an event after it has validated that there are no deployment problems and before creating contexts or processing requests.




            A1: As a consequence, events with qualifier @Initialized for any scope will be fired after AfterDeploymentValidation event.






            Q2: Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.




            A2: Section 6.7. Context management for built-in scopes describes behaviour for each built-in scope and provides recommendations for custom scopes implementations:




            Portable extensions are encouraged to fire an event with qualifier @Initialized(X.class) when a custom context is initialized
            ...

            An event with qualifier @Initialized(RequestScoped.class) is fired when the request context is initialized
            ...etc.







            Q3: For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed?




            As described in 6.7. Context management for built-in scopes:




            The request scope is active:

            - ...

            - during @PostConstruct callback of any bean.


            The application scope is active:

            - ...

            - during @PostConstruct callback of any bean.

            ...etc




            A3: For a scope to become active it needs to be initialized first. As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of any bean, but only for the scopes which must be active in a callback.






            Q4: Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?




            A4: EJBs are covered by a separate specification JSR 345: Enterprise JavaBeans TM ,Version 3.2 EJB Core Contracts and Requirements.



            According to section 4.8.1 Singleton Session Bean Initialization there:




            By default, the container is responsible for deciding when to initialize a singleton session bean instance. However, the Bean Provider can optionally configure the singleton session bean for eager initialization. If the Startup annotation appears on the singleton session bean class or if the singleton session bean has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the singleton session bean instance during the application startup sequence. The container must initialize all such startup-time singleton session beans before any external client requests (that is,
            client requests originating outside of the application) are delivered to any enterprise bean components in the application.

            ...

            In some cases, explicit initialization ordering dependencies exist between multiple singleton session bean components in an application. The DependsOn annotation is used to express these dependencies. A DependsOn dependency is used in cases where one singleton session bean must initialize before one or more other singleton session beans. The container ensures that all singleton session beans with which a singleton session bean has a DependsOn relationship have been initialized before the PostConstruct method is called.




            As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of EJB bean as well, but only for the scopes which must be active in a callback.






            share|improve this answer

























              up vote
              1
              down vote



              accepted











              Q1: What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact.




              As described in CDI 1.1 spec, section 11.5.4. AfterDeploymentValidation event:




              The container must fire an event after it has validated that there are no deployment problems and before creating contexts or processing requests.




              A1: As a consequence, events with qualifier @Initialized for any scope will be fired after AfterDeploymentValidation event.






              Q2: Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.




              A2: Section 6.7. Context management for built-in scopes describes behaviour for each built-in scope and provides recommendations for custom scopes implementations:




              Portable extensions are encouraged to fire an event with qualifier @Initialized(X.class) when a custom context is initialized
              ...

              An event with qualifier @Initialized(RequestScoped.class) is fired when the request context is initialized
              ...etc.







              Q3: For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed?




              As described in 6.7. Context management for built-in scopes:




              The request scope is active:

              - ...

              - during @PostConstruct callback of any bean.


              The application scope is active:

              - ...

              - during @PostConstruct callback of any bean.

              ...etc




              A3: For a scope to become active it needs to be initialized first. As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of any bean, but only for the scopes which must be active in a callback.






              Q4: Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?




              A4: EJBs are covered by a separate specification JSR 345: Enterprise JavaBeans TM ,Version 3.2 EJB Core Contracts and Requirements.



              According to section 4.8.1 Singleton Session Bean Initialization there:




              By default, the container is responsible for deciding when to initialize a singleton session bean instance. However, the Bean Provider can optionally configure the singleton session bean for eager initialization. If the Startup annotation appears on the singleton session bean class or if the singleton session bean has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the singleton session bean instance during the application startup sequence. The container must initialize all such startup-time singleton session beans before any external client requests (that is,
              client requests originating outside of the application) are delivered to any enterprise bean components in the application.

              ...

              In some cases, explicit initialization ordering dependencies exist between multiple singleton session bean components in an application. The DependsOn annotation is used to express these dependencies. A DependsOn dependency is used in cases where one singleton session bean must initialize before one or more other singleton session beans. The container ensures that all singleton session beans with which a singleton session bean has a DependsOn relationship have been initialized before the PostConstruct method is called.




              As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of EJB bean as well, but only for the scopes which must be active in a callback.






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted







                Q1: What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact.




                As described in CDI 1.1 spec, section 11.5.4. AfterDeploymentValidation event:




                The container must fire an event after it has validated that there are no deployment problems and before creating contexts or processing requests.




                A1: As a consequence, events with qualifier @Initialized for any scope will be fired after AfterDeploymentValidation event.






                Q2: Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.




                A2: Section 6.7. Context management for built-in scopes describes behaviour for each built-in scope and provides recommendations for custom scopes implementations:




                Portable extensions are encouraged to fire an event with qualifier @Initialized(X.class) when a custom context is initialized
                ...

                An event with qualifier @Initialized(RequestScoped.class) is fired when the request context is initialized
                ...etc.







                Q3: For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed?




                As described in 6.7. Context management for built-in scopes:




                The request scope is active:

                - ...

                - during @PostConstruct callback of any bean.


                The application scope is active:

                - ...

                - during @PostConstruct callback of any bean.

                ...etc




                A3: For a scope to become active it needs to be initialized first. As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of any bean, but only for the scopes which must be active in a callback.






                Q4: Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?




                A4: EJBs are covered by a separate specification JSR 345: Enterprise JavaBeans TM ,Version 3.2 EJB Core Contracts and Requirements.



                According to section 4.8.1 Singleton Session Bean Initialization there:




                By default, the container is responsible for deciding when to initialize a singleton session bean instance. However, the Bean Provider can optionally configure the singleton session bean for eager initialization. If the Startup annotation appears on the singleton session bean class or if the singleton session bean has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the singleton session bean instance during the application startup sequence. The container must initialize all such startup-time singleton session beans before any external client requests (that is,
                client requests originating outside of the application) are delivered to any enterprise bean components in the application.

                ...

                In some cases, explicit initialization ordering dependencies exist between multiple singleton session bean components in an application. The DependsOn annotation is used to express these dependencies. A DependsOn dependency is used in cases where one singleton session bean must initialize before one or more other singleton session beans. The container ensures that all singleton session beans with which a singleton session bean has a DependsOn relationship have been initialized before the PostConstruct method is called.




                As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of EJB bean as well, but only for the scopes which must be active in a callback.






                share|improve this answer













                Q1: What I'm having trouble finding out is where during this container lifecycle would the @Initialized event be triggered. I suspect that it is done AfterDeploymentValidation, but I cannot find any documentation to support that fact.




                As described in CDI 1.1 spec, section 11.5.4. AfterDeploymentValidation event:




                The container must fire an event after it has validated that there are no deployment problems and before creating contexts or processing requests.




                A1: As a consequence, events with qualifier @Initialized for any scope will be fired after AfterDeploymentValidation event.






                Q2: Additionally, I can't seem to find anything in the CDI 1.1 spec which dictates when/where the @Initalized event is thrown.




                A2: Section 6.7. Context management for built-in scopes describes behaviour for each built-in scope and provides recommendations for custom scopes implementations:




                Portable extensions are encouraged to fire an event with qualifier @Initialized(X.class) when a custom context is initialized
                ...

                An event with qualifier @Initialized(RequestScoped.class) is fired when the request context is initialized
                ...etc.







                Q3: For instance, is the event thrown before or after all the @PostConstruct methods of discovered beans is executed?




                As described in 6.7. Context management for built-in scopes:




                The request scope is active:

                - ...

                - during @PostConstruct callback of any bean.


                The application scope is active:

                - ...

                - during @PostConstruct callback of any bean.

                ...etc




                A3: For a scope to become active it needs to be initialized first. As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of any bean, but only for the scopes which must be active in a callback.






                Q4: Is the event thrown before or after an EJB @Startup is initialized? Is there any documentation that clearly lists the order/sequence of these events in CDI?




                A4: EJBs are covered by a separate specification JSR 345: Enterprise JavaBeans TM ,Version 3.2 EJB Core Contracts and Requirements.



                According to section 4.8.1 Singleton Session Bean Initialization there:




                By default, the container is responsible for deciding when to initialize a singleton session bean instance. However, the Bean Provider can optionally configure the singleton session bean for eager initialization. If the Startup annotation appears on the singleton session bean class or if the singleton session bean has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the singleton session bean instance during the application startup sequence. The container must initialize all such startup-time singleton session beans before any external client requests (that is,
                client requests originating outside of the application) are delivered to any enterprise bean components in the application.

                ...

                In some cases, explicit initialization ordering dependencies exist between multiple singleton session bean components in an application. The DependsOn annotation is used to express these dependencies. A DependsOn dependency is used in cases where one singleton session bean must initialize before one or more other singleton session beans. The container ensures that all singleton session beans with which a singleton session bean has a DependsOn relationship have been initialized before the PostConstruct method is called.




                As a consequence, events with qualifier @Initialized will be fired before @PostConstruct callback of EJB bean as well, but only for the scopes which must be active in a callback.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 at 23:44









                Illya Kysil

                701411




                701411






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229576%2fwhen-is-the-initializedapplicationscoped-class-event-sent-in-cdi%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Guess what letter conforming each word

                    Port of Spain

                    Run scheduled task as local user group (not BUILTIN)