Created
August 23, 2012 18:40
-
-
Save eevans/3440075 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.apache.cassandra.tools; | |
| import java.io.IOException; | |
| import java.util.Arrays; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import javax.management.JMX; | |
| import javax.management.MBeanServerConnection; | |
| import javax.management.MalformedObjectNameException; | |
| 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 Topology | |
| { | |
| private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi"; | |
| private static final String ssObjName = "org.apache.cassandra.db:type=StorageService"; | |
| private static final int defaultPort = 7199; | |
| final String host; | |
| final int port; | |
| private JMXConnector jmxc; | |
| private MBeanServerConnection mbeanServerConn; | |
| private StorageServiceMBean ssProxy; | |
| public Topology(String host) throws IOException | |
| { | |
| this(host, defaultPort); | |
| } | |
| public Topology(String host, int port) throws IOException | |
| { | |
| this.host = host; | |
| this.port = port; | |
| connect(); | |
| } | |
| /** | |
| * Create a connection to the JMX agent and setup the M[X]Bean proxies. | |
| * | |
| * @throws IOException on connection failures | |
| */ | |
| private void connect() throws IOException | |
| { | |
| JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port)); | |
| Map<String,Object> env = new HashMap<String,Object>(); | |
| jmxc = JMXConnectorFactory.connect(jmxUrl, env); | |
| mbeanServerConn = jmxc.getMBeanServerConnection(); | |
| try | |
| { | |
| ObjectName name = new ObjectName(ssObjName); | |
| ssProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageServiceMBean.class); | |
| } catch (MalformedObjectNameException e) | |
| { | |
| throw new RuntimeException( | |
| "Invalid ObjectName? Please report this as a bug.", e); | |
| } | |
| } | |
| public static void main(String[] args) throws Exception | |
| { | |
| //args = new String[]{"26827489534178531658985394796824233139"}; | |
| args = new String[]{"41929325298747031914175438363534668486"}; | |
| new Topology("localhost", 7300).ssProxy.relocate(Arrays.asList(args)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment