在Weblogic上访问Mbeans [英] access Mbeans on weblogic
问题描述
来自oracle的文档:
From the documentation of oracle :
域运行时MBean服务器:此MBean服务器还充当单个MBean服务器. 托管服务器上的MBean的访问点.
Domain Runtime MBean Server : This MBean server also acts as a single point of access for MBeans that reside on Managed Servers.
我想要做的就是利用这个事实来访问分散在多个受管服务器中的所有自定义mBean. 例如,假设我有两个节点server-1 server-2. 如何通过连接到管理员节点来访问两个server-1 server-2上的所有自定义mBean?
what i want to do is to use this fact to access all my custom mBeans scattered in several managed servers. for example assume that i have two nodes server-1 server-2 . how can i access all of the custom mBeans on both server-1 server-2 by connecting to the administrator node ?
我不想远程访问每个节点以返回结果,我想要一个入口点 通过这样做,我设法获得了服务器的名称,状态和其他信息.
i dont want to remotly access each node to return the result i want a single entry point i managed to get the names of the servers and the states and other information by doing this
JMXConnector connector;
ObjectName service;
MBeanServerConnection connection;
String protocol = "t3";
Integer portInteger = Integer.valueOf(<admin server port>);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.runtime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, "<serverName>", port,
jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, "weblogic");
h.put(Context.SECURITY_CREDENTIALS, "weblogicpass");
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection(); service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
ObjectName[] ons = (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");
int length = (int) ons.length;
for (int i = 0; i < length; i++) {
String name = (String) connection.getAttribute(ons[i],
"Name");
String state = (String) connection.getAttribute(ons[i],
"State");
String internalPort = (String) connection.getAttribute(ons[i],"ListenPort");
System.out.println("Server name: " + name + ". Server state: "
+ state);
但是我需要访问在每台服务器上创建的自定义Mbean,而不仅仅是访问信息
but i need to access the custom Mbeans created on each server and not only the information
推荐答案
也许我的问题不清楚,但是我找到了答案,现在我将在这里分享: 问题摘要:我需要通过从客户端应用程序连接到管理服务器来访问托管服务器中存在的自定义mBean.
maybe my question wasnt clear but i found an answer and i will share it here now : Question summary : i need to access custom mBeans exists in a managed server by connecting to the administration server from a client application.
答案: 为此,您需要将应用程序部署到管理员服务器(我尝试了远程操作,但没有用)
Answer : to do that you need to deploy your application to the administrator server (i tried remote but it didn't work )
您需要连接到DomainRuntimeServiceMBean,因为它提供了用于访问域中所有运行时和配置MBean的公共访问点.
you need to connect to the DomainRuntimeServiceMBean because it provide a common access point for navigating to all runtime and configuration MBeans in the domain .
搜索对象名称时,添加位置=
when searching for the Object name add Location=
下面是代码:
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.SECURITY_PRINCIPAL, "<userName>");
props.put(Context.SECURITY_CREDENTIALS, "<password>");
Context ctx = new InitialContext(props);
MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/domainRuntime");
ObjectName on =new ObjectName("com.<companyName>:Name=<Name>,Type=<Type>,Location=<managed_server_name>");
boolean boolresult=(Boolean)server.invoke(on, "<method_Name>",
new Object[]{"<ARG1>","<ARG2>","<ARG3>"}
,new String[]{"java.lang.String","java.lang.String","java.lang.String"});
out.print(boolresult);
这篇关于在Weblogic上访问Mbeans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!