本文整理汇总了Java中javax.management.remote.JMXConnectorFactory.connect方法的典型用法代码示例。如果您正苦于以下问题:Java JMXConnectorFactory.connect方法的具体用法?Java JMXConnectorFactory.connect怎么用?Java JMXConnectorFactory.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.remote.JMXConnectorFactory
的用法示例。
在下文中一共展示了JMXConnectorFactory.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JMXExecutor
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
/**
* Instantiates a new JMXExecutor targeting the VM indicated by the given host/port combination or a full JMX
* Service URL
*
* @param target a host/port combination on the format "host:port" or a full JMX Service URL of the target VM
*/
public JMXExecutor(String target) {
String urlStr;
if (target.matches("^\\w[\\w\\-]*(\\.[\\w\\-]+)*:\\d+$")) {
/* Matches "hostname:port" */
urlStr = String.format("service:jmx:rmi:///jndi/rmi://%s/jmxrmi", target);
} else if (target.startsWith("service:")) {
urlStr = target;
} else {
throw new IllegalArgumentException("Could not recognize target string: " + target);
}
try {
JMXServiceURL url = new JMXServiceURL(urlStr);
JMXConnector c = JMXConnectorFactory.connect(url, new HashMap<>());
mbs = c.getMBeanServerConnection();
} catch (IOException e) {
throw new CommandExecutorException("Could not initiate connection to target: " + target, e);
}
}
示例2: initMBeanServerConnection
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
private static MBeanServerConnection initMBeanServerConnection() {
try {
String ip = Config.getProperty("jmx_ip");
String port = Config.getProperty("jmx_port");
String jmxURL = "service:jmx:rmi:///jndi/rmi://" + ip + ":" + port + "/jmxrmi";
JMXServiceURL serviceURL = new JMXServiceURL(jmxURL);
Map map = new HashMap();
String[] credentials = Config.getProperty("credentials").split(",");
map.put("jmx.remote.credentials", credentials);
JMXConnector connector = JMXConnectorFactory.connect(serviceURL, map);
mbsconnector = connector.getMBeanServerConnection();
} catch (IOException e) {
logger.error("get connector error" + e);
}
return mbsconnector;
}
示例3: main
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
String host = "localhost"; host = "csseredapp-dev-03";
String port = "8356"; //port = "8356";
String mbeanName = "java.lang:type=Memory";
String attributeName = "HeapMemoryUsage";
JMXServiceURL jmxUrl = new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" );
// jmxUrl = new JMXServiceURL(
// "service:jmx:rmi://localhost/jndi/rmi://" + host + ":" + port + "/jmxrmi" );
logger.info("Target: " + jmxUrl ) ;
JMXConnector jmxConnection = JMXConnectorFactory.connect( jmxUrl );
logger.info("Got connections") ;
CompositeData resultData = (CompositeData) jmxConnection.getMBeanServerConnection()
.getAttribute( new ObjectName(mbeanName), attributeName) ;
logger.log(Level.INFO, "Got mbean: heapUsed: {0}", resultData.get( "used")) ;
Thread.sleep( 5000 );
} catch ( Exception ex ) {
logger.log( Level.SEVERE, "Failed connection", ex );
}
}
示例4: fetchKafkaMetrics
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
private static void fetchKafkaMetrics(String host, String jmxPort, String metric)
throws Exception {
Map<String, String[]> env = new HashMap<>();
JMXServiceURL address = new JMXServiceURL(
"service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address, env);
MBeanServerConnection mbs = connector.getMBeanServerConnection();
ObjectName name = ObjectName.getInstance(metric);
MBeanInfo beanInfo = mbs.getMBeanInfo(name);
for (MBeanAttributeInfo attributeInfo : beanInfo.getAttributes()) {
Object obj = mbs.getAttribute(name, attributeInfo.getName());
System.out.println(" attributeName = " + attributeInfo.getName() + " " + obj.toString());
}
}
示例5: connect
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
private static void connect(String pid, String address) throws Exception {
if (address == null) {
throw new RuntimeException("Local connector address for " +
pid + " is null");
}
System.out.println("Connect to process " + pid + " via: " + address);
JMXServiceURL url = new JMXServiceURL(address);
JMXConnector c = JMXConnectorFactory.connect(url);
MBeanServerConnection server = c.getMBeanServerConnection();
System.out.println("Connected.");
RuntimeMXBean rt = newPlatformMXBeanProxy(server,
RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
System.out.println(rt.getName());
// close the connection
c.close();
}
示例6: start
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
@Override
public int start() {
try {
this.mbscConnector = JMXConnectorFactory.connect(this.JMXConnectionURL);
this.mbsc = mbscConnector.getMBeanServerConnection();
return 1;
}
catch (Exception e) {
log.err(this,
"Worker[" + this.cName + "] Connect to JMXURL[" + this.JMXConnectionURL.toString() + "] FAIL:", e);
return -1;
}
}
示例7: getMBeanServerConnection
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
public MBeanServerConnection getMBeanServerConnection(String user,
String password) throws Exception {
HashMap<String,String[]> env = new HashMap<String,String[]>();
if (user != null) {
String[] credentials = new String[] {
user, password };
env.put("jmx.remote.credentials", credentials);
}
JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection();
Map<MBeanServerConnection,JMXConnector> conns = connections.get();
if (conns == null) {
conns = new HashMap<MBeanServerConnection,JMXConnector>();
connections.set(conns);
}
conns.put(jmxConn, jmxc);
return jmxConn;
}
示例8: connectService
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
void connectService(String JMXServiceURL) throws Exception {
int count = 0;
String error = "";
while (count++ < 3) {
try {
url = new JMXServiceURL(JMXServiceURL);
jmxc = JMXConnectorFactory.connect(url, null);
error = "";
break;
} catch (IOException e) {
error = e.getMessage();
HelperLogger.loggerFile.error(e);
HelperLogger.loggerStdOut.info("JMX connection error. \nRetrying after " + CliControl.WAIT_AFTER_ERROR + " seconds...");
CliControl.sleep(CliControl.WAIT_AFTER_ERROR);
}
}
if (!Objects.equals(error, "")) {
throw new Exception(error);
}
}
示例9: connect
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
/**
* Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}:
* to the specified JMX service, or to a local MBeanServer if no service URL specified.
* @param serviceUrl the JMX service URL to connect to (may be {@code null})
* @param environment the JMX environment for the connector (may be {@code null})
* @param agentId the local JMX MBeanServer's agent id (may be {@code null})
*/
public MBeanServerConnection connect(JMXServiceURL serviceUrl, Map<String, ?> environment, String agentId)
throws MBeanServerNotFoundException {
if (serviceUrl != null) {
if (logger.isDebugEnabled()) {
logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]");
}
try {
this.connector = JMXConnectorFactory.connect(serviceUrl, environment);
return this.connector.getMBeanServerConnection();
}
catch (IOException ex) {
throw new MBeanServerNotFoundException("Could not connect to remote MBeanServer [" + serviceUrl + "]", ex);
}
}
else {
logger.debug("Attempting to locate local MBeanServer");
return JmxUtils.locateMBeanServer(agentId);
}
}
示例10: getMBeanServerConnection
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
/**
* @return Connection to a remote MBeanServer
* @throws cz.cuni.amis.utils.exception.PogamutException
*/
public MBeanServerConnection getMBeanServerConnection() throws PogamutException {
// connect through RMI and get the proxy
try {
if (mbsc == null) {
JMXServiceURL url = getMBeanServerURL();
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
mbsc = jmxc.getMBeanServerConnection();
}
return mbsc;
} catch (IOException iOException) {
throw new PogamutException("IO exception occured while creating remote MBeanServer connector.",
iOException);
}
}
示例11: addJMXAgentFromAdress
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
/**
* Creates JMX wrapper for agent on specified adress and adds it to the list
* of all connected agents.
* @param serviceUrl URL of the JMX service where remote agent resides eg. service:jmx:rmi:///jndi/rmi://localhost:9999/server
* @param objectName name of the MBean representing agent eg. myDomain:name=MyAgent1
*/
protected void addJMXAgentFromAdress(String serviceUrl, ObjectName objectName) throws IOException {
JMXServiceURL url = new JMXServiceURL(serviceUrl);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
IAgent agent = JMX.newMXBeanProxy(mbsc, objectName, IAgent.class);
agents.add(agent);
}
示例12: setUp
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
public static void setUp() throws IOException {
MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
}
示例13: connect
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
public void connect() {
close();
// JMXServiceURL jmxUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + _HostPortString + "/jmxrmi");
JmxConnectionDescriptor descriptor = getDescriptor();
JMXServiceURL jmxUrl = descriptor.getJmxServiceUrl();
String userName = descriptor.getUserName();
String password = descriptor.getPassword();
Map<String, String[]> env = null;
if (userName != null) {
env = new HashMap<String, String[]>();
env.put(JMXConnector.CREDENTIALS, new String[] { userName, password });
}
try {
_JMXConnector = JMXConnectorFactory.connect(jmxUrl, env);
_MBeanServerConnection = _JMXConnector.getMBeanServerConnection();
_Connected = true;
addConnectionListener();
addMBeanServerDelegateListener();
// System.out.println("JMX connection opened");
fireConnectionStateChanged(null);
}
catch (IOException e) {
}
}
示例14: tryConnect
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
private static void tryConnect(int port, boolean shouldSucceed) throws Exception {
String jmxUrlStr =
String.format(
"service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi",
port);
JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
HashMap<String, ?> env = new HashMap<>();
boolean succeeded;
try {
System.err.println("Trying to connect to " + jmxUrlStr);
JMXConnector c = JMXConnectorFactory.connect(url, env);
System.err.println("Connected, getting MBeanServerConnection");
c.getMBeanServerConnection();
System.err.println("Success");
succeeded = true;
} catch(Exception ex) {
ex.printStackTrace(System.err);
succeeded = false;
}
if (succeeded && !shouldSucceed) {
throw new Exception("Could connect to agent, but should not have been possible");
}
if (!succeeded && shouldSucceed) {
throw new Exception("Could not connect to agent");
}
}
示例15: getMemberId
import javax.management.remote.JMXConnectorFactory; //导入方法依赖的package包/类
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort,
final String memberName) throws Exception {
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
"service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
assertNotNull(objectNames);
assertFalse(objectNames.isEmpty());
assertEquals(1, objectNames.size());
// final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
// memberName);
ObjectName objectName = objectNames.iterator().next();
// System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName,
// objectName);
return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
} finally {
IOUtils.close(connector);
}
}