!--a11y-->
Query MBeans 
Often, you do not know the full name of a MBean in advance, but you want to query all MBeans whose ObjectNames match a given pattern. The following example returns all MBeans of a certain type on the given element:

|
import java.util.Set; import javax.management.ObjectName; import javax.management.MBeanServerConnection; import com.sap.jmx.ObjectNameFactory; ... MBeanServerConnection mbsc; ... // build the ObjectName pattern: // ":*,j2eeType=SAP_MyType,SAP_J2EEClusterNode=4001,SAP_J2EECluster=\"\"" ObjectName pattern = ObjectNameFactory.getPatternForServerChildPerNode("SAP_MyType", "4001", null); // the query returns a set of matching ObjectNames Set names = mbsc.queryName(pattern, null); |
Another example shows a query that returns all MBeans of a certain type on all elements, assuming that the given type is a local MBean. This will result in a broadcast to all cluster elements, performed by the Mbean Server internally:

|
... // build the ObjectName pattern: // ":*,j2eeType=SAP_MyType,SAP_J2EECluster=\"\"" ObjectName pattern = ObjectNameFactory.getPatternForServerChildPerNode("SAP_MyType", null); // the query returns a set of matching ObjectNames Set names = mbsc.queryName(pattern, null); |

Both queries apply to the default domain only.
