在 weblogic 上访问 Mbean

发布于 2024-12-26 07:48:21 字数 1976 浏览 3 评论 0原文

来自 oracle 的文档:

Domain Runtime MBean Server:此 MBean 服务器也充当单个 驻留在托管服务器上的 MBean 的访问点。

我想要做的是利用这个事实来访问分散在多个托管服务器中的所有自定义 mBean。 例如假设我有两个节点 server-1 server-2 。 如何通过连接到管理员节点来访问 server-1 server-2 上的所有自定义 mBean?

我不想远程访问每个节点以返回结果我想要一个入口点 我通过这样做设法获取服务器的名称、状态和其他信息

    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,而不仅仅是信息

From the documentation of oracle :

Domain Runtime MBean Server : This MBean server also acts as a single
point of access for MBeans that reside on Managed Servers.

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);

but i need to access the custom Mbeans created on each server and not only the information

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-柠檬树下少年和吉他 2025-01-02 07:48:21

也许我的问题不清楚,但我找到了答案,我现在将在这里分享:
问题摘要:我需要通过从客户端应用程序连接到管理服务器来访问托管服务器中存在的自定义 mBean。

回答 :
为此,您需要将应用程序部署到管理员服务器(我尝试了远程,但没有成功),

您需要连接到 DomainRuntimeServiceMBean,因为它提供了一个公共访问点,用于导航到域中的所有运行时和配置 MBean。

搜索对象名称时添加 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);

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 )

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=

here is the code:

    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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文