Package org.cafesip.jiplet.standalone

Source Code of org.cafesip.jiplet.standalone.JipletMgmtAgent

/*
* Created on Dec 5, 2004
*
* Copyright 2005 CafeSip.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.cafesip.jiplet.standalone;

import java.net.InetAddress;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;

import org.cafesip.jiplet.JipletLogger;

/**
* @author amit
*/
public class JipletMgmtAgent
{

    private MBeanServer agent;

    /**
     * 
     */
    public JipletMgmtAgent() throws Exception
    {
        super();
        agent = MBeanServerFactory.createMBeanServer("Jiplet JMX Agent");

        int rmi_port = 1099;       
        String param =   System.getProperty("jiplet.jndi.port");
        if (param != null)
        {
            rmi_port = Integer.parseInt(param);
        }
       
        initRmiAdaptor(rmi_port);
    }

    private void initRmiAdaptor(int rmiPort) throws Exception
    {
        String host = InetAddress.getLocalHost().getHostAddress();
           
        //      The address of the connector server
        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://" + host
                + "/jndi/rmi://" + host + ":" + rmiPort + "/jipletagent");
       
        //         Create the JMXCconnectorServer
        JMXConnectorServer connector = JMXConnectorServerFactory
                .newJMXConnectorServer(address, null, agent);

        //         Start the JMXConnectorServer
        connector.start();

        JipletLogger
                .info("RMI MBean server started at " + host + ":" + rmiPort);
    }

    /**
     * @return Returns the agent.
     */
    public MBeanServer getAgent()
    {
        return agent;
    }
}
TOP

Related Classes of org.cafesip.jiplet.standalone.JipletMgmtAgent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.