8 Replies Latest reply on Sep 23, 2014 12:13 PM by Morten Olsen

    Switchyard deployed/initialized event - lifecycle events??

    Anton Hughes Master

      Hi

       

      We would like to call a service when our Switchyard project is deployed

       

      We tried doing this in PostConstruct - but, there is this issue: Bug 1086295 – SwitchYard injection does not work in @PostConstruct method of Service bean

      We tried doing it with Quartz - but there is this issue: [SWITCHYARD-2177] 'cron' should be optional in Camel Quartz - JBoss Issue Tracker

       

      Are there any Switchyard lifecycle events, such as deployed, that we can observe?

       

      Thanks

        • 1. Re: Switchyard deployed/initialized event - lifecycle events??
          Anton Hughes Master

          Hi,

           

          We are really stuck on this issue.

           

          Does anyone have any suggestions? Any help is greatly appreciated.

           

          Thanks

          • 2. Re: Switchyard deployed/initialized event - lifecycle events??
            Morten Olsen Newbie

            I'm facing a similar thing and tried to observe the ApplicationDeployedEvent, but I'm getting this:

             

            18:02:53,472 INFO  [org.jboss.weld.ClassLoading] (MSC service thread 1-10) catching: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class mypackage.Init

              at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:167) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.bootstrap.BeanDeployer.loadWeldClass(BeanDeployer.java:116) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:79) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:135) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:184) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:349) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:63) [jboss-as-weld-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67]

              at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]

            Caused by: java.lang.NoClassDefFoundError: org/switchyard/deploy/event/ApplicationDeployedEvent

              at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.7.0_67]

              at java.lang.Class.privateGetDeclaredMethods(Class.java:2570) [rt.jar:1.7.0_67]

              at java.lang.Class.getDeclaredMethods(Class.java:1855) [rt.jar:1.7.0_67]

              at org.jboss.weld.util.reflection.SecureReflections$8.work(SecureReflections.java:175) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.util.reflection.SecureReflections$8.work(SecureReflections.java:172) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.util.reflection.SecureReflectionAccess.runAndWrap(SecureReflectionAccess.java:63) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.util.reflection.SecureReflections.getDeclaredMethods(SecureReflections.java:172) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:235) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:121) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:59) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:50) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:358) [guava-13.0.1-redhat-1.jar:13.0.1-redhat-1]

              at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184) [guava-13.0.1-redhat-1.jar:13.0.1-redhat-1]

              at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153) [guava-13.0.1-redhat-1.jar:13.0.1-redhat-1]

              at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69) [guava-13.0.1-redhat-1.jar:13.0.1-redhat-1]

              at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:396) [guava-13.0.1-redhat-1.jar:13.0.1-redhat-1]

              at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:163) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]

              ... 11 more

            Caused by: java.lang.ClassNotFoundException: org.switchyard.deploy.event.ApplicationDeployedEvent from [Module "deployment.rhythm.jar:main" from Service Module Loader]

              at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:196) [jboss-modules.jar:1.2.0.Final-redhat-1]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:444) [jboss-modules.jar:1.2.0.Final-redhat-1]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:432) [jboss-modules.jar:1.2.0.Final-redhat-1]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:374) [jboss-modules.jar:1.2.0.Final-redhat-1]

              at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:119) [jboss-modules.jar:1.2.0.Final-redhat-1]

              ... 29 more

            • 3. Re: Switchyard deployed/initialized event - lifecycle events??
              Keith Babo Master

              Does anyone have any suggestions? Any help is greatly appreciated.

               

               

              We don't provide direct support for invoking a service based on an event.  The best way to support this would probably be producing implementation-specific events, e.g. CDI events for CDI beans.  Looking at alternate solutions, have you considered using a Camel timer binding with a delay of 0 and a repeat count of 1?  You won't find the timer binding in the tooling palette, but it's part of camel-core so you can just use the Camel URI binding to configure it.

               

              Camel URI - SwitchYard - Project Documentation Editor

              • 4. Re: Switchyard deployed/initialized event - lifecycle events??
                Keith Babo Master

                Morten Olsen wrote:

                 

                I'm facing a similar thing and tried to observe the ApplicationDeployedEvent, but I'm getting this:

                 

                Caused by: java.lang.NoClassDefFoundError: org/switchyard/deploy/event/ApplicationDeployedEvent

                  at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.7.0_67]

                  at java.lang.Class.privateGetDeclaredMethods(Class.java:2570) [rt.jar:1.7.0_67]

                  at java.lang.Class.getDeclaredMethods(Class.java:1855) [rt.jar:1.7.0_67]

                 

                Hmm ... IIRC, the deploy module is not automatically added to the application's dependencies during deployment.  You could try adding it as a dependency in your application's manifest or through jboss-deployment-structure.xml.  How are you using the event in your CDI bean?

                • 5. Re: Switchyard deployed/initialized event - lifecycle events??
                  Keith Babo Master

                  For reference, the module name would be "org.switchyard.deploy".

                  • 6. Re: Switchyard deployed/initialized event - lifecycle events??
                    Morten Olsen Newbie

                    I just tried the camel timer through the uri binding, as my goal is just to have a method called in my bean when the application is started - but I was unsuccessful.

                    My switchyard XML snippet looks like this

                     

                        ...

                        <sca:service name="StrategyService" promote="StrategyComponent/StrategyService">

                          <sca:interface.java interface="mypackage.StrategyService"/>

                          <rest:binding.rest>

                            <rest:contextMapper/>

                            <rest:interfaces>mypackage.StrategyResource</rest:interfaces>

                            <rest:contextPath>rest-binding</rest:contextPath>

                          </rest:binding.rest>

                          <quartz:binding.quartz>

                            <operationSelector operationName="syncStrategies"/>

                            <quartz:name>syncStrategies</quartz:name>

                            <quartz:cron>0 0/10 * * * ?</quartz:cron>

                          </quartz:binding.quartz>

                          <camel:binding.uri configURI="timer:init?delay=0&amp;repeatCount=1">

                            <operationSelector operationName="init"/>

                          </camel:binding.uri>

                        </sca:service>

                        ...

                     

                    When building with Maven I get:

                     

                    [ERROR] Failed to execute goal org.switchyard:switchyard-plugin:1.1.0.Final:configure (default) on project myproject: SWITCHYARD011602: Model [org.switchyard.config.model.switchyard.v1.V1SwitchYardModel] is invalid: cvc-complex-type.2.4.a: Invalid content was found starting with element 'camel:binding.uri'. One of '{"http://docs.oasis-open.org/ns/opencsa/sca/200912":binding, "http://docs.oasis-open.org/ns/opencsa/sca/200912":callback, "http://docs.oasis-open.org/ns/opencsa/sca/200912":requires, "http://docs.oasis-open.org/ns/opencsa/sca/200912":policySetAttachment, "http://docs.oasis-open.org/ns/opencsa/sca/200912":extensions}' is expected. -> [Help 1]

                     

                    I will try your suggestion about jboss-deployment-structure.xml now.

                    • 7. Re: Switchyard deployed/initialized event - lifecycle events??
                      Keith Babo Master

                      It's not the timer configuration that's the problem.  It's the <camel:binding.uri> definition.  Do you have the 'camel' namespace prefix defined in your switchyard.xml?

                       

                      e.g. xmlns:camel="urn:switchyard-component-camel-core:config:1.1"

                      • 8. Re: Switchyard deployed/initialized event - lifecycle events??
                        Morten Olsen Newbie

                        I was using: xmlns:camel="urn:switchyard-component-camel-core:config:1.0" - not ending in 1.1.

                         

                        However, I found another way that seems to be working. I'm using: xmlns:quartz="urn:switchyard-component-camel-quartz:config:1.1" and:

                         

                              <quartz:binding.quartz>

                                <operationSelector operationName="init"/>

                                <quartz:contextMapper/>

                                <quartz:additionalUriParameters>

                                  <quartz:parameter name="trigger.repeatCount" value="0"/>

                                </quartz:additionalUriParameters>

                                <quartz:name>init</quartz:name>

                                <quartz:cron/>

                              </quartz:binding.quartz>