Example usage for javax.management ObjectInstance getClassName

List of usage examples for javax.management ObjectInstance getClassName

Introduction

In this page you can find the example usage for javax.management ObjectInstance getClassName.

Prototype

public String getClassName() 

Source Link

Document

Returns the class part.

Usage

From source file:com.quinsoft.zeidon.jconsole.JConsoleEnvironment.java

void searchForObjectEngineBeans() {
    try {//from ww  w.  j av a 2s . c om
        proxies = new ArrayList<>();
        Set<ObjectName> objects = server.queryNames(null, null);
        for (ObjectName object : objects) {
            ObjectInstance oi = server.getObjectInstance(object);
            if (oi.getClassName().equals("com.quinsoft.zeidon.jmx.JmxObjectEngineMonitor")) {
                String name = object.getCanonicalName();
                JmxObjectEngineMonitorMBean proxy = JMX.newMBeanProxy(server, object,
                        JmxObjectEngineMonitorMBean.class, true);
                proxies.add(new OeProxy(name, proxy));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.taobao.metamorphosis.tools.shell.StopBrokerTool.java

@Override
public void doMain(String[] args) throws Exception {
    CommandLine commandLine = this.getCommandLine(args);

    String host = commandLine.getOptionValue("host", "127.0.0.1");
    int port = Integer.parseInt(commandLine.getOptionValue("port", "9999"));

    JMXClient jmxClient = JMXClient.getJMXClient(host, port);
    this.println("connected to " + jmxClient.getAddressAsString());
    ObjectInstance brokerInstance = jmxClient.queryMBeanForOne(METABROKER_NAME);

    if (brokerInstance != null) {
        jmxClient.invoke(brokerInstance.getObjectName(), "stop", new Object[0], new String[0]);
        jmxClient.close();/*  www.j ava  2s  .c  o m*/
        this.println("invoke " + brokerInstance.getClassName() + "#stop success");
    } else {
        this.println(" " + METABROKER_NAME);
    }
}

From source file:com.taobao.metamorphosis.tools.shell.SlaveStatus.java

@Override
public void doMain(String[] args) throws Exception {
    CommandLine commandLine = CommandLineUtils.parseCmdLine(args,
            new Options().addOption("host", true, "host").addOption("port", true, "port"));

    String host = commandLine.getOptionValue("host", "127.0.0.1");
    int port = Integer.parseInt(commandLine.getOptionValue("port", "9123"));

    JMXClient jmxClient = JMXClient.getJMXClient(host, port);

    this.println("connected to " + jmxClient.getAddressAsString());

    ObjectInstance metaConfigInstance = jmxClient.queryMBeanForOne(HANDLE_NANE);
    if (metaConfigInstance != null) {
        Object result = jmxClient.getAttribute(metaConfigInstance.getObjectName(), "Status");
        System.out.println(result);
        jmxClient.close();/*from  www  .jav a 2  s .  co m*/
        this.println("invoke " + metaConfigInstance.getClassName() + "#reload success");
    } else {
        this.println(" " + METACONFIG_NAME);
    }
}

From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java

public void handleNotification(Notification notification, Object handBack) {

    if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
        MBeanServerNotification regNot = (MBeanServerNotification) notification;
        MBeanServer srv = getMBeanServer();
        ObjectName name = regNot.getMBeanName();
        try {//from   w  w  w. ja  v  a 2  s .c  om
            ObjectInstance objIn = srv.getObjectInstance(name);
            String className = objIn.getClassName();
            // do not expose as UPN, UPNP devices exposed as MBeans ( class UPNPServiceMBean purpose )
            if (className.equals(UPNPServiceMBean.class.getName()))
                return;
            if (builder.select(name, className)) {
                MBeanInfo info = srv.getMBeanInfo(name);
                UPNPMBeanDevice dv = builder.buildUPNPMBean(getMBeanServer(), objIn, info);
                if (dv != null) {
                    dv.setBindAddress(sktAddress);
                    dv.start();
                    registeredMBeans.put(name.toString(), dv);
                }
            }
        } catch (Exception ex) {
            log.error("Error during UPNP Mbean device " + name.toString() + " creation", ex);
        }
    } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
        MBeanServerNotification regNot = (MBeanServerNotification) notification;
        String beanName = regNot.getMBeanName().toString();
        synchronized (STOP_PROCESS) {
            UPNPMBeanDevice dv = (UPNPMBeanDevice) registeredMBeans.get(beanName);
            if (dv != null) {
                try {
                    dv.stop();
                } catch (Exception ex) {
                    log.error("Error during UPNPMBean device stop", ex);
                }
                registeredMBeans.remove(beanName);
            }
        }
    }
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void doShutdown(String[] vals) throws Exception {
    StringBuilder buf = new StringBuilder("service:jmx:rmi://localhost/jndi/rmi://localhost:");
    String serviceName = vals[0];

    buf.append(vals[1]).append("/").append(serviceName);
    String serviceUrl = buf.toString();

    JMXServiceURL url = new JMXServiceURL(serviceUrl);
    JMXConnector jmxc = null;//from w  w  w  .  j a  v a 2s  .  com
    try {
        jmxc = JMXConnectorFactory.connect(url, null);

    } catch (Exception e) {
        throw new Exception("Unable to establish JMX connection at " + serviceUrl);
    }

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    Set<ObjectInstance> mBeansSet = mbsc.queryMBeans(new ObjectName(serviceName + ":*"), null);
    List<IServiceController> serviceProxies = new ArrayList<IServiceController>();
    Class serviceBusInterface = Class.forName(IServiceBusManager.class.getName());
    Class serviceControllerInterface = Class.forName(IServiceController.class.getName());

    for (ObjectInstance mBeanObject : mBeansSet) {
        ObjectName mbeanName = mBeanObject.getObjectName();
        Class mbeanClass = Class.forName(mBeanObject.getClassName());
        if (serviceBusInterface.isAssignableFrom(mbeanClass)) {
            IServiceBusManager requestConnector = JMX.newMBeanProxy(mbsc, mbeanName, IServiceBusManager.class,
                    true);
            System.out.print(mbeanName + " terminating....");
            requestConnector.disconnect();
            while (true) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ie) {

                }

                if (!requestConnector.isConnected()) {
                    break;
                }
            }
            System.out.println(" Done");
        } else if (serviceControllerInterface.isAssignableFrom(mbeanClass)) {
            // save off the service proxies to make sure we disconnect
            // all connectors before shutting down the service itself
            IServiceController mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, IServiceController.class, true);
            serviceProxies.add(mbeanProxy);
        }
    }

    for (IServiceController mbeanProxy : serviceProxies) {
        try {
            mbeanProxy.shutdown();
        } catch (UndeclaredThrowableException ex) {
        }
    }

    System.out.println("Service terminated");
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles all the distributed mbean creation part when a Manager is started
 *//*w w  w .j a v  a 2 s.co m*/
public void handleManagerStart() throws ManagementException {
    if (!isServiceInitialised("handleManagerStart")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();

    DistributedSystemBridge dsBridge = new DistributedSystemBridge(service);
    this.aggregator = new MBeanAggregator(dsBridge);
    // register the aggregator for Federation framework to use
    service.addProxyListener(aggregator);

    /*
     * get the local member mbean as it need to be provided to aggregator first
     */

    MemberMXBean localMember = service.getMemberMXBean();
    ObjectName memberObjectName = MBeanJMXAdapter
            .getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());

    FederationComponent addedComp = service.getLocalManager().getFedComponents().get(memberObjectName);

    service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp);

    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            continue;
        }
        Object object = registeredMBeans.get(objectName);
        ObjectInstance instance;
        try {
            instance = mbeanServer.getObjectInstance(objectName);
            String className = instance.getClassName();
            Class cls = ClassLoadUtil.classFromName(className);
            Type[] intfTyps = cls.getGenericInterfaces();

            FederationComponent newObj = service.getLocalManager().getFedComponents().get(objectName);

            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterCreateProxy(objectName, intfTyp, object, newObj);

            }
        } catch (InstanceNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean ");
            }
            throw new ManagementException(e);
        } catch (ClassNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean");
            }
            throw new ManagementException(e);
        }
    }
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles all the clean up activities when a Manager is stopped It clears the distributed mbeans
 * and underlying data structures//from  w w  w  . jav  a2 s .co  m
 */
public void handleManagerStop() throws ManagementException {
    if (!isServiceInitialised("handleManagerStop")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();

    ObjectName aggregatemMBeanPattern;
    try {
        aggregatemMBeanPattern = new ObjectName(ManagementConstants.AGGREGATE_MBEAN_PATTERN);
    } catch (MalformedObjectNameException | NullPointerException e1) {
        throw new ManagementException(e1);
    }

    MemberMXBean localMember = service.getMemberMXBean();

    ObjectName memberObjectName = MBeanJMXAdapter
            .getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());

    FederationComponent removedComp = service.getLocalManager().getFedComponents().get(memberObjectName);

    service.afterRemoveProxy(memberObjectName, MemberMXBean.class, localMember, removedComp);

    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            continue;
        }
        if (aggregatemMBeanPattern.apply(objectName)) {
            continue;
        }
        Object object = registeredMBeans.get(objectName);
        ObjectInstance instance;
        try {
            instance = mbeanServer.getObjectInstance(objectName);
            String className = instance.getClassName();
            Class cls = ClassLoadUtil.classFromName(className);
            Type[] intfTyps = cls.getGenericInterfaces();

            FederationComponent oldObj = service.getLocalManager().getFedComponents().get(objectName);

            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterRemoveProxy(objectName, intfTyp, object, oldObj);
            }
        } catch (InstanceNotFoundException | ClassNotFoundException e) {
            logger.warn("Failed to invoke aggregator for {} with exception {}", objectName, e.getMessage(), e);
        }
    }
    service.removeProxyListener(this.aggregator);
    this.aggregator = null;
}

From source file:org.apache.hadoop.hbase.TestStochasticBalancerJmxMetrics.java

/**
 * Read the attributes from Hadoop->HBase->Master->Balancer in JMX
 * @throws IOException //  w  w w  .ja v a2s . c  o m
 */
private Set<String> readJmxMetrics() throws IOException {
    JMXConnector connector = null;
    ObjectName target = null;
    MBeanServerConnection mb = null;
    try {
        connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
        mb = connector.getMBeanServerConnection();

        Hashtable<String, String> pairs = new Hashtable<>();
        pairs.put("service", "HBase");
        pairs.put("name", "Master");
        pairs.put("sub", "Balancer");
        target = new ObjectName("Hadoop", pairs);
        MBeanInfo beanInfo = mb.getMBeanInfo(target);

        Set<String> existingAttrs = new HashSet<String>();
        for (MBeanAttributeInfo attrInfo : beanInfo.getAttributes()) {
            existingAttrs.add(attrInfo.getName());
        }
        return existingAttrs;
    } catch (Exception e) {
        LOG.warn("Failed to get bean!!! " + target, e);
        if (mb != null) {
            Set<ObjectInstance> instances = mb.queryMBeans(null, null);
            Iterator<ObjectInstance> iterator = instances.iterator();
            System.out.println("MBean Found:");
            while (iterator.hasNext()) {
                ObjectInstance instance = iterator.next();
                System.out.println("Class Name: " + instance.getClassName());
                System.out.println("Object Name: " + instance.getObjectName());
            }
        }
    } finally {
        if (connector != null) {
            try {
                connector.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:org.apache.helix.tools.JmxDumper.java

void init() throws Exception {
    try {/*from   w w w  .  j a v a2  s  .com*/
        Set<ObjectInstance> existingInstances = _mbeanServer.queryMBeans(new ObjectName(_namePattern), null);
        _logger.info("Total " + existingInstances.size() + " mbeans matched " + _namePattern);
        for (ObjectInstance instance : existingInstances) {
            if (instance.getClassName().equals(_beanClassName)) {
                _mbeanNames.put(instance.getObjectName(), instance.getObjectName());
                _logger.info("Sampling " + instance.getObjectName());
            }
        }
        FileWriter fos = new FileWriter(_outputFileName);
        System.out.println(_outputFileName);
        _outputFile = new PrintWriter(fos);
    } catch (Exception e) {
        _logger.error("fail to get all existing mbeans in " + _domain, e);
        throw e;
    }
}

From source file:org.opennms.netmgt.vmmgr.InvokerTest.java

private static String getObjectInstanceString(ObjectInstance objectInstance) {
    return new ToStringBuilder(objectInstance).append("class", objectInstance.getClassName())
            .append("object", objectInstance.getObjectName()).toString();
}