This section describes how to subscribe to the partitioning facility (WPF) PMI statistics. For additional information describing how to enable this infrastructure, see the management section. To include reportTransactionComplete(....) in your application, see the partitioned stateless session bean (PSSB) programming section.
package com.ibm.websphere.wpf.jmx; import java.util.Properties; import java.util.Set; import javax.management.InstanceNotFoundException; import javax.management.MBeanException; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.ReflectionException; import com.ibm.websphere.management.AdminClient; import com.ibm.websphere.management.AdminClientFactory; import com.ibm.websphere.management.exception.ConnectorException; /** * Creates a node scoped resource.xml entry for a DB2 XA datasource. * The datasource created is for CMP use. * * You need following to run with the classpath * $WAS_HOME\lib\admin.jar; * $WAS_HOME\lib\wasjmx.jar; * $WAS_HOME\lib\wasx.jar */ public class PMIJMXSample { /** * Main method. * arg[0] is the connection type, such as SOAP. * arg[1] is the connection host, such as localhost. * arg[2] is the connections port, such as 8879 * arg[3] is the optional process. Default is Deployment Manager */ public static void main(String[] args) throws MalformedObjectNameException, ConnectorException, MBeanException, ReflectionException, InstanceNotFoundException { System.out.println("Sample starts"); // Initialize the AdminClient. String connectorType = args[0]; String connectorHost = args[1]; String connectorPort = args[2]; String jmxServer = "Deployment Manager"; if (args.length >= 4) { jmxServer = args[3]; } Properties adminProps = new Properties(); adminProps.setProperty(AdminClient.CONNECTOR_TYPE, connectorType); adminProps.setProperty(AdminClient.CONNECTOR_HOST, connectorHost); adminProps.setProperty(AdminClient.CONNECTOR_PORT, connectorPort); AdminClient adminClient = AdminClientFactory.createAdminClient(adminProps); ObjectName queryName = new ObjectName("WebSphere:type=WPF,process=" + jmxServer + ",*"); ObjectName wpfJMX = null; Set s = adminClient.queryNames(queryName, null); if (!s.isEmpty()) { wpfJMX = (ObjectName) s.iterator().next(); } else { System.out.println("WPF JMX MBean was not found"); System.exit(0); } String subscribeWPFPMIName = "subscribeWPFPMI"; String[] subscribeSignatures = new String[] { "java.lang.String", "java.lang.String", "java.lang.Integer", "java.lang.Integer", "java.lang.Integer", "java.lang.Integer" }; Object[] subscribeParams = new Object[] { "WPFKeyBasedPartitionSample", "WPFKeyBasedPartition", new Integer(0), new Integer(1), new Integer(5), new Integer(60000)}; // invoke the subscribeWPFPMI method Long id = (Long) adminClient.invoke(wpfJMX, subscribeWPFPMIName, subscribeParams, subscribeSignatures); System.out.println("Subscription ID is " + id); String unsubscribeWPFPMIName = "unsubscribeWPFPMI"; String[] unsubscribeSignatures = new String[] { "java.lang.Long" }; Object[] unsubscribeParams = new Object[] { id }; // invoke the unsubscribeWPFPMI method adminClient.invoke(wpfJMX, unsubscribeWPFPMIName, unsubscribeParams, unsubscribeSignatures); } }
wsamdin -f JACL_FILE
# Jacl script to show how to subscribe and unsubscribe WPF PMI # get WPF Mbean set wpf [lindex [$AdminControl queryNames "type=WPF,process=Deployment Manager,*"] 0]puts $wpf # subscribe WPF PMI set id [$AdminControl invoke $wpf subscribeWPFPMI "WPFKeyBasedPartitionSample WPFKeyBasedPartition 0 1 5 60000"] puts $id # unsubscribe WPF PMI $AdminControl invoke $wpf unsubscribeWPFPMI $id
wsamdin -lang jython -f JYTHON_FILE
# Jython script to show how to subscribe and unsubscribe WPF PMI # get WPF Mbean strObjectName=AdminControl.queryNames("type=WPF,process=Deployment Manager,*") objectName = AdminControl.makeObjectName(strObjectName) wpf = TypedProxy.makeProxy(AdminControl, objectName, "com.ibm.websphere.wpf.jmx.WPFJMX") # subscribe WPF PMI id = wpf.subscribeWPFPMI("WPFKeyBasedPartitionSample", "WPFKeyBasedPartition", 0, 1, 5, 60000) print id # unsubscribe WPF PMI wpf.unsubscribeWPFPMI(id)