weblogicjmxjconsolemxbean

MBean non showing if registered on Weblogic Cluster


the scenario is:

  1. Application Server: Weblogic 12.2.1.2
  2. Application: an Entenprise Application

The working scenario:

  1. Application deployed on the Admin Server.
  2. JConsole correctly shows my MXBean.

The NOT working scenario:

  1. Application deployed on a cluster of 2 Managed Server.
  2. JMX configured on each Maanaged Server.
  3. JConsole does NOT show my MXBean.

Below my source code relevant fragments.

public class JpaCacheDescriptor {
    private String name;
    private int    size;

    @ConstructorProperties({ "name", "size" })
    public JpaCacheDescriptor(String name, int size) {
        this.name = name;
        this.size = size;
    }

    // Not relevant
}

public interface JpaCacheManager {
    List<JpaCacheDescriptor> getCaches();
    void clearAll();
}

@Slf4j
public class JpaCacheManagerImpl
    extends    StandardMBean
    implements JpaCacheManager
{
    private static ObjectName objectName;

    private static MBeanServer getMBeanServer()
        throws NamingException
    {
        InitialContext initialContext = new InitialContext();

        return (MBeanServer)initialContext.lookup("java:comp/jmx/runtime");
    }

    public JpaCacheManagerImpl()
        throws NotCompliantMBeanException
    {
        super(JpaCacheManager.class);
    }

    public static void register() {
        log.info("{ }");

        try {
            objectName = new ObjectName(String.format(
                "${wls.jmx.root}:name=${application.name},version=${application.version},node=%s,type=%s",
                System.getProperty("weblogic.Name"),
                JpaCacheManager.class.getSimpleName()
            ));

            JpaCacheManagerImpl jpaCacheMBean = new JpaCacheManagerImpl();
            StandardMBean       standardMBean = new StandardMBean(jpaCacheMBean, JpaCacheManager.class, true); // Force MXBean which is not inferred by @MXBean and MXBean prefix!!!

            getMBeanServer().registerMBean(standardMBean, objectName);

            log.info("Registered as \"{}\".", objectName.getCanonicalName());
        } catch (
              InstanceAlreadyExistsException
            | MalformedObjectNameException
            | MBeanRegistrationException
            | NamingException
            | NotCompliantMBeanException exception
        ) {
            objectName = null;
            log.error(exception.getMessage(), exception);
        }
    }

    public static void unregister() {
        log.info("{ }");

        if (null == objectName) {
            log.warn("MBean not registered!");
        } else {
            try {
                getMBeanServer().unregisterMBean(objectName);

                log.info("MBean unregistered.");
            }
            catch (
                  InstanceNotFoundException
                | MBeanRegistrationException
                | NamingException exception
            ) {
                log.error(exception.getMessage(), exception);
            }
        }
    }

    @Override
    public List<JpaCacheDescriptor> getCaches() {
        // Not relevant
    }

    @Override
    public void clearAll() {
        // Not relevant
    }
}

I spent a lot of time searching for a solution, but with no luck!

Thank you in advance.


Solution

  • I got a solution directly from Oracle ( https://blogs.oracle.com/weblogicserver/managing-weblogic-servers-with-jconsole ).

    Please look at following notes:

    jconsole -J-Djava.class.path=$JAVA_HOME/lib/jconsole.jar:$JAVA_HOME/lib/tools.jar:$WL_HOME/server/lib/wljmxclient.jar \
             -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote \
             -debug
    
    Remote URL:
      - Managed Server Runtime : service:jmx:iiop://<MANAGED_HOST>:<PORT>/jndi/weblogic.management.mbeanservers.runtime
      - Domain Runtime         : service:jmx:iiop://<ADMIN_HOST>:<PORT>/jndi/weblogic.management.mbeanservers.domainruntime
    
    User: <USER_NAME>
    Password: <PASSWORD>