7 Replies Latest reply on Oct 17, 2012 11:58 AM by ludof

    How to programmatically access custom workManager defined in standalone.xml

    jboss7_newbie

      I have defined a custome workManager in standalone.xml as given below -

      <subsystem xmlns="urn:jboss:domain:jca:1.1">

                  <archive-validation enabled="true" fail-on-error="true" fail-on-warn="false"/>

                  <bean-validation enabled="true"/>

                  <default-workmanager>

                      <short-running-threads>

                          <core-threads count="50"/>

                          <queue-length count="50"/>

                          <max-threads count="50"/>

                          <keepalive-time time="10" unit="seconds"/>

                      </short-running-threads>

                      <long-running-threads>

                          <core-threads count="50"/>

                          <queue-length count="50"/>

                          <max-threads count="50"/>

                          <keepalive-time time="10" unit="seconds"/>

                      </long-running-threads>

                  </default-workmanager>

                  <workmanager name="NewWorkManager">

                      <short-running-threads>

                          <core-threads count="50"/>

                          <queue-length count="50"/>

                          <max-threads count="50"/>

                          <keepalive-time time="10" unit="seconds"/>

                      </short-running-threads>

                  </workmanager>

                  <bootstrap-contexts>

                      <bootstrap-context name="NewBootStrapContext" workmanager="NewWorkManager"/>

                  </bootstrap-contexts>

                  <cached-connection-manager debug="true" error="false"/>

              </subsystem>

      The <bootstrap-context> is also included in the activemq resource adapter as in the post - https://community.jboss.org/thread/169380 it is mentioned to do so.

      I can see the new customer workmanager from Jboss Admin conole and would like to access it programatically from my application via Spring.

       

      This is the piece of code trying to that -

      MBeanServer server = java.lang.management.ManagementFactory.getPlatformMBeanServer();

      ObjectName on = new ObjectName("jboss.as:subsystem=jca,workmanager=NewWorkManager");

      ObjectInstance instance = server.getObjectInstance(on);

       

      But on running my application I get -

      Caused by: javax.management.InstanceNotFoundException: JBAS011340: No MBean found with name jboss.as:subsystem=jca,workmanager=NewWorkManager

          at org.jboss.as.jmx.model.ModelControllerMBeanHelper.createInstanceNotFoundException(ModelControllerMBeanHelper.java:398)

          at org.jboss.as.jmx.model.ModelControllerMBeanHelper.getObjectInstance(ModelControllerMBeanHelper.java:291)

          at org.jboss.as.jmx.model.ModelControllerMBeanServerPlugin.getObjectInstance(ModelControllerMBeanServerPlugin.java:122)

          at org.jboss.as.jmx.PluggableMBeanServerImpl.getObjectInstance(PluggableMBeanServerImpl.java:217)

          ... 78 more

       

      I have started Jconsole and I can see the object as well.I also tried listing the MBeans from my application and the output does not show it -

       

      MBeanServer server = java.lang.management.ManagementFactory.getPlatformMBeanServer();

      System.out.println("Got the MBeanServer - " + server);

      ObjectName serviceRef = new ObjectName("*.*:*");

      Set<ObjectName> mbeans = server.queryNames(serviceRef, null);

      for (ObjectName on :mbeans)

      {

                  System.out.println("\t ObjectName : " + on);

      }

      Output -

      18:18:41,471 INFO  [stdout] (MSC service thread 1-1) Got the MBeanServer - org.jboss.as.jmx.PluggableMBeanServerImpl@f8c570

       

      18:18:41,471 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=Memory

       

      18:18:41,471 INFO  [stdout] (MSC service thread 1-1)      ObjectName : jboss.jta:type=ObjectStore

       

      18:18:41,471 INFO  [stdout] (MSC service thread 1-1)      ObjectName : jboss.modules:type=ModuleLoader,name=ModuleLoaderIntegration-7

       

      18:18:41,472 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=Compilation

       

      18:18:41,472 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=GarbageCollector,name=MarkSweepCompact

       

      18:18:41,472 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=MemoryPool,name=Perm Gen

       

      18:18:41,472 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=OperatingSystem

       

      18:18:41,472 INFO  [stdout] (MSC service thread 1-1)      ObjectName : jboss.modules:type=ModuleLoader,name=ServiceModuleLoader-5

       

      18:18:41,472 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=MemoryManager,name=CodeCacheManager

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=GarbageCollector,name=Copy

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=MemoryPool,name=Code Cache

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=Runtime

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=ClassLoading

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : org.apache.derby:type=Version,jar=derby.jar,system=c013800d-013a-4688-f518-00000e04d4d0

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=Threading

       

      18:18:41,473 INFO  [stdout] (MSC service thread 1-1)      ObjectName : org.apache.derby:type=Management,system=c013800d-013a-4688-f518-00000e04d4d0

       

      18:18:41,474 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.util.logging:type=Logging

       

      18:18:41,474 INFO  [stdout] (MSC service thread 1-1)      ObjectName : org.apache.derby:type=JDBC,system=c013800d-013a-4688-f518-00000e04d4d0

       

      18:18:41,474 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=MemoryPool,name=Eden Space

       

      18:18:41,474 INFO  [stdout] (MSC service thread 1-1)      ObjectName : jboss.msc:type=container,name=jboss-as

       

      18:18:41,474 INFO  [stdout] (MSC service thread 1-1)      ObjectName : jboss.ws:service=ServerConfig

       

      18:18:41,474 INFO  [stdout] (MSC service thread 1-1)      ObjectName : com.sun.management:type=HotSpotDiagnostic

       

      18:18:41,475 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=MemoryPool,name=Survivor Space

       

      18:18:41,475 INFO  [stdout] (MSC service thread 1-1)      ObjectName : jboss.modules:type=ModuleLoader,name=LocalModuleLoader-3

       

      18:18:41,475 INFO  [stdout] (MSC service thread 1-1)      ObjectName : java.lang:type=MemoryPool,name=Tenured Gen

       

       

      Am I doing something wrong and is there a better way of accessing the custom workmanager.Please do let me know.

        • 1. Re: How to programmatically access custom workManager defined in standalone.xml
          maeste

          The best way to access it is to use DMR api, or if you prefer CLI API to access DMR and manage it.

           

          https://docs.jboss.org/author/display/AS7/Detyped+management+and+the+jboss-dmr+library

           

          https://community.jboss.org/wiki/JBossAS7Command-linePublicAPI

           

          regards

          S.

          • 2. Re: How to programmatically access custom workManager defined in standalone.xml
            jboss7_newbie

            Thank you for responding.If I am to use the CLI API then I assume I need to have jboss-cli-client.jar in my classpath.

            I am trying to access the workmanager from my deployed application placed in standalone\deployments which means I would need to place a dependency to jboss-cli-client.jar.

            Is that possible/allowed ?

            • 3. Re: How to programmatically access custom workManager defined in standalone.xml
              jesper.pedersen

              Use the DMR API or develop a resource adapter with a proper API that uses the WorkManager internally

              • 4. Re: How to programmatically access custom workManager defined in standalone.xml
                jboss7_newbie

                Thank you.I'll check the DMR API as it seems the best way to do the lookup.

                • 5. Re: How to programmatically access custom workManager defined in standalone.xml
                  jboss7_newbie

                  Here is a snippet of what I am doing using the DMR API -

                   

                  ModelNode request = new ModelNode();

                  request.get(ClientConstants.OP).set("read-resource");

                  request.get("recursive").set(false);

                  request.get(ClientConstants.OP_ADDR).add("subsystem", "jca");

                  System.out.println("built the request " + request);

                             

                  ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);

                  System.out.println("execute the request");

                  ModelNode response = client.execute(new OperationBuilder(request).build());

                  System.out.println("response recieved - " + response);

                   

                  In my logs-

                   

                    [stdout] (MSC service thread 1-14) built the request {

                    [stdout] (MSC service thread 1-14)     "operation" => "read-resource",

                    [stdout] (MSC service thread 1-14)     "recursive" => false,

                    [stdout] (MSC service thread 1-14)     "address" => [("subsystem" => "jca")],

                     [stdout] (MSC service thread 1-14) }

                   

                    [stdout] (MSC service thread 1-14) execute the request

                   

                  [org.jboss.as.controller.management-operation] (management-handler-thread - 1) JBAS014613: Operation ("read-resource") failed - address: ([("subsystem" => "jca")]) - failure description: "JBAS014807: Management resource '[(\"subsystem\" => \"jca\")]' not found"

                    [stdout] (MSC service thread 1-14) response recieved - {

                    [stdout] (MSC service thread 1-14)     "outcome" => "failed",

                    [stdout] (MSC service thread 1-14)     "failure-description" => "JBAS014807: Management resource '[(\"subsystem\" => \"jca\")]' not found",

                    [stdout] (MSC service thread 1-14)     "rolled-back" => true

                    [stdout] (MSC service thread 1-14) }

                   

                  From the CLI if I issue a command -

                  [standalone@localhost:9999 /] workmanager read-resource --name=NewWorkManager [Note: I created a new command 'workmanager' from the CLI]

                   

                  The response I get -

                  long-running-threads=n/a

                  name=NewWorkManager

                  short-running-threads

                    CentralWorkManager=n/a

                   

                  So from CLI I am seeing my custom workmanager.Although I don't know why I have 'n/a' for the long and short running threads.In the Admin console I see the correct values.

                  If I try request.get(ClientConstants.OP_ADDR).add("subsystem", "jca/workmanager"); then I get a

                  [stdout] (MSC service thread 1-3) "failure-description" => "JBAS014739: No handler for read-resource at address [(\"subsystem\" => \"jca/workmanager\")]",

                   

                  I think the way I have built my request is not quite right.Could anybody please help me on this.

                  • 6. Re: How to programmatically access custom workManager defined in standalone.xml
                    jboss7_newbie

                    In CLI if I run the command -

                    [standalone@localhost:9999 /] /subsystem=jca/:read-resource

                    {

                        "outcome" => "success",

                        "result" => {

                            "archive-validation" => {"archive-validation" => undefined},

                            "bean-validation" => {"bean-validation" => undefined},

                            "bootstrap-context" => {

                                "default" => undefined,

                                "NewBootStrapContext" => undefined

                            },

                            "cached-connection-manager" => {"cached-connection-manager" => undefined

                    },

                            "workmanager" => {

                                "default" => undefined,

                                "NewWorkManager" => undefined,

                            }

                        }

                    }

                     

                    Via code I tried -

                    ModelNode request = new ModelNode();

                                request.get(ClientConstants.OP).set("read-resource");

                                request.get("recursive").set(false);

                                request.get(ClientConstants.OP_ADDR).add("/subsystem=jca");

                     

                    The response is different -

                    [stdout] (MSC service thread 1-10) response recieved - {

                    [stdout] (MSC service thread 1-10)     "outcome" => "success",

                    [stdout] (MSC service thread 1-10)     "result" => {

                    [stdout] (MSC service thread 1-10)         "deployment" => undefined,

                    [stdout] (MSC service thread 1-10)         "deployment-overlay" => undefined,

                    [stdout] (MSC service thread 1-10)         "interface" => undefined,

                    [stdout] (MSC service thread 1-10)         "management-major-version" => 1,

                    [stdout] (MSC service thread 1-10)         "management-micro-version" => 0,

                    [stdout] (MSC service thread 1-10)         "management-minor-version" => 4,

                    [stdout] (MSC service thread 1-10)         "name" => "ukcds-dev",

                    [stdout] (MSC service thread 1-10)         "namespaces" => [],

                    [stdout] (MSC service thread 1-10)         "product-name" => undefined,

                    [stdout] (MSC service thread 1-10)         "product-version" => undefined,

                    [stdout] (MSC service thread 1-10)         "release-codename" => "Steropes",

                    [stdout] (MSC service thread 1-10)         "release-version" => "7.2.0.Alpha1-SNAPSHOT",

                    [stdout] (MSC service thread 1-10)         "schema-locations" => [],

                    [stdout] (MSC service thread 1-10)         "socket-binding-group" => undefined,

                    [stdout] (MSC service thread 1-10)         "subsystem" => undefined,

                    [stdout] (MSC service thread 1-10)         "system-property" => undefined,

                    [stdout] (MSC service thread 1-10)         "core-service" => {

                    [stdout] (MSC service thread 1-10)             "management" => undefined,

                    [stdout] (MSC service thread 1-10)             "service-container" => undefined,

                    [stdout] (MSC service thread 1-10)             "server-environment" => undefined,

                    [stdout] (MSC service thread 1-10)             "platform-mbean" => undefined

                    [stdout] (MSC service thread 1-10)         },

                    [stdout] (MSC service thread 1-10)         "extension" => {

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.clustering.infinispan" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.configadmin" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.connector" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.deployment-scanner" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.ee" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.ejb3" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.jaxrs" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.jdr" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.jmx" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.jpa" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.jsf" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.logging" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.mail" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.naming" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.osgi" => undefined,

                    [stdout] (MSC service thread 1-10)             "org.jboss.as.pojo" => undefined,

                     

                    [stdout] (MSC service thread 1-10)         "org.jboss.as.remoting" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.sar" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.security" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.threads" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.transactions" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.web" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.webservices" => undefined,
                    [stdout] (MSC service thread 1-10)         "org.jboss.as.weld" => undefined
                    [stdout] (MSC service thread 1-10)     },
                    [stdout] (MSC service thread 1-10)     "path" => {
                    [stdout] (MSC service thread 1-10)         "jboss.server.temp.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "user.home" => undefined,
                    [stdout] (MSC service thread 1-10)         "jboss.server.base.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "java.home" => undefined,
                    [stdout] (MSC service thread 1-10)         "user.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "jboss.server.data.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "jboss.home.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "jboss.server.log.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "jboss.server.config.dir" => undefined,
                    [stdout] (MSC service thread 1-10)         "jboss.controller.temp.dir" => undefined
                    [stdout] (MSC service thread 1-10)     }
                    [stdout] (MSC service thread 1-10) }

                    [stdout] (MSC service thread 1-10) }

                     

                    I assume they are the same requests then why do I get different responses ?

                    • 7. Re: How to programmatically access custom workManager defined in standalone.xml
                      ludof

                      Could you please post sample code to use DMR and create the corresponding workmanager instance ?

                       

                      Thanks.