4 Replies Latest reply on Dec 18, 2009 4:32 AM by Bernd Ruecker

    Change schedule-provider configuration at runtime

    Bernd Ruecker Master

      Hey guys.


      I currently face the requirement, that I want to change provider configuration of a service during runtime. In this special case, the frequency of the Scheduler is the concrete example (to automatically slow it down in case of errors or too much load or the like). The corresponding static configuratuion in the jboss-esb.xml looks like this;


              <schedule-provider name="Scheduler">
                  <simple-schedule scheduleid="GetJob-Trigger" frequency="5"/>


      The problem is, that it seams pretty hard to get the provider and reconfigure it. I looked into the following approach:


      Querying the JBoss4ESBDeployment MBean, this internally has a controller (ManagedLifecycleController) which has a reference to the ScheduleProvider. But from the MBean-Server I just get a proxy, which just can retrieve the jboss-esb.xml, but is not able to change anything. And I don't have any idea how to get to the concrete MBean implementation class.


      Any other idea? Any hint would be really helpful!


      For the ESB itself it would be nice to have some kind of central registry, where I can query all services, providers and listeners and can access its configuration. Something I cannot achieve with the jUDDI registry (or can I?).


      Thanks in advance


        • 1. Re: Change schedule-provider configuration at runtime
          Bernd Ruecker Master

          I am still searching for an easy and elegant solution, but it seems to be pretty hard. The way I found now is to go via the deployment, check for ESB deploymentmetadata and then use reflection a lot to query private fields until I "arrive" at the Trigger of the Scheudler. It is pretty hacky, but at least it works ;-)


          Here is the code:

          MBeanServer mbeanServer = MBeanServerLocator.locate();
          MainDeployerMBean mainDeployer = (MainDeployerMBean) MBeanProxyExt.create(MainDeployerMBean.class, MainDeployerMBean.OBJECT_NAME, mbeanServer);
          Collection deployed = mainDeployer.listDeployed();
          for (Object o : deployed) {
            if (o instanceof DeploymentInfo) {
              DeploymentInfo di = (DeploymentInfo) o;
              if (di.context.containsKey(JBoss4ESBDeploymentMetaData.class)) {
                JBoss4ESBDeploymentMetaData metaData = (JBoss4ESBDeploymentMetaData) di.context.get(JBoss4ESBDeploymentMetaData.class);      
                if (metaData.getDeployment().getController() instanceof ManagedLifecycleController) {
                  Field instancesField = ManagedLifecycleController.class.getDeclaredField("instances");
                  ManagedLifecycle[] instances = (ManagedLifecycle[]) instancesField.get(metaData.getDeployment().getController());
                  for (ManagedLifecycle instance : instances) {
                    if (instance instanceof ScheduleListener) {                  
                      // TODO check if we have the right scheduler depending on the service name (see sysout below)
                      ScheduleListener sl = (ScheduleListener)instance;
                      Field jobField = AbstractScheduledManagedLifecycle.class.getDeclaredField("job");
                      SchedulerJob job = (SchedulerJob) jobField.get(sl);
                      Field triggerField = SchedulerJob.class.getDeclaredField("trigger");
                      SimpleTrigger trigger = (SimpleTrigger) triggerField.get(job);
                      System.out.println("#### CHANGED SCHEDULER : Service '" + sl.getConfig().getAttribute("service-name") + "' with trigger " + trigger);


          Any comments? Anybody a better idea?


          And on the other hand I think it is a trigger for the development of the ESB to allow easier configuration or at least access of it during runtime. Or is it intended, that this is not possible?




          • 2. Re: Change schedule-provider configuration at runtime
            Tom Fennelly Master

            Hi Bernd.


            As you have discovered, this is not really possible with the current codebase, without a hack.  I think providing a clean API for this would probably require introduction of new APIs etc at the service/action level.  I don't think there are any plans to do anything like this, but I'm not sure.

            • 3. Re: Change schedule-provider configuration at runtime
              Ryan Hochstetler Newbie



              We've taken to re-writing the jboss-esb.xml on the fly and letting the deployer pick it up.  We needed dynamic reconfiguration of FTP gateways to support user-defined subscriptions.  Of course, this requires that you have deployment scanning on in production, which may not fit in with your current practices.  It works so far.  See the classes in jbossesb-config-model-1.1.0.jar, especially if you're already cursed to use xmlbeans.  If not, you can try converting the jboss-esb.xsd to pojos.  I tried it a few versions back and the schema had some mistakes related to an incomplete refactoring which prevented easy pojo generation, but I was eventually able to modify it enough to get Jibx's xsd-to-java tool to digest it fully.  I haven't revisited it in quite a while (since 4.4) so perhaps things have changed.

              • 4. Re: Change schedule-provider configuration at runtime
                Bernd Ruecker Master

                Thanks for the answers! Yeah, it seems we have to go down the same path and reading and changing the jboss-esb.xml during runtime. Current plan is, to write an EJB3 for it. But will at least get tricky in a cluster ;-)

                And at least I know I didn't completly miss the easy solution :-)