Example usage for javax.management ObjectInstance getObjectName

List of usage examples for javax.management ObjectInstance getObjectName

Introduction

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

Prototype

public ObjectName getObjectName() 

Source Link

Document

Returns the object name part.

Usage

From source file:org.apache.synapse.commons.snmp.SNMPAgent.java

@Override
protected void registerManagedObjects() {
    log.info("Initializing Synapse SNMP MIB");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectInstance> instances = mbs.queryMBeans(null, null);

    try {//from  w w  w  . ja v  a2  s. c  o m
        for (ObjectInstance instance : instances) {
            ObjectName objectName = instance.getObjectName();
            if (objectName.getDomain().equals("org.apache.synapse")) {
                String oidString = SynapseMIBUtils.getOID(objectName);
                if (oidString == null) {
                    continue;
                }

                MBeanInfo info = mbs.getMBeanInfo(objectName);
                MBeanAttributeInfo[] attributes = info.getAttributes();
                List<String> attributeNames = new ArrayList<String>();
                List<String> mapAttributes = new ArrayList<String>();
                for (MBeanAttributeInfo attributeInfo : attributes) {
                    attributeNames.add(attributeInfo.getName());
                    if (Map.class.getName().equals(attributeInfo.getType())) {
                        mapAttributes.add(attributeInfo.getName());
                    }
                }
                Collections.sort(attributeNames);

                doRegister(attributeNames, mapAttributes, oidString, objectName);
            }
        }
    } catch (Exception e) {
        log.error("Error while initializing the SNMP MIB", e);
    }
}

From source file:org.jboss.web.tomcat.tc5.Tomcat5.java

public void stopService() throws Exception {

    String objectNameS = catalinaDomain + ":type=server";
    ObjectName objectName = new ObjectName(objectNameS);

    server.invoke(objectName, "stop", new Object[] {}, new String[] {});

    server.invoke(objectName, "destroy", new Object[] {}, new String[] {});

    server.unregisterMBean(objectName);/*  www  . j  ava2  s . co m*/

    MBeanServer server2 = server;

    // deregister with MainDeployer
    mainDeployer.removeDeployer(thisProxy);

    // Unregister any remaining jboss.web or Catalina MBeans
    ObjectName queryObjectName = new ObjectName(catalinaDomain + ":*");
    Iterator iterator = server2.queryMBeans(queryObjectName, null).iterator();
    while (iterator.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iterator.next();
        ObjectName toRemove = oi.getObjectName();
        // Exception: Don't unregister the service right now
        if (!"WebServer".equals(toRemove.getKeyProperty("service"))) {
            if (server2.isRegistered(toRemove)) {
                server2.unregisterMBean(toRemove);
            }
        }
    }
    queryObjectName = new ObjectName("Catalina:*");
    iterator = server2.queryMBeans(queryObjectName, null).iterator();
    while (iterator.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iterator.next();
        ObjectName name = oi.getObjectName();
        server2.unregisterMBean(name);
    }

}

From source file:org.jboss.web.tomcat.tc5.Tomcat5.java

/**
 * Start all the connectors//from   w  w  w .j  a v a  2s.  c  o  m
 * 
 * @throws JMException
 * @throws LifecycleException
 */
private void startAllConnectors() throws JMException, LifecycleException {
    /**
     * Not able to query the Catalina server for the services that it has
     * registered. A usuable solution is to query the MBean server for the
     * tomcat services.
     * http://www.jboss.com/index.html?module=bb&op=viewtopic&t=75353
     */
    ObjectName oname = new ObjectName("*:type=Service,*");
    Set services = server.queryMBeans(oname, null);
    Iterator iter = services.iterator();
    while (iter.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iter.next();
        ObjectName on = oi.getObjectName();
        //Ignore jboss.web:*
        if (this.catalinaDomain.equals(on.getDomain()))
            continue;
        String key = on.getKeyProperty("serviceName");
        if (key != null) {
            Connector[] connectors = (Connector[]) server.invoke(on, "findConnectors", new Object[0],
                    new String[0]);
            for (int n = 0; n < connectors.length; n++) {
                Lifecycle lc = (Lifecycle) connectors[n];
                lc.start();
            }
        }
    }
}

From source file:org.jboss.web.tomcat.tc5.Tomcat5.java

/**
 * Stop all the connectors/*from  w  ww.j a va2s .c  o m*/
 * 
 * @throws JMException
 * @throws LifecycleException
 */
private void stopAllConnectors() throws JMException, LifecycleException {
    ObjectName oname = new ObjectName("*:type=Service,*");
    Set services = server.queryMBeans(oname, null);
    Iterator iter = services.iterator();
    while (iter.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iter.next();
        ObjectName on = oi.getObjectName();
        //Ignore jboss.web:*
        if (this.catalinaDomain.equals(on.getDomain()))
            continue;
        String key = on.getKeyProperty("serviceName");
        if (key != null) {
            Connector[] connectors = (Connector[]) server.invoke(on, "findConnectors", new Object[0],
                    new String[0]);
            for (int n = 0; n < connectors.length; n++) {
                Lifecycle lc = (Lifecycle) connectors[n];
                lc.stop();
            }
        }
    }
}

From source file:org.jpos.q2.Q2.java

private void start(ObjectInstance instance) {
    try {/*w ww .  ja  v a 2 s .c  om*/
        factory.startQBean(this, instance.getObjectName());
    } catch (Exception e) {
        getLog().warn("start", e);
    }
}

From source file:org.mc4j.ems.impl.jmx.connection.DConnection.java

public EmsBean registerBean(String className, String objectName) {

    try {//www  .  java  2s  . c o m
        ObjectName objName = new ObjectName(objectName);
        ObjectInstance instance = connectionProvider.getMBeanServer().createMBean(className, objName);
        return mapBean(instance.getObjectName(), false);
    } catch (MBeanException e) {
        e.printStackTrace();
        throw new EmsException("Couldn't create MBean", e);
    } catch (OperationsException e) {
        throw new EmsException("Couldn't create MBean", e);
    } catch (ReflectionException e) {
        throw new EmsException("Couldn't create MBean", e);
    }
}

From source file:org.mc4j.ems.impl.jmx.connection.DConnection.java

public EmsBean registerBean(String className, String objectName, Object[] params, String[] signature) {

    try {//from w  w w.j a  va  2s. c o m
        ObjectName objName = new ObjectName(objectName);
        ObjectInstance instance = connectionProvider.getMBeanServer().createMBean(className, objName, params,
                signature);
        return mapBean(instance.getObjectName(), false);
    } catch (MBeanException e) {
        e.printStackTrace();
        throw new EmsException("Couldn't create MBean", e);
    } catch (OperationsException e) {
        throw new EmsException("Couldn't create MBean", e);
    } catch (ReflectionException e) {
        throw new EmsException("Couldn't create MBean", e);
    }
}

From source file:org.midonet.midolman.tools.MmStat.java

public void dumpMBeans(String jmxDomain, String filter, int count, int interval) {

    ObjectName on = null;//from  w w w  .j a  va2  s  . c o  m
    try {
        on = new ObjectName(jmxDomain + ":*");
    } catch (MalformedObjectNameException e) {
        System.err.println("Aborted: malformed domain " + jmxDomain);
        e.printStackTrace();
        System.exit(1);
    }
    java.util.Set<ObjectInstance> beans = null;
    try {
        beans = mbsc.queryMBeans(on, null);
    } catch (IOException e) {
        System.err.println("Aborted: querying Mbeans failed " + e);
        e.printStackTrace();
    }

    // Remember MBean instances to dump
    List<ObjectInstance> objectInstances = new ArrayList<>();
    for (ObjectInstance oi : beans) {
        if (filter != null) {
            String objectName = oi.getObjectName().toString();
            if (!objectName.contains(filter)) {
                continue;
            }
        }
        objectInstances.add(oi);
    }

    int attempt = 1;
    while (true) {
        // Header
        System.out.println("============================");
        System.out.println(String.format("Reading at %s (%s/%s)", new Date().toString(), attempt, count));
        System.out.println("============================");

        try {
            for (ObjectInstance oi : objectInstances) {
                on = oi.getObjectName();
                System.out.println("MBean: " + on.toString());
                MBeanInfo info = mbsc.getMBeanInfo(on);

                for (MBeanAttributeInfo attr : info.getAttributes()) {
                    System.out.print("\t" + attr.getName() + ": ");
                    System.out.println(mbsc.getAttribute(on, attr.getName()));
                }
            }
            if (attempt == count)
                System.exit(0);
            attempt++;
            //* Sleep "interval" seconds" */
            Thread.sleep(interval * 1000);
        } catch (IOException e) {
            System.err.println("Aborted: got IOException: " + e);
            e.printStackTrace();
            System.exit(1);
        } catch (JMException e) {
            System.err.println("Aborted: got JMException: " + e);
            e.printStackTrace();
            System.exit(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.nuxeo.ecm.core.management.jtajca.internal.DefaultMonitorComponent.java

protected static void unbind(ObjectInstance instance) {
    MBeanServer mbs = Framework.getLocalService(ServerLocator.class).lookupServer();
    try {/* ww  w  .j ava 2 s. co m*/
        mbs.unregisterMBean(instance.getObjectName());
    } catch (MBeanRegistrationException | InstanceNotFoundException e) {
        throw new UnsupportedOperationException("Cannot unbind " + instance, e);
    }
}

From source file:org.nuxeo.ecm.webapp.seam.NuxeoSeamFlusher.java

protected void invalidateWebSessions() throws IOException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name;// ww w.j  a  va2 s .  co  m
    try {
        name = new ObjectName("Catalina:type=Manager,context=/nuxeo,host=*");
    } catch (MalformedObjectNameException e) {
        throw new IOException(e);
    }
    for (ObjectInstance oi : mbs.queryMBeans(name, null)) {
        WebSessionFlusher flusher = JMX.newMBeanProxy(mbs, oi.getObjectName(), WebSessionFlusher.class);
        StringTokenizer tokenizer = new StringTokenizer(flusher.listSessionIds(), " ");
        while (tokenizer.hasMoreTokens()) {
            String id = tokenizer.nextToken();
            flusher.expireSession(id);
        }
    }
}