本文整理匯總了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);
}
}