Java Code Examples for javax.management.remote.JMXServiceURL

The following are top voted examples for showing how to use javax.management.remote.JMXServiceURL. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Byter   File: JmxConnectionHelper.java   View source code 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example 2
Project: SuitAgent   File: JMXConnection.java   View source code 6 votes vote down vote up
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;
}
 
Example 3
Project: eZooKeeper   File: ZooKeeperServerNewWizard.java   View source code 6 votes vote down vote up
@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;
}
 
Example 4
Project: csap-core   File: TestRawJmx.java   View source code 6 votes vote down vote up
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 );
		} 
	}
 
Example 5
Project: jdk8u-jdk   File: RMIConnectorLogAttributesTest.java   View source code 6 votes vote down vote up
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;
}
 
Example 6
Project: OpenJSharp   File: RMIConnector.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 7
Project: OperatieBRP   File: JMXAgent.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 8
Project: openjdk-jdk10   File: ProviderTest.java   View source code 6 votes vote down vote up
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());
}
 
Example 9
Project: openjdk-jdk10   File: ListenerScaleTest.java   View source code 6 votes vote down vote up
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();
    }
}
 
Example 10
Project: jdk8u-jdk   File: RMIConnector.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 11
Project: jdk8u-jdk   File: ConnectorStopDeadlockTest.java   View source code 6 votes vote down vote up
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");
}
 
Example 12
Project: openjdk-jdk10   File: TestManager.java   View source code 6 votes vote down vote up
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();
}
 
Example 13
Project: jdk8u-jdk   File: IIOPURLTest.java   View source code 5 votes vote down vote up
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();
}
 
Example 14
Project: Pogamut3   File: DefaultPogamutPlatform.java   View source code 5 votes vote down vote up
/**
 * @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);
    }
}
 
Example 15
Project: Pogamut3   File: AbstractJMXAgentObserver.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 16
Project: SuitAgent   File: JMXConnectWithTimeout.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 17
Project: eZooKeeper   File: ZooKeeperServerNewWizardPage2.java   View source code 5 votes vote down vote up
public JMXServiceURL getServiceUrl() {
    Text jmxUrlText = (Text) getGridComposite().getControl(CONTROL_NAME_JMX_URL_TEXT);
    String jmxServiceUrlString = jmxUrlText.getText();

    try {
        return new JMXServiceURL(jmxServiceUrlString);
    }
    catch (MalformedURLException e) {
        // Validation should ensure that this should never happen
        return null;
    }
}
 
Example 18
Project: eZooKeeper   File: JmxConnection.java   View source code 5 votes vote down vote up
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) {
        }

    }
 
Example 19
Project: jdk8u-jdk   File: JMXConnectorServerProviderImpl.java   View source code 5 votes vote down vote up
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL url,
                                                Map<String,?> map,
                                                MBeanServer mbeanServer)
    throws IOException {
    final String protocol = url.getProtocol();
    called = true;
    System.out.println("JMXConnectorServerProviderImpl called");
    if(protocol.equals("rmi"))
        return new RMIConnectorServer(url, map, mbeanServer);
    if(protocol.equals("throw-provider-exception"))
        throw new JMXProviderException("I have been asked to throw");

    throw new IllegalArgumentException("UNKNOWN PROTOCOL");
}
 
Example 20
Project: eZooKeeper   File: JmxConnectionNewWizardPage1.java   View source code 5 votes vote down vote up
public JMXServiceURL getServiceUrl() {
    Text jmxUrlText = (Text) getGridComposite().getControl(CONTROL_NAME_JMX_URL_TEXT);
    String jmxServiceUrlString = jmxUrlText.getText();

    try {
        return new JMXServiceURL(jmxServiceUrlString);
    }
    catch (MalformedURLException e) {
        // Validation should ensure that this should never happen
        return null;
    }
}
 
Example 21
Project: openjdk-jdk10   File: ServerProvider.java   View source code 5 votes vote down vote up
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("rmi")) {
        throw new MalformedURLException("Protocol not rmi: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
Example 22
Project: fuck_zookeeper   File: JMXEnv.java   View source code 5 votes vote down vote up
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);
}
 
Example 23
Project: rocketmq-flink-plugin   File: HelloAgent.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws MalformedObjectNameException,
            NotCompliantMBeanException, InstanceAlreadyExistsException,
            MBeanRegistrationException, IOException {
        // 下面这种方式不能再JConsole中使用
//      MBeanServer server = MBeanServerFactory.createMBeanServer();
// 首先建立一个MBeanServer,MBeanServer用来管理我们的MBean,通常是通过MBeanServer来获取我们MBean的信息,间接
// 调用MBean的方法,然后生产我们的资源的一个对象。
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        String domainName = "MyMBean";

//为MBean(下面的new Hello())创建ObjectName实例
        ObjectName helloName = new ObjectName(domainName+":name=HelloWorld");
// 将new Hello()这个对象注册到MBeanServer上去
        mbs.registerMBean(new Hello(),helloName);

// Distributed Layer, 提供了一个HtmlAdaptor。支持Http访问协议,并且有一个不错的HTML界面,这里的Hello就是用这个作为远端管理的界面
// 事实上HtmlAdaptor是一个简单的HttpServer,它将Http请求转换为JMX Agent的请求
        ObjectName adapterName = new ObjectName(domainName+":name=htmladapter,port=8082");
        HtmlAdaptorServer adapter = new HtmlAdaptorServer();
        adapter.start();
        mbs.registerMBean(adapter,adapterName);

        int rmiPort = 1099;
        Registry registry = LocateRegistry.createRegistry(rmiPort);

        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/"+domainName);
        JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        jmxConnector.start();
    }
 
Example 24
Project: ditb   File: JMXListener.java   View source code 5 votes vote down vote up
public static JMXServiceURL buildJMXServiceURL(int rmiRegistryPort,
    int rmiConnectorPort) throws IOException {
  // Build jmxURL
  StringBuilder url = new StringBuilder();
  url.append("service:jmx:rmi://localhost:");
  url.append(rmiConnectorPort);
  url.append("/jndi/rmi://localhost:");
  url.append(rmiRegistryPort);
  url.append("/jmxrmi");

  return new JMXServiceURL(url.toString());

}
 
Example 25
Project: openjdk-jdk10   File: AuthorizationTest.java   View source code 5 votes vote down vote up
public void run(Map<String, Object> serverArgs, String clientArgs[]) {

        System.out.println("AuthorizationTest::run: Start") ;
        int errorCount = 0;

        try {
            // Initialise the server side
            JMXServiceURL urlToUse = createServerSide(serverArgs);

            // Run client side
            errorCount = runClientSide(clientArgs, urlToUse.toString());

            if ( errorCount == 0 ) {
                System.out.println("AuthorizationTest::run: Done without any error") ;
            } else {
                System.out.println("AuthorizationTest::run: Done with "
                        + errorCount
                        + " error(s)") ;
                throw new RuntimeException("errorCount = " + errorCount);
            }

            cs.stop();

        } catch(Exception e) {
            throw new RuntimeException(e);
        }

    }
 
Example 26
Project: OpenJSharp   File: ClientProvider.java   View source code 5 votes vote down vote up
public JMXConnector newJMXConnector(JMXServiceURL serviceURL,
                                    Map<String,?> environment)
        throws IOException {
    if (!serviceURL.getProtocol().equals("rmi")) {
        throw new MalformedURLException("Protocol not rmi: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnector(serviceURL, environment);
}
 
Example 27
Project: OpenJSharp   File: ServerProvider.java   View source code 5 votes vote down vote up
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("iiop")) {
        throw new MalformedURLException("Protocol not iiop: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
Example 28
Project: OpenJSharp   File: ClientProvider.java   View source code 5 votes vote down vote up
public JMXConnector newJMXConnector(JMXServiceURL serviceURL,
                                    Map<String,?> environment)
        throws IOException {
    if (!serviceURL.getProtocol().equals("iiop")) {
        throw new MalformedURLException("Protocol not iiop: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnector(serviceURL, environment);
}
 
Example 29
Project: OpenJSharp   File: RMIConnectorServer.java   View source code 5 votes vote down vote up
static boolean isIiopURL(JMXServiceURL directoryURL, boolean strict)
    throws MalformedURLException {
    String protocol = directoryURL.getProtocol();
    if (protocol.equals("rmi"))
        return false;
    else if (protocol.equals("iiop"))
        return true;
    else if (strict) {

        throw new MalformedURLException("URL must have protocol " +
                                        "\"rmi\" or \"iiop\": \"" +
                                        protocol + "\"");
    }
    return false;
}
 
Example 30
Project: OpenJSharp   File: RMIConnector.java   View source code 5 votes vote down vote up
private RMIConnector(RMIServer rmiServer, JMXServiceURL address,
        Map<String, ?> environment) {
    if (rmiServer == null && address == null) throw new
            IllegalArgumentException("rmiServer and jmxServiceURL both null");
    initTransients();

    this.rmiServer = rmiServer;
    this.jmxServiceURL = address;
    if (environment == null) {
        this.env = Collections.emptyMap();
    } else {
        EnvHelp.checkAttributes(environment);
        this.env = Collections.unmodifiableMap(environment);
    }
}
 
Example 31
Project: activemq-jmx-monitor   File: ActiveMQJmxMonitor.java   View source code 5 votes vote down vote up
public ActiveMQJmxMonitor(String jmxUrl, String brokerName, String[] credentials) throws IOException, MalformedObjectNameException {
	Map<String, String[]> env = new HashMap<>();
	if (credentials != null) {
		env.put(JMXConnector.CREDENTIALS, credentials);
	}
	JMXServiceURL jmxServiceUrl = new JMXServiceURL(jmxUrl);
	JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, env);

	mBeanConnection = jmxConnector.getMBeanServerConnection();
	initObjectNames(brokerName);
}
 
Example 32
Project: monarch   File: LauncherLifecycleCommandsDUnitTest.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 33
Project: monarch   File: AgentImpl.java   View source code 5 votes vote down vote up
/**
 * Returns the address (URL) on which the RMI connector server runs or <code>null</code> if the
 * RMI connector server has not been started. This method is used primarily for testing purposes.
 *
 * @see JMXConnectorServer#getAddress()
 */
public JMXServiceURL getRMIAddress() {
  if (this.rmiConnector != null) {
    return this.rmiConnector.getAddress();

  } else {
    return null;
  }
}
 
Example 34
Project: jdk8u-jdk   File: SecurityTest.java   View source code 5 votes vote down vote up
public void run(Map<String, Object> serverArgs, String clientArgs[]) {

        System.out.println("SecurityTest::run: Start") ;
        int errorCount = 0;

        try {
            // Initialise the server side
            JMXServiceURL urlToUse = createServerSide(serverArgs);

            // Run client side
            errorCount = runClientSide(clientArgs, urlToUse.toString());

            if ( errorCount == 0 ) {
                System.out.println("SecurityTest::run: Done without any error") ;
            } else {
                System.out.println(
                    "SecurityTest::run: Done with " + errorCount + " error(s)");
                throw new RuntimeException("errorCount = " + errorCount);
            }

            cs.stop();

        } catch(Exception e) {
            throw new RuntimeException(e);
        }

    }
 
Example 35
Project: monarch   File: MBeanProcessController.java   View source code 5 votes vote down vote up
/**
 * Connects to the JMX agent in the local process.
 * 
 * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
 *         in the process
 * @throws IOException if the JDK management agent cannot be found and loaded
 */
private void connect() throws ConnectionFailedException, IOException {
  try {
    final JMXServiceURL jmxUrl = getJMXServiceURL();
    this.jmxc = JMXConnectorFactory.connect(jmxUrl);
    this.server = this.jmxc.getMBeanServerConnection();
  } catch (AttachNotSupportedException e) {
    throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
  }
}
 
Example 36
Project: monarch   File: JMXMBeanDUnitTest.java   View source code 5 votes vote down vote up
private void connectAndValidateAsJmxClient(final int jmxPort, final String serverHostName,
    final boolean useSSL, final boolean useMulti) throws Exception {
  // JMX RMI

  Map<String, Object> environment = new HashMap();

  if (useSSL) {
    System.setProperty("javax.net.ssl.keyStore",
        useMulti ? getMultiKeyKeystore() : getSimpleSingleKeyKeystore());
    System.setProperty("javax.net.ssl.keyStoreType", "JKS");
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStore",
        useMulti ? getMultiKeyTruststore() : getSimpleSingleKeyKeystore());
    System.setProperty("javax.net.ssl.trustStoreType", "JKS");
    System.setProperty("javax.net.ssl.trustStorePassword", "password");
    environment.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
  }

  JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + serverHostName + ":" + jmxPort
      + "/jndi/rmi://" + serverHostName + ":" + jmxPort + "/jmxrmi");
  JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);


  try {
    MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName("GemFire:service=System,type=Distributed");

    // Get MBean proxy instance that will be used to make calls to registered MBean
    DistributedSystemMXBean distributedSystemMXBean =
        JMX.newMBeanProxy(mbeanServerConnection, mbeanName, DistributedSystemMXBean.class, true);

    assertEquals(1, distributedSystemMXBean.getMemberCount());
    assertEquals(1, distributedSystemMXBean.getLocatorCount());

  } finally {
    jmxConnector.close();
  }
}
 
Example 37
Project: OperatieBRP   File: AnonymousSslSocketFactory.java   View source code 5 votes vote down vote up
/**
 * Create a server socket.
 * @param serviceUrl jmx service url
 * @return server socket
 * @throws IOException if an I/O error occurs when creating the socket
 */
@Override
public ServerSocket createServerSocket(final JMXServiceURL serviceUrl) throws IOException {
    final InetAddress host = InetAddress.getByName(serviceUrl.getHost());
    final SSLServerSocket baseSslServerSocket = (SSLServerSocket) sslContext.getServerSocketFactory()
            .createServerSocket(serviceUrl.getPort(), BACKLOG, host);
    baseSslServerSocket.setEnabledProtocols(enabledProtocols);
    baseSslServerSocket.setEnabledCipherSuites(enabledCiphersuites);

    LOGGER.log(Level.FINE, "Created server socket");
    return baseSslServerSocket;
}
 
Example 38
Project: OperatieBRP   File: SystemSslSocketFactory.java   View source code 5 votes vote down vote up
/**
 * Create a client socket.
 * @param serviceUrl jmx service url
 * @return client socket
 * @throws IOException if an I/O error occurs when creating the socket
 */
@Override
public Socket createSocket(final JMXServiceURL serviceUrl) throws IOException {
    final SSLSocket baseSslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(serviceUrl.getHost(),
            serviceUrl.getPort());
    baseSslSocket.setKeepAlive(true);

    LOGGER.log(Level.FINE, "Created client socket");
    return baseSslSocket;
}
 
Example 39
Project: OperatieBRP   File: ClientConnection.java   View source code 5 votes vote down vote up
/**
 * Create a new client connection.
 * @param connector client connector (to send notifications)
 * @param serviceUrl jmx service url
 */
ClientConnection(final ClientConnector connector, final JMXSocketFactory socketFactory, final JMXServiceURL serviceUrl, final Object credentials,
                 final int requestTimeout) {
    this.connector = connector;
    this.socketFactory = socketFactory;
    this.serviceUrl = serviceUrl;
    this.credentials = credentials;
    this.requestTimeout = requestTimeout;
}
 
Example 40
Project: OperatieBRP   File: ClientProvider.java   View source code 5 votes vote down vote up
@Override
public JMXConnector newJMXConnector(final JMXServiceURL url, final Map<String, ?> environment)
        throws MalformedURLException {
    final String protocol = url.getProtocol();
    if (!SimpleJmx.PROTOCOL.equals(protocol)) {
        throw new MalformedURLException(
                "Invalid protocol '" + protocol + "' for provider " + this.getClass().getName());
    }

    return new ClientConnector(url, environment);
}