当前位置: 首页>>代码示例>>Java>>正文


Java JMXServiceURL类代码示例

本文整理汇总了Java中javax.management.remote.JMXServiceURL的典型用法代码示例。如果您正苦于以下问题:Java JMXServiceURL类的具体用法?Java JMXServiceURL怎么用?Java JMXServiceURL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JMXServiceURL类属于javax.management.remote包,在下文中一共展示了JMXServiceURL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildJmxMPConnector

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
/**
 * Creates the jmxConnector with passed parameters.
 * @param host host address
 * @param port port of the host
 * @param user username (null possible)
 * @param pass password (null possible)
 * @return connected JMXConnector
 * @throws IOException IOException
 */
public static JMXConnector buildJmxMPConnector(final String host, final int port, final String user, final String pass) throws IOException {
    try {
        final JMXServiceURL serviceURL = new JMXServiceURL("jmxmp", host,port);
        if("null".equals(user) || "null".equals(pass) || user == null || pass == null){
            return JMXConnectorFactory.connect(serviceURL);
        }
        final Map<String, Object> environment = new HashMap<>();
        environment.put("jmx.remote.credentials", new String[]{user,pass});
        environment.put(Context.SECURITY_PRINCIPAL, user);
        environment.put(Context.SECURITY_CREDENTIALS, pass);
        return JMXConnectorFactory.connect(serviceURL,environment);
    } catch (MalformedURLException e) {
        log.log(Level.WARNING, "Malformed ServiceURL in buildJmxConnector");
        return null;
    }
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:26,代码来源:JmxConnectionHelper.java

示例2: getJMXConnector

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
private JMXConnector getJMXConnector(JMXConnectUrlInfo jmxConnectUrlInfo) throws Exception {
    JMXServiceURL url = new JMXServiceURL(jmxConnectUrlInfo.getRemoteUrl());
    JMXConnector connector;
    if(jmxConnectUrlInfo.isAuthentication()){
        connector = JMXConnectWithTimeout.connectWithTimeout(url,jmxConnectUrlInfo.getJmxUser()
                ,jmxConnectUrlInfo.getJmxPassword(),10, TimeUnit.SECONDS);
    }else{
        connector = JMXConnectWithTimeout.connectWithTimeout(url,null,null,10, TimeUnit.SECONDS);
    }
    return connector;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:12,代码来源:JMXConnection.java

示例3: performFinish

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
@Override
public boolean performFinish() {

    String host = _Page1.getHost();
    int port = _Page1.getPort();

    _ServerDescriptor = new ZooKeeperServerDescriptor(host, port);

    if (_Page2.isJmxEnabled()) {
        JMXServiceURL jmxServiceUrl = _Page2.getServiceUrl();
        String userName = _Page2.getUserName();
        String password = _Page2.getPassword();

        // Generate a unique name
        String name = JMX_CONNECTION_NAME_PREFIX + UUID.randomUUID().toString();

        JmxConnectionDescriptor jmxConnectionDescriptor = new JmxConnectionDescriptor(name, jmxServiceUrl,
                userName, password);
        _ServerDescriptor.setJmxConnectionDescriptor(jmxConnectionDescriptor);
    }

    return true;
}
 
开发者ID:baloise,项目名称:eZooKeeper,代码行数:24,代码来源:ZooKeeperServerNewWizard.java

示例4: main

import javax.management.remote.JMXServiceURL; //导入依赖的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 );
		} 
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:31,代码来源:TestRawJmx.java

示例5: startServer

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
private JMXConnectorServer startServer(int rmiPort) throws Exception {
    System.out.println("DEBUG: Create RMI registry on port " + rmiPort);
    LocateRegistry.createRegistry(rmiPort);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    HashMap<String,Object> env = new HashMap<String,Object>();

    JMXServiceURL url =
            new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:" + rmiPort + "/jmxrmi");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);

    cs.start();
    System.out.println("DEBUG: Started the RMI connector server");
    return cs;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:RMIConnectorLogAttributesTest.java

示例6: findRMIServer

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
private RMIServer findRMIServer(JMXServiceURL directoryURL,
        Map<String, Object> environment)
        throws NamingException, IOException {
    final boolean isIiop = RMIConnectorServer.isIiopURL(directoryURL,true);
    if (isIiop) {
        // Make sure java.naming.corba.orb is in the Map.
        environment.put(EnvHelp.DEFAULT_ORB,resolveOrb(environment));
    }

    String path = directoryURL.getURLPath();
    int end = path.indexOf(';');
    if (end < 0) end = path.length();
    if (path.startsWith("/jndi/"))
        return findRMIServerJNDI(path.substring(6,end), environment, isIiop);
    else if (path.startsWith("/stub/"))
        return findRMIServerJRMP(path.substring(6,end), environment, isIiop);
    else if (path.startsWith("/ior/")) {
        if (!IIOPHelper.isAvailable())
            throw new IOException("iiop protocol not available");
        return findRMIServerIIOP(path.substring(5,end), environment, isIiop);
    } else {
        final String msg = "URL path must begin with /jndi/ or /stub/ " +
                "or /ior/: " + path;
        throw new MalformedURLException(msg);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:RMIConnector.java

示例7: createConnectorServer

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
/**
 * Maak een connector server instantie.
 *
 * @return connector server
 * @throws IOException bij fouten
 */
private JMXConnectorServer createConnectorServer() throws IOException {
    final Properties configuration = readConfiguration();
    final MBeanServer server = locateMBeanServer();

    final JMXServiceURL url = new JMXServiceURL(SimpleJmx.PROTOCOL,
            configuration.getProperty("jmx.host", DEFAULT_HOST), Integer.parseInt(configuration.getProperty("jmx.port", DEFAULT_PORT)));

    final Map<String,Object> environment = new HashMap<>();
    Properties authentication = new Properties();
    authentication.setProperty("admin", "admin");
    environment.put("jmx.remote.authenticator", new PropertiesAuthenticator(authentication));
    environment.put("jmx.remote.accesscontroller", new AllAccessController());

    return JMXConnectorServerFactory.newJMXConnectorServer(url, environment, server);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:22,代码来源:JMXAgent.java

示例8: dotest

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ProviderTest.java

示例9: main

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if (Platform.isDebugBuild()) {
        System.out.println("Running on a debug build. Performance test not applicable. Skipping.");
        return;
    }
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    Sender sender = new Sender();
    mbs.registerMBean(sender, testObjectName);
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    try {
        test(mbs, cs, cc);
    } finally {
        cc.close();
        cs.stop();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ListenerScaleTest.java

示例10: main

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    RMIJRMPServerImplSub impl = new RMIJRMPServerImplSub();

    System.out.println("Creating connectorServer");
    connectorServer = new RMIConnectorServer(url, null, impl, mbs);
    System.out.println("Starting connectorServer");
    connectorServer.start();
    System.out.println("Making client");
    RMIConnection cc = impl.newClient(null);
    System.out.println("Closing client");
    cc.close();
    if (connectorServer.isActive()) {
        System.out.println("Stopping connectorServer");
        connectorServer.stop();
    }
    if (failure == null)
        System.out.println("TEST PASSED, no deadlock");
    else
        System.out.println("TEST FAILED");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:ConnectorStopDeadlockTest.java

示例11: connect

import javax.management.remote.JMXServiceURL; //导入依赖的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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestManager.java

示例12: main

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    JMXServiceURL inputAddr =
        new JMXServiceURL("service:jmx:iiop://");
    JMXConnectorServer s;
    try {
        s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
    } catch (java.net.MalformedURLException x) {
        try {
            Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
            throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
        } catch (ClassNotFoundException expected) { }
        System.out.println("IIOP protocol not supported, test skipped");
        return;
    }
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    mbs.registerMBean(s, new ObjectName("a:b=c"));
    s.start();
    JMXServiceURL outputAddr = s.getAddress();
    if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
        throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +
                                   outputAddr);
    }
    System.out.println("IIOP URL path looks OK: " + outputAddr);
    JMXConnector c = JMXConnectorFactory.connect(outputAddr);
    System.out.println("Successfully got default domain: " +
                       c.getMBeanServerConnection().getDefaultDomain());
    c.close();
    s.stop();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:IIOPURLTest.java

示例13: getMBeanServerConnection

import javax.management.remote.JMXServiceURL; //导入依赖的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);
    }
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:19,代码来源:DefaultPogamutPlatform.java

示例14: addJMXAgentFromAdress

import javax.management.remote.JMXServiceURL; //导入依赖的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);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:16,代码来源:AbstractJMXAgentObserver.java

示例15: connectWithTimeout

import javax.management.remote.JMXServiceURL; //导入依赖的package包/类
/**
 * JMX连接
 * @param url
 * JMX连接地址
 * @param jmxUser
 * JMX授权用户 null为无授权用户
 * @param jmxPassword
 * JMX授权密码 null为无授权密码
 * @param timeout
 * 超时时间
 * @param unit
 * 超时单位
 * @return
 * @throws IOException
 */
public static JMXConnector connectWithTimeout( final JMXServiceURL url,String jmxUser,String jmxPassword, long timeout, TimeUnit unit) throws Exception {
    final BlockingQueue<Object> blockingQueue = new ArrayBlockingQueue<>(1);
    ExecuteThreadUtil.execute(() -> {
        try {
            JMXConnector connector;
            if(jmxUser != null && jmxPassword != null){
                Map<String,Object> env = new HashMap<>();
                String[] credentials = new String[] { jmxUser, jmxPassword };
                env.put(JMXConnector.CREDENTIALS, credentials);
                connector = JMXConnectorFactory.connect(url,env);
            }else{
                connector = JMXConnectorFactory.connect(url,null);
            }
            if (!blockingQueue.offer(connector))
                connector.close();
        } catch (Throwable t) {
            blockingQueue.offer(t);
        }
    });

    Object result = BlockingQueueUtil.getResult(blockingQueue,timeout,unit);
    blockingQueue.clear();


    if (result instanceof JMXConnector){
        return (JMXConnector) result;
    }else if (result == null){
        throw new SocketTimeoutException("Connect timed out: " + url);
    }else if(result instanceof Throwable){
        throw new IOException("JMX Connect Failed : " + url,((Throwable) result));
    }
    return null;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:49,代码来源:JMXConnectWithTimeout.java


注:本文中的javax.management.remote.JMXServiceURL类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。