cassandra getNaturalEndpoints JMX client

本文介绍了如何通过RMI(Remote Method Invocation)技术实现远程调用Apache Cassandra集群中的StorageServiceMBean接口,具体包括创建JMX RMI连接器、连接MBean Server以及调用getNaturalEndpoints方法来获取指定表和列族的自然端点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.net.InetAddress;
import java.util.List;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import org.apache.cassandra.service.StorageServiceMBean;

public class RmiClient {
private JMXServiceURL jmxUrl;
private JMXConnector connector;
private MBeanServerConnection mBeanServerconnection;

public RmiClient() throws Exception {
createJMXRmiConnector();
createMBeanServerConnection();
}

public static void main(String[] args) throws Exception {
String sStr = "testbucket000000011/obj000004672";
new RmiClient().test(sStr);
String addM = ComputeMD5.MD5Encode(sStr);
System.out.println("key=> " + sStr + " token=> " + addM);

}

private void createJMXRmiConnector() throws Exception {
// 1.The JMXConnectorServer protocol
String serverProtocol = "rmi";

// 2.The RMI server's host
// this is actually ignored by JSR 160
// String serverHost = "localhost";
String serverHost = "193.50.51.1:7199";

// 3.The host, port and path where the rmiregistry runs.
String namingHost = "193.50.51.1";
int namingPort = 1099;
String jndiPath = "/jmxconnector";

// 4. connector server url
// jmxUrl = new JMXServiceURL("service:jmx:" +
// serverProtocol + "://" + serverHost +
// "/jndi/rmi://" + namingHost + ":" +
// namingPort + jndiPath);

jmxUrl = new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://193.50.51.1:7199/jmxrmi");

// 5. 生成 JMXConnector,连接到url一端
// Connect a JSR 160 JMXConnector to the server side
connector = JMXConnectorFactory.connect(jmxUrl);

}

private void createMBeanServerConnection() throws Exception {
mBeanServerconnection = connector.getMBeanServerConnection();
}

public void test(String sStr) throws Exception {

ObjectName oName = new ObjectName(
"org.apache.cassandra.db:type=StorageService");
// 获取代理对象
Object proxy = MBeanServerInvocationHandler.newProxyInstance(
mBeanServerconnection, oName, StorageServiceMBean.class, true);

// 获取测试MBean,并执行它的(暴露出来被管理监控的)方法
StorageServiceMBean helloMBean = (StorageServiceMBean) proxy;

// public List getNaturalEndpoints(String table, String cf,
// String key);
// public List getNaturalEndpoints(String table, ByteBuffer
// key);

byte[] bytearray = sStr.getBytes();

List naturalEndpoints = helloMBean.getNaturalEndpoints(
"OBS", bytearray);
for (InetAddress add : naturalEndpoints) {
System.out.println(add.toString());
}
}

}[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23937368/viewspace-1054899/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23937368/viewspace-1054899/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值