Skip to content

How to use JMX bean in app

Natalia Firstova edited this page Aug 21, 2020 · 4 revisions

How to allow JMX connection in the project

This section describes Tomcat startup configuration required for a remote connection of JMX tools. For more information see CUBA documentation.

Edit bin/setenv.bat in the following way:

set CATALINA_OPTS=-Xmx512m -Dfile.encoding=UTF-8

set CATALINA_OPTS=%CATALINA_OPTS% -Dlogback.configurationFile=../conf/logback.xml

set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote 
set CATALINA_OPTS=%CATALINA_OPTS% -Djava.rmi.server.hostname=localhost 
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.port=7777 
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.ssl=false 
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.authenticate=false

set JPDA_OPTS=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

Edit bin/setenv.sh in the following way:

CATALINA_OPTS="-Xmx512m -Dfile.encoding=UTF-8"

CATALINA_OPTS="$CATALINA_OPTS -Dlogback.configurationFile=../conf/logback.xml"

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote"

CATALINA_OPTS="$CATALINA_OPTS \\
-Djava.rmi.server.hostname=localhost \\
-Dcom.sun.management.jmxremote.port=7777 \\
-Dcom.sun.management.jmxremote.ssl=false \\
-Dcom.sun.management.jmxremote.authenticate=false"

JPDA_OPTS="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

How to use JMX bean in-app

Let's assume that you need a JMX bean that will perform operations for UI testing, for example, terminates sessions by user logins and terminates all non-system sessions. You've created bean interface UiTestSupportMBean with necessary methods and bean class UiTestSupport that implements the interface.

To use this JMX bean in UI tests you need to create a public interface with @JmxName annotation in the same package with tests:

@JmxName("app-core.rent:type=UiTestSupport")
public interface UiTestSupport {
    String killSessions(String[] logins);

    String killAllSessions();
}

@JmxName - annotation provided by Masquerade connector. It is used to refer to JMX bean class: first, you need to set module contains the bean, than project name and bean class. Also, Masquerade connector containConnectors factory that provides proxy objects for remote services. To use the JMX bean method in app use jmx method from the factory:

Connectors.jmx(UiTestSupport.class)
                    .killAllSessions()