java - 如何访问weblogic服务器上的ehcache mbean

标签 java weblogic jmx ehcache

在我的weblogic服务器中部署了ehcache,我需要通过java编程从这个程序中获取ehcahe mbean,通过JMX我无法连接。我怎样才能获得那些自定义mbean?

我尝试通过 weblogic t3 协议(protocol)获取 mbean

public class Test
{

    private String hostName = "";
    private String port = "";
    private String userName = "";
    private String password = "";
    private String connectorURL = "service:jmx:rmi:///jndi/rmi://{0}:{1}/jmxrmi";
    private JMXConnector jmxc = null;
    public static void main(String []args) throws Exception
    {
        Test t = new Test();
        t.hostName = args[0];
        System.out.println(args[1]);
        t.port = args[1];
        t.userName = args[2];
        t.password = args[3];
        t.jmxc = t.initConnection(); 




        MBeanServerConnection mbsc = t.jmxc.getMBeanServerConnection();
        System.out.println(mbsc);
        Set<ObjectInstance>  st =mbsc.queryMBeans(new ObjectName("net.*:*"), null);
        System.out.println(st.toString());
        Iterator<ObjectInstance> it = st.iterator();

        while(it.hasNext())
        {
            System.out.println(it.next());
        }


        t.closeConnection();
    }


    private  JMXConnector initConnection() 
    {
        System.out.println("initiate connection");


        JMXServiceURL serviceURL = null;

        try 
        {
            String jndiroot = "/jndi/";
            String mserver = "weblogic.management.mbeanservers.domainruntime";

            int port1 = Integer.parseInt(port);
            serviceURL = new JMXServiceURL("t3", hostName, port1, jndiroot + mserver);

            Hashtable h = new Hashtable();
            h.put(Context.SECURITY_PRINCIPAL, userName);
            h.put(Context.SECURITY_CREDENTIALS, password);
            h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,  "weblogic.management.remote");

            long lngJmxClientWTO = 10000;

            h.put("jmx.remote.x.request.waiting.timeout", lngJmxClientWTO );



            return JMXConnectorFactory.connect(serviceURL, h);
        }
        catch (Exception e)
        {
             e.printStackTrace();
             return null;
        }

   }


  /**
    * This method closes client connection with server 
    * @throws IOException
    */
   public void closeConnection() 
   {

       if(jmxc != null)
       {
           try
           {
               jmxc.close();
           }
           catch (IOException e) {
               jmxc = null;
           }
       }
   }

最佳答案

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;

CacheManager manager = CacheManager.newInstance();
Ehcache cache = manager.getEhcache("Some cache name here..."); //<-- PLEASE EDIT THE CACHE NAME...

不知道你要的是不是这个......

一旦获得缓存,您就可以使用它,就像java map 一样。

<小时/>

您可以关注Ehcache documentation了解如何以编程方式获取远程缓存。本质上,您需要创建一个 configuration (or configuration file) CacheManager 可以访问它。

关于java - 如何访问weblogic服务器上的ehcache mbean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25523559/

相关文章:

java - 单击时取消选择 javafx ListView 上的项目

java - 处理测试继承的Testng

java - 即使类在编译时存在,也无法加载该类

java - Spring JMX - 导出键值对映射

java - 连接到远程 JMX 代理 ActiveMQ Artemis 时出错

java - 如何连接到另一个本地进程中的 mBeanServer?

Java boolean if问题

java - 通过字节码访问变量

docker - 找不到startNodeManager.sh

java - weblogic 12c 中的类大小写异常