12 Replies Latest reply on Jan 16, 2003 7:39 PM by Adrian Brock

    getClassLoaderFor

    Danilo Luiz Rheinheimer Newbie

      Hi,

      The version 4.0 of JBoss will implement the release 1.2 of the specification ? Or the 1.1 version.

      I am asking this because I need to use the

      MBeanServer.getClassLoaderFor(ObjectName mbeanName)

      function from the 1.2 spec.

      And how I can do this now on the 3.2 release of JBoss ?

      Thanks.

      Danilo.

        • 1. Re: JMX Invocation Value
          Adrian Brock Master

          Have a look at org.jboss.mx.server.Suspendable interface. This is extended by MBeanInvoker and in turn implemented by org.jboss.mx.server.AbstractMBeanInvoker class (with empty implementation).

          The methods provided by the interface are:

          public void suspend() {}

          public void suspend(long wait) throws TimeoutException{}

          public void suspend(boolean force) {}

          public boolean isSuspended() { return false; }

          public void setInvocationTimeout(long time) {}

          public long getInvocationTimeout() { return 0l; }

          public void resume() {}

          So these are available per registered MBean. You can provide policy implementations and then have these methods delegate to your policy for requested functionality.

          What you need to do in the policy/invoker level is keep track of the invocation objects going into the interceptor stack to be able to cleanly suspend a service (and possible recycle it). Simple counter should do. Method suspend() should block until all existing invocations are returned from the service. Invocations arriving in the mean time can be either queued (with or without timeout), redirected, or plain denied from the client via an exception. If queued (and assuming not timed out), resume() should release the invocations objects from the queue and send them down the interceptor stack.

          Suspend(long ms) only allows x ms for the existing invocations to be serviced. After that -- depending on the policy -- the service can be forcibly shut down or the server may just give up on the suspend() effort.

          Suspend(boolean force) obviously allows a forced suspend of all invocations.

          set/getTimeout on the invocation allows the invocations that have been queued to timeout -- if the service has not been resumed in the given time the invocations may be redirected or denied by throwing an exception to the client.

          In addition you need to add a mechanism to expose the suspend/resume operations as part of the management interface. That means each invoker is available through a central management component (some type of xxxManager object) that exposes the suspend(ObjectName) operations.

          • 2. Re: getClassLoaderFor
            Adrian Brock Master

            JBoss4 will implement jmx1.2
            It should be possible to backport some of jmx1.2
            to 3.2. But we need to get it working in JBoss4
            first.

            I've already done getClassLoaderFor() in JBoss4,
            but the other classloader changes are outstanding.

            Regards,
            Adrian

            • 3. Re: getClassLoaderFor
              Danilo Luiz Rheinheimer Newbie

              Ok.
              But you can suject any workaround to to 3.2 ?
              How I can got the ClassLoader of a MBean if I have his Name without use getClassLoaderFor ?

              • 4. Re: getClassLoaderFor
                Adrian Brock Master

                You can nearly get the spec behaviour with

                MBeanInfo info = server.getMBeanInfo(objectName);
                String name = info.getClassName().
                Class cl = Thread.currentThread().getContextClassLoader().loadClass(name).
                return cl.getClassLoader();

                But this will only work if you can load the class
                from your current classloader.

                It won't work for a DynamicMBean that returns the
                wrong class name information.

                Regards,
                Adrian

                • 5. Re: getClassLoaderFor
                  Danilo Luiz Rheinheimer Newbie

                  This not solve my problem because I can not load the class from your current classloader.

                  Looking on the source code :

                  public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException {
                  MBeanEntry entry = registry.get(name);
                  ClassLoader newTCL = entry.getClassLoader();
                  ...
                  }

                  There are some way of get the mbean MBeanEntry instance ?
                  If I can get the registry this can be done.

                  Any idea ?

                  --
                  Best regards,
                  Danilo mailto:danilo@floripa.com.br


                  • 6. Re: getClassLoaderFor
                    Adrian Brock Master

                    You can invoke on the registry

                    ClassLoader cl = server.invoke(
                    new ObjectName("JMImplemention:type=MBeanRegistry"),
                    "getValue",
                    new Object[] { "org.jboss.mx.classloader" },
                    new String[] { "java.lang.String" }
                    );

                    But this isn't the same thing as getClassLoaderFor(),
                    it only stores classloaders that where explicity
                    passed to server.createMBean

                    Why can't you load the class, where is your code?

                    Regards,
                    Adrian

                    • 7. Re: getClassLoaderFor
                      Danilo Luiz Rheinheimer Newbie

                      I will explain what I need to do. So maybe you can point me on the rigth direction.

                      I am deploing a MBean with the BeanShell script engine on it. One of the methods of this MBean enable the user to run scripts inside JBoss.
                      I am deploing this as a .sar file.
                      So the problem is the classloader used by this SAR can not load classes from other modules. And this is the objective of the script thing. Because of this I need to get the classloader of the EJB modules to beanshell use it as his classloader.

                      If you want to test it you can install a prototype on JBoss :

                      http://www.danilo.floripa.com.br/script-mbean.sar

                      You must be on a graphic UI (Windows/KDE/...) in the same machine of JBoss to this work. After install invoke the show() method of the Sigea:service=SigeaScriptManager
                      MBean. After this right click on the desktop and it go to "new class browser" to see a list of classes avaliable to the script.

                      It will close JBoss when you exit it, so do not do it on a production server.

                      Danilo.

                      • 8. Re: getClassLoaderFor
                        marc fleury Master

                        If your bean shell is loaded by JBoss then it is backed by a UnifiedClassLoader and these have visibility on every class. You don't need to be talking to a particular CL to be doing your work.

                        • 9. Re: getClassLoaderFor
                          Adrian Brock Master

                          There is something wrong with your bean
                          shell browser. It is only showing classes in the
                          classpath.

                          On the main shell type

                          Class c = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.Container");
                          System.out.println(c);

                          It does find the class.

                          Regards,
                          Adrian

                          • 10. Re: getClassLoaderFor
                            Adrian Brock Master

                            Oops

                            org.jboss.ejb.Container :-)

                            Regards,
                            Adrian

                            • 11. Re: getClassLoaderFor
                              Danilo Luiz Rheinheimer Newbie

                              Yes, you and Marc are right.
                              It is finding the classes fine.

                              I do not wrote this shell browser, it is from the BeanShell script.
                              I will write a new Shell Desktop to be used to script JBoss.

                              • 12. Re: getClassLoaderFor
                                Danilo Luiz Rheinheimer Newbie

                                I was looking on the bean shell browser, and it really gets his data from the classpath.
                                I was looking in the net about this and all code completation routines, and class browsers make it this way.

                                There are some way of get a list of all packages/classes avaliable to the UnifiedClassLoader ?