Hallo zusammen, ich habe ein Problem oder eine Frage in JAVA... ich benutze JMX um eine Connection zu einem Applikation Server herzustellen, auf welchem sich MBeans befinden, diese Beans möchte ich ansprechen können und die Informationen jedes einzelnen Beans ausgeben können... bis herhabe ich diesen Code:
Java
package JmxBrowser_Phil;
import javax.management.*;
import javax.management.remote.JMXServiceURL;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnector;
import javax.management.ObjectName;
import javax.management.MBeanServerConnection;
import javax.naming.Context;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.IOException;
import java.lang.Object;
/**
* Created by IntelliJ IDEA.
* User: pkanne
* Date: 14.07.2006
* Time: 14:06:46
* To change this template use File | Settings | File Templates.
*/
public class Connecter {
private JMXConnector myConnector; // Connector to the JMX server. Used to cleanly close the connection.
private MBeanServerConnection myConnection; // The actual established connection. Should be closed before shutdown
private Connecter myParent; // Parent of this Node
private String myName; // Descriptive name of this Node. Passed by parent
private ObjectName myObjectName; // Object name of this Node. Passed by parent
private boolean myNodeIsExpanded; // TRUE after data of this Node has been read from JMX server
private ArrayList<Connecter> myChildreen; // Children of this Node
/**
* Defatul Constructor. Initializes Hierarchy independend attributes
*/
public Connecter() {
myNodeIsExpanded = false;
myChildreen = new ArrayList<Connecter>();
}
/**
* Establishs the connection to the remove JMX server.
*/
public void connect() {
try {
// JMXServiceURL url = new JMXServiceURL("t3", "chzrhs9a034", 8001, "/jndi/weblogic.management.mbeanservers.runtime");
JMXServiceURL url = new JMXServiceURL("t3", "chzrhs9a034", 8001, "/jndi/weblogic.management.mbeanservers.runtime");
Map<String, String> env = new HashMap<String, String>();
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
env.put(Context.SECURITY_CREDENTIALS, "xge0x7D3");
env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
myConnector = JMXConnectorFactory.connect(url, env);
myConnection = myConnector.getMBeanServerConnection();
myObjectName = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
// myObjectName = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
myName = (String) myConnection.getAttribute(myObjectName, "ServerName");
System.out.println("Connection worked!");
System.out.println("List:" + myObjectName.getKeyPropertyList());
System.out.println("List2:" + myObjectName.getKeyPropertyListString());
System.out.println("List3:" + myObjectName.hashCode());
System.out.println("GetClass:" + myConnection.getClass());
System.out.println("MBeanCount:" + myConnection.getMBeanCount());
} catch(Exception e) {
System.out.println("this.abort(e);");
}
}
/**
* Cleanly closes connection to JMX server
*/
public void disconnect() {
try {
if (myConnector != null) myConnector.close();
} catch (IOException e) {
System.out.println("Shit happens!!");
}
}
}
Alles anzeigen