1 2 3 Previous Next 35 Replies Latest reply on Oct 24, 2011 3:51 PM by lmcdasi Go to original post
      • 15. Re: can I avoid a service to block as7 startup ?
        lmcdasi

        I am "ok" at that level - I think. What I am seeing though is that the FrameworkBootstrap class start method is called in parallel with the "addModule" from the SubsystemState. Then somehow the start context from the FrameworkBootstrap is marked as COMPLETE. And thus I am getting the IllegalStateException when the async method is called.

         

        I am not getting - yet - where my problem is ..... I understand that the SubsytemState has to fill the module list in order for the framework to retrieve it - that is done. But I do not understand why this goes on top of the framework .... looks like I miss a dependency or something else ...

        • 16. Re: can I avoid a service to block as7 startup ?
          lmcdasi

          I do have in the framework addService method :

           

          builder.addDependency(SubsystemState.

          SERVICE_NAME,SubsystemState.class, service.injectedSubsystemState);

           

          So I do not understand something ... else ...

           

           

          • 17. Re: can I avoid a service to block as7 startup ?
            jason.greene

            Dan Sirbu wrote:

             

            I am "ok" at that level - I think. What I am seeing though is that the FrameworkBootstrap class start method is called in parallel with the "addModule" from the SubsystemState. Then somehow the start context from the FrameworkBootstrap is marked as COMPLETE. And thus I am getting the IllegalStateException when the async method is called.

             

            I am not getting - yet - where my problem is ..... I understand that the SubsytemState has to fill the module list in order for the framework to retrieve it - that is done. But I do not understand why this goes on top of the framework .... looks like I miss a dependency or something else ...

            It's not clear to me exactly what you are doing, but you can't call your own start method. Only when your start method is called BY MSC can you call context.asynchronous(). As mentioned above the purpose of this method is to tell MSC that when it is starting a service, that the service did not complete startup. Otherwise, once the start method called by MSC returns, the service is started

            • 18. Re: can I avoid a service to block as7 startup ?
              jason.greene

              Jason Greene wrote:

               

              It's not clear to me exactly what you are doing, but you can't call your own start method. Only when your start method is called BY MSC can you call context.asynchronous(). As mentioned above the purpose of this method is to tell MSC that when it is starting a service, that the service did not complete startup. Otherwise, once the start method called by MSC returns, the service is started

               

              Put another way this is the chain of events that should happen for it to work

               

              MSC Thread X:
              
              MSC decides to start a service -> MSC calls your service.start() -> { 
                     /* Not done yet! */ ctx.asynchronous(); 
                      passToSomeOtherThread(ctx); 
                      return;
              }
              
              SomeOtherThread: {
                  doStuff();
                  /* Tell MSC I am done */ ctx.complete();
              }
              
              • 19. Re: can I avoid a service to block as7 startup ?
                lmcdasi

                I don't think the problem is there. I do not call my own start method.

                 

                The SubsytemState has a list of modules with their own "start methods that are executed from the ME start method.

                 

                It is the MSC that triggers ME.start(StartContext), correct ?

                 

                Then from ME.start(StartContext) and from the SubsysteState it retreives the M1,M2 list then:

                     M1.start

                     M2.start

                     return;          so "normally" I should be able to do context.asyn anywhere in between.

                 

                SubsystemState can add a module from jboss-admin.sh, because it has an addModule. The addModule can do M3.start for example via the framework.

                 

                The problem is that this addModule interferes with the ME.start(StartContext) - when it should not. It seems that it does twice the start. And the problem is that when switching traces from boot.log to server.log I think I miss something - a TR is already there for the logging.

                • 20. Re: can I avoid a service to block as7 startup ?
                  jason.greene

                  Dan Sirbu wrote:

                   

                  I don't think the problem is there. I do not call my own start method.

                   

                  The SubsytemState has a list of modules with their own "start methods that are executed from the ME start method.

                   

                  It is the MSC that triggers ME.start(StartContext), correct ?

                   

                  Then from ME.start(StartContext) and from the SubsysteState it retreives the M1,M2 list then:

                       M1.start

                       M2.start

                       return;          so "normally" I should be able to do context.asyn anywhere in between.

                  Only ME.start can call startContext.asynchronous(). Having something else do it doesn't make much sense (either the method is asynchronous or it isn't).

                   

                   

                  The problem is that this addModule interferes with the ME.start(StartContext) - when it should not. It seems that it does twice the start. And the problem is that when switching traces from boot.log to server.log I think I miss something - a TR is already there for the logging.

                   

                  The only call that is ever intended to be done outside of the ME.start(SC) thread is complete() and that MUST be done after asynchronous is called.

                  • 21. Re: can I avoid a service to block as7 startup ?
                    jason.greene

                    Just to be very clear this stack trace you pasted shows that asynchronous() is being called on a Service outside of it's start method

                     

                    org.jboss.msc.service.ServiceControllerImpl$StartContextImpl.asynchronous(ServiceControllerImpl.java:2158)
                    11:00:23,197 ERROR [stderr] (Controller Boot Thread)    at <mypkg>.AbstractModule.startAsync(AbstractModule.java:29) <-- context.asynchronous()
                    11:00:23,197 ERROR [stderr] (Controller Boot Thread)    at <mypkg>l.AsyncTestModuleImpl.start(AsyncTestModuleImpl.java:58)
                    11:00:23,197 ERROR [stderr] (Controller Boot Thread)    at <mypkg>.FrameworkBootstrapService.startModule(FrameworkBootstrapService.java:261)
                    
                    • 22. Re: can I avoid a service to block as7 startup ?
                      lmcdasi

                      I got that.

                       

                      My problem is that when the ME.start() is called by the MSC - the SubsystemState did not build yet the module list: M1, M2 !

                       

                      And thus when populating the model, SubsystemState will call addModule which in turn will do the WRONG stuff ! That is clear.

                       

                      Any idea what I doing wrong that the ME.start() gets called before the SubsystemState builds the list of modules ? I do not see why that happens.

                      • 23. Re: can I avoid a service to block as7 startup ?
                        jason.greene

                        Dan Sirbu wrote:

                         

                        I got that.

                         

                        My problem is that when the ME.start() is called by the MSC - the SubsystemState did not build yet the module list: M1, M2 !

                         

                        And thus when populating the model, SubsystemState will call addModule which in turn will do the WRONG stuff ! That is clear.

                        OK, but my point is that a call to asynchronous from another thread is always going to break. There is a race condition between the thread starting the service finishing (and MSC thinking it's done) and the other thread telling it the service is not done. The only way it makes sense to toggle that async method is to do it in the same thread that MSC is using to execute start() but before start() completes.

                         

                        Dan Sirbu wrote:

                         

                        Any idea what I doing wrong that the ME.start() gets called before the SubsystemState builds the list of modules ? I do not see why that happens.

                         

                        Only a service dependecy will prevent a service from starting, so ME has to depend on some other service that represents the state it needs.

                         

                        Maybe it would help to take a step back. Could you describe what you are ultimately trying to build here? It sounds like you are creating some new kind of module system?

                        • 24. Re: can I avoid a service to block as7 startup ?
                          lmcdasi

                          Yes - I commented out the addModule and the FrameworkBootstrap does not get the list of modules:

                           

                          server.log

                          12:46:49,376 INFO  [<mypkg>.SubsystemAdd] (Controller Boot Thread) Activating Test Subsystem
                          12:46:49,380 INFO  [<mypkg>.FrameworkBootstrapService] (Controller Boot Thread) Test FrameworkBootstrapService - created
                          12:46:49,381 INFO  [<mypkg>.FrameworkBootstrapService] (MSC service thread 1-15) Test FrameworkBootstrapService - started.
                          <NOTHING - which means that the module list is empty>
                          12:46:49,404 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-16) Starting remote JMX connector
                          12:46:49,408 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem

                           

                          boot.log
                          12:46:48,559 INFO  [<mypkg>.TestExtension] TestSubsystemParser --> readElement
                          12:46:48,561 INFO  [<mypkg>.TestExtension] TestSubsystemParser --> parseModulesElement
                          12:46:48,797 INFO  [<mypkg>.TestExtension] TestExtension --> Activating TestExtension
                          12:46:48,800 INFO  [<mypkg>.TestExtension] TestExtension --> Activating Testpreloaded modules
                          12:46:48,845 INFO  [<mypkg>.TestSubsystemAdd] TestSubsystemAdd --> populateModel
                          12:46:48,845 INFO  [<mypkg>.TestModuleAdd] TestModuleAdd --> execute add
                          12:46:48,846 INFO  [<mypkg>.TestModuleAdd] TestModuleAdd --> execute add

                           

                           

                          • 25. Re: can I avoid a service to block as7 startup ?
                            lmcdasi

                            Yes - I am trying to build a 'very' basic module loader. Instead of having multiple application from my collegues writing their own ME, I could have one ME handling different module startups - obviously with very basic or restricted type of service functionality (like no ejb support within, etc ...)

                             

                            So, I think I have done that ok but it looks like I have some issues.

                             

                            The problem must be around here :

                             

                            SubsystemState:

                             

                             

                             

                             

                             

                             

                             

                            public static ServiceController<SubsystemState> addService(ServiceTarget serviceTarget, Activation activation) {  // activation is forced to eager

                                 SubsystemState state = new SubsystemState(); // will this be the object that will be injected into the FrameworkBootstrapService ?!?

                                 state.setActivation(activation);

                             

                                 ServiceBuilder<SubsystemState> builder = serviceTarget.addService(SERVICE_NAME, state); };

                            protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) {

                                 context.addStep(new AbstractDeploymentChainStep() {

                                 builder.setInitialMode(Mode.ACTIVE);

                                 return builder.install()

                             

                            SubsystemAdd:

                             

                             

                             

                                 protected void  execute(DeploymentProcessorTarget processorTarget) {

                             

                                       // Add deployment dependency on the WAR/RAR/SAR applications

                                       processorTarget.addDeploymentProcessor(Phase.

                                       DEPENDENCIES, Phase.DEPENDENCIES_MODULE, new DependencyProcessor());

                                 }

                            }, OperationContext.Stage.

                            RUNTIME );

                             

                            ServiceTarget serviceTarget = context.getServiceTarget();

                             

                            // Add the Subsystem State service - it will hold subsystem config. Activation is EAGER for both.

                            newControllers.add(SubsystemState.addService(serviceTarget, getActivationMode(operation)));

                             

                            // Add the service - all modules will be handled via the service

                            newControllers.add(FrameworkBootstrapService.addService(serviceTarget, verificationHandler));

                             

                             

                             

                            So, to me, it looks like I am doing the right stuff. BUT ......

                             

                             

                                

                            }

                             

                            FrameworkBootstrapService: - dependency towards the SubsystemState added.

                            private

                             

                             

                            public static ServiceController<FrameworkBootstrapService> addService(final ServiceTarget target, final ServiceListener<Object>... listeners) {

                            FrameworkBootstrapService service =

                            new FrameworkBootstrapService();

                            ServiceBuilder<FrameworkBootstrapService> builder = target.addService(

                            SERVICE_NAME, service);

                            builder.addDependency(SubsystemState.

                            SERVICE_NAME,SubsystemState.class, service.injectedSubsystemState);

                            builder.addListener(listeners);

                             

                             

                            return builder.install();

                            }

                            final InjectedValue<SubsystemState> injectedSubsystemState = new InjectedValue<SubsystemState>();

                            • 26. Re: can I avoid a service to block as7 startup ?
                              lmcdasi

                              Interesting:

                               

                              13:30:23,199 INFO  [<mypkg>.SubsystemAdd] (Controller Boot Thread) Activating Test Subsystem
                              13:30:23,203 INFO  [<mypkg>.FrameworkBootstrapService] (Controller Boot Thread) Test SubsystemState - created
                              13:30:23,204 INFO  [<mypkg>.FrameworkBootstrapService] (Controller Boot Thread) Test FrameworkBootstrapService - created
                              13:30:23,204 INFO  [<mypkg>.FrameworkBootstrapService] (MSC service thread 1-9) Test SubsystemState - started
                              13:30:23,204 INFO  [<mypkg>.ModuleAdd] (Controller Boot Thread) Test ModuleAdd --> execute add
                              13:30:23,205 INFO  [<mypkg>.FrameworkBootstrapService] (MSC service thread 1-4) Test FrameworkBootstrapService - started.
                              13:30:23,205 INFO  [<mypkg>.TestModuleAdd] (Controller Boot Thread) Test ModuleAdd --> execute add

                              Hmm ... that does not look good. So it means that the dependency is respected BUT the operation step handler for the ModuleAdd comes in "late" ...

                               

                              And I am wondering how can I sync the Bootstrap with ModuleAdd operation handler.

                               

                              BR,

                              Dan S.

                              • 27. Re: can I avoid a service to block as7 startup ?
                                lmcdasi

                                Any idea how can I synchronize between the Framework bootstrap and the Add Operation Handler ?

                                • 28. Re: can I avoid a service to block as7 startup ?
                                  lmcdasi

                                  Well, the Framework depends "ok" on the SubsystemState. And since they run on the same thread the Framework will wait until Subsytem finishes.

                                   

                                  The problem comes from the fact that the SubsystemState has NO clue how many modules are to be set. Thus it does not know how many adds need to be performed in order for the Subsystem Model to be created ok. The adds are comming in parallel with the SubsytemState start method .....

                                   

                                  So, to sync ok, the SubsystemState "start" method needs to block the startup UNTIL the model is properly set with all modules otherwise the SubsystemState cannot have built the proper structure.

                                   

                                  And I see a similar issue within the jboss-as-osgi-service .....

                                   

                                  So again, how to properly synchronize this ....

                                   

                                  A Thead.sleep(1000) within the SubsystemState "start" method does a dirty job ....

                                   

                                  00:32:17,451 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-7) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/JAVACAF/lib

                                  00:32:17,451 INFO  [<mypkg>.TestSubsystemAdd] (Controller Boot Thread) Activating Test Subsystem

                                  00:32:17,455 INFO  [<mypkg>.FrameworkBootstrapService] (Controller Boot Thread) Test SubsystemState - created

                                  00:32:17,455 INFO  [<mypkg>.FrameworkBootstrapService] (Controller Boot Thread) Test FrameworkBootstrapService - created

                                  00:32:17,455 INFO  [<mypkg>.FrameworkBootstrapService] (MSC service thread 1-4) Test SubsystemState - started

                                  00:32:17,456 INFO  [<mypkg>.TestModuleAdd] (Controller Boot Thread) TestModuleAdd --> execute add

                                  00:32:17,457 INFO  [<mypkg>.TestModuleAdd] (Controller Boot Thread) TestModuleAdd --> execute add

                                   

                                  <MyModuleStartups>

                                   

                                  00:32:24,651 INFO  [<mypkg>.FrameworkBootstrapService] (MSC service thread 1-14) Test FrameworkBootstrapService - started.

                                  • 29. Re: can I avoid a service to block as7 startup ?
                                    jason.greene

                                    Dan Sirbu wrote:

                                     

                                    Yes - I am trying to build a 'very' basic module loader. Instead of having multiple application from my collegues writing their own ME, I could have one ME handling different module startups - obviously with very basic or restricted type of service functionality (like no ejb support within, etc ...)

                                     

                                    Hmm I don't really follow. Do you just want the ability to create lightweight services from a deployment? We have a notion called a "service activator" which allows you to take any jar/war deployment and have it launch services when it is deployed.

                                     

                                    If you could describe the use case behind this I might be able to offer better suggestions.