Accessing the remote trace controller
You can access the remote trace controller through out-of-the-box management tools, or through an application.
About this task
You use out-of-the-box management through a JMX-compliant management client, such as JConsole, which is part of Java™ Standard Edition, Version 6. Information on using JConsole for out-of-the-box management is at the following URL:
http://download.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html
In an application that accesses the remote trace controller, the remote trace controller is a managed bean (MBean). JMX manages resources through JMX agents. A JMX agent is an MBean server. Each MBean represents a resource. Every MBean has a name, which you define through an object of class javax.management.ObjectName. You use the ObjectName object to register and retrieve MBeans in the MBeanServer.
The MBean name has two parts: the domain and the key properties. For the ObjectName for the IBM® Data Server Driver for JDBC and SQLJ remote trace controller, the domain is com.ibm.db2.jcc, and the key properties are name=DB2TraceManager.
Procedure
An application that accesses the remote trace controller must include these steps:
Examples
Hashtable<String> env = new Hashtable<String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
try {
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Establish an RMI connection to an MBeanServer");
System.out.println ("-------------------------------------------------");
JMXServiceURL url =
new JMXServiceURL ("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect (url, env);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Processing MBean");
System.out.println ("-------------------------------------------------");
String objectNameString = "com.ibm.db2.jcc:name=DB2TraceManager";
ObjectName name = new ObjectName(objectNameString);
System.out.println ("ObjectName="+objectNameString);
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Print all attributes of the MBean");
System.out.println ("-------------------------------------------------");
System.out.println(
"TraceDirectory = "+mbsc.getAttribute (name, "TraceDirectory"));
System.out.println(
"TraceFile = "+mbsc.getAttribute (name, "TraceFile"));
System.out.println(
"TraceFileAppend = "+mbsc.getAttribute (name, "TraceFileAppend"));
System.out.println(
"TraceLevel = "+mbsc.getAttribute (name, "TraceLevel"));
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Invoke some operations on the MBean");
System.out.println ("-------------------------------------------------");
System.out.print ("Invoking suspendTrace()...");
mbsc.invoke (name, "suspendTrace", null , null);
System.out.println ("success");
System.out.print ("Invoking resumeTrace()...");
mbsc.invoke (name, "resumeTrace", null , null);
System.out.println ("success");
}
catch (Exception e) {
System.out.println ("failure");
e.printStackTrace ();
}
Hashtable<String> env = new Hashtable<String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
try {
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Establish an RMI connection to an MBeanServer");
System.out.println ("-------------------------------------------------");
JMXServiceURL url =
new JMXServiceURL ("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect (url, env);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Processing MBean");
System.out.println ("-------------------------------------------------");
String objectNameString = "com.ibm.db2.jcc:name=DB2TraceManager";
ObjectName name = new ObjectName(objectNameString);
System.out.println ("ObjectName="+objectNameString);
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Print all attributes of the MBean");
System.out.println ("-------------------------------------------------");
com.ibm.db2.jcc.mx.DB2TraceManagerMXBean mbeanProxy =
JMX.newMBeanProxy(mbsc, name,
com.ibm.db2.jcc.mx.DB2TraceManagerMXBean.class, true);
System.out.println ("TraceDirectory = "+mbeanProxy.getTraceDirectory ());
System.out.println ("TraceFile = "+mbeanProxy.getTraceFile ());
System.out.println ("TraceFileAppend = "+mbeanProxy.getTraceFileAppend ());
System.out.println ("TraceLevel = "+mbeanProxy.getTraceLevel ());
System.out.println ("");
System.out.println ("-------------------------------------------------");
System.out.println ("Invoke some operations on the MBean");
System.out.println ("-------------------------------------------------");
System.out.print ("Invoking suspendTrace()...");
mbeanProxy.suspendTrace();
System.out.println ("success");
System.out.print ("Invoking resumeTrace()...");
mbeanProxy.resumeTrace();
System.out.println ("success");
}
catch (Exception e) {
System.out.println ("failure");
e.printStackTrace ();
}