Example usage for javax.management JMX newMBeanProxy

List of usage examples for javax.management JMX newMBeanProxy

Introduction

In this page you can find the example usage for javax.management JMX newMBeanProxy.

Prototype

public static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName,
        Class<T> interfaceClass) 

Source Link

Document

Make a proxy for a Standard MBean in a local or remote MBean Server.

If you have an MBean Server mbs containing an MBean with ObjectName name , and if the MBean's management interface is described by the Java interface MyMBean , you can construct a proxy for the MBean like this:

 MyMBean proxy = JMX.newMBeanProxy(mbs, name, MyMBean.class); 

Suppose, for example, MyMBean looks like this:

 public interface MyMBean { public String getSomeAttribute(); public void setSomeAttribute(String value); public void someOperation(String param1, int param2); } 

Then you can execute:

  • proxy.getSomeAttribute() which will result in a call to mbs.

    Usage

    From source file:org.apache.cassandra.tools.NodeProbe.java

    /**
     * Retrieve Proxy metrics//ww  w. jav  a2 s  .co  m
     * @param metricName CompletedTasks, PendingTasks, BytesCompacted or TotalCompactionsCompleted.
     */
    public Object getCompactionMetric(String metricName) {
        try {
            switch (metricName) {
            case "BytesCompacted":
                return JMX.newMBeanProxy(mbeanServerConn,
                        new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
                        JmxReporter.CounterMBean.class);
            case "CompletedTasks":
            case "PendingTasks":
                return JMX.newMBeanProxy(mbeanServerConn,
                        new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
                        JmxReporter.GaugeMBean.class).getValue();
            case "TotalCompactionsCompleted":
                return JMX.newMBeanProxy(mbeanServerConn,
                        new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
                        JmxReporter.MeterMBean.class);
            default:
                throw new RuntimeException("Unknown compaction metric.");
            }
        } catch (MalformedObjectNameException e) {
            throw new RuntimeException(e);
        }
    }
    

    From source file:org.apache.cassandra.tools.NodeProbe.java

    /**
     * Retrieve Proxy metrics/*from www  .  j  av  a 2  s  .  c om*/
     * @param metricName Exceptions, Load, TotalHints or TotalHintsInProgress.
     */
    public long getStorageMetric(String metricName) {
        try {
            return JMX.newMBeanProxy(mbeanServerConn,
                    new ObjectName("org.apache.cassandra.metrics:type=Storage,name=" + metricName),
                    JmxReporter.CounterMBean.class).getCount();
        } catch (MalformedObjectNameException e) {
            throw new RuntimeException(e);
        }
    }
    

    From source file:org.apache.cassandra.tools.NodeProbe.java

    private List<Entry<String, ColumnFamilyStoreMBean>> getCFSMBeans(MBeanServerConnection mbeanServerConn,
            String type) throws MalformedObjectNameException, IOException {
        ObjectName query = new ObjectName("org.apache.cassandra.db:type=" + type + ",*");
        Set<ObjectName> cfObjects = mbeanServerConn.queryNames(query, null);
        List<Entry<String, ColumnFamilyStoreMBean>> mbeans = new ArrayList<Entry<String, ColumnFamilyStoreMBean>>(
                cfObjects.size());/*from   w  ww  .j  a  v  a 2  s . co  m*/
        for (ObjectName n : cfObjects) {
            String keyspaceName = n.getKeyProperty("keyspace");
            ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, n, ColumnFamilyStoreMBean.class);
            mbeans.add(
                    new AbstractMap.SimpleImmutableEntry<String, ColumnFamilyStoreMBean>(keyspaceName, cfsProxy));
        }
        return mbeans;
    }
    

    From source file:org.apache.cassandra.tools.NodeProbe.java

    public Map.Entry<String, JMXEnabledThreadPoolExecutorMBean> next() {
        ObjectName objectName = resIter.next();
        String poolName = objectName.getKeyProperty("type");
        JMXEnabledThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(mbeanServerConn, objectName,
                JMXEnabledThreadPoolExecutorMBean.class);
        return new AbstractMap.SimpleImmutableEntry<String, JMXEnabledThreadPoolExecutorMBean>(poolName,
                threadPoolProxy);//from   ww  w  . j a  v a  2 s.c  om
    }
    

    From source file:org.apache.cassandra.tools.Shuffle.java

    public StorageServiceMBean getSSProxy(MBeanServerConnection mbeanConn) {
        StorageServiceMBean proxy = null;/*w w w. j  ava2 s.  c o  m*/
        try {
            ObjectName name = new ObjectName(ssObjName);
            proxy = JMX.newMBeanProxy(mbeanConn, name, StorageServiceMBean.class);
        } catch (MalformedObjectNameException e) {
            throw new RuntimeException(e);
        }
        return proxy;
    }
    

    From source file:org.apache.cassandra.tools.Shuffle.java

    public EndpointSnitchInfoMBean getEpSnitchProxy(MBeanServerConnection mbeanConn) {
        EndpointSnitchInfoMBean proxy = null;
        try {// ww  w .  ja v a 2  s.co m
            ObjectName name = new ObjectName(epSnitchObjName);
            proxy = JMX.newMBeanProxy(mbeanConn, name, EndpointSnitchInfoMBean.class);
        } catch (MalformedObjectNameException e) {
            throw new RuntimeException(e);
        }
        return proxy;
    }
    

    From source file:org.codice.ddf.catalog.download.action.ResourceDownloadActionProvider.java

    ResourceCacheServiceMBean createResourceCacheMBeanProxy() {
        try {/*from   ww w  . j  a  va2s .  c o m*/
            return JMX.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(),
                    new ObjectName(ResourceCacheServiceMBean.OBJECT_NAME), ResourceCacheServiceMBean.MBEAN_CLASS);
        } catch (MalformedObjectNameException e) {
            String message = String.format("Unable to create MBean proxy for [%s].",
                    ResourceCacheServiceMBean.class.getName());
            LOGGER.debug(message, e);
            throw new ResourceDownloadActionException(message, e);
        }
    }
    

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

    protected void invalidateWebSessions() throws IOException {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName name;/* www.  j  a v a 2  s . c  o  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);
            }
        }
    }
    

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

    protected Set<WebConnector> fetchConnectors() {
        Set<WebConnector> connectors = new HashSet<WebConnector>();
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName names;//from   w  ww .  jav a  2 s .  c o  m
        try {
            names = new ObjectName("Catalina:type=Connector,port=*,address=*");
        } catch (MalformedObjectNameException e) {
            log.error("Cannot query for tomcat connectors", e);
            return connectors;
        }
        Set<ObjectInstance> ois = mbs.queryMBeans(names, null);
        for (ObjectInstance oi : ois) {
            WebConnector connector = JMX.newMBeanProxy(mbs, oi.getObjectName(), WebConnector.class);
            connectors.add(connector);
        }
        return connectors;
    }
    

    From source file:org.nuxeo.jboss.jca.JBossJCADynamicConfigurator.java

    protected void configureRepository(String repoName) throws Exception {
    
        ServerLocator locator = Framework.getLocalService(ServerLocator.class);
    
        MBeanServer server = locator.lookupServer(DOMAIN);
    
        ObjectName name = new ObjectName(
                DOMAIN + ":name=NXRepository/" + repoName + ",service=ManagedConnectionPool");
    
        JBossManagedConnectionPoolMBean jca = JMX.newMBeanProxy(server, name,
                JBossManagedConnectionPoolMBean.class);
    
        String min = Framework.getProperty(PREFIX + repoName + MIN_POOL);
        String max = Framework.getProperty(PREFIX + repoName + MAX_POOL);
        String timeout = Framework.getProperty(PREFIX + repoName + TIMEOUT);
        String idle = Framework.getProperty(PREFIX + repoName + IDLE);
        String valid = Framework.getProperty(PREFIX + repoName + VALID);
    
        if (min != null) {
            jca.setMinSize(Integer.parseInt(min));
        }//ww  w.  jav  a 2  s. c o  m
        if (max != null) {
            jca.setMaxSize(Integer.parseInt(max));
        }
        if (timeout != null) {
            jca.setBlockingTimeoutMillis(Integer.parseInt(timeout));
        }
        if (idle != null) {
            jca.setIdleTimeoutMinutes(Integer.parseInt(idle));
        }
        if (valid != null) {
            jca.setBackGroundValidationMillis(Integer.parseInt(valid));
        }
    
        // restart pool so that configuration is taken into account
        jca.stop();
        jca.start();
    
    }