Example usage for javax.management ObjectName ObjectName

List of usage examples for javax.management ObjectName ObjectName

Introduction

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

Prototype

public ObjectName(String name) throws MalformedObjectNameException 

Source Link

Document

Construct an object name from the given string.

Usage

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Cluster System and map them to
 * cluster vo//from   w w  w  .  j av  a2 s .  c om
 * 
 * @param mbeanName
 *          Cluster System MBean
 * @throws IOException
 * 
 */
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
    try {
        if (!this.isAddedNotiListner) {
            this.mbs.addNotificationListener(mbeanName, this, null, new Object());
            this.isAddedNotiListner = true;
        }

        if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) {
            // Reset to zero
            cluster.setServerCount(0);
            cluster.setTotalRegionCount(0);
        } else {
            String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_LISTCACHESERVER, null, null));
            cluster.setServerCount(serverCnt.length);
        }

        TabularData table = (TabularData) (this.mbs.invoke(mbeanName,
                PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null));

        Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
        cluster.getWanInformationObject().clear();
        for (CompositeData row : rows) {
            final Object key = row.get("key");
            final Object value = row.get("value");
            cluster.getWanInformationObject().put((String) key, (Boolean) value);
        }

        AttributeList attributeList = this.mbs.getAttributes(mbeanName,
                PulseConstants.CLUSTER_MBEAN_ATTRIBUTES);

        for (int i = 0; i < attributeList.size(); i++) {

            Attribute attribute = (Attribute) attributeList.get(i);

            if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT)) {
                cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS)) {
                cluster.setClientConnectionCount(
                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID)) {
                cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT)) {
                cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION)) {
                try {
                    cluster.setRunningFunctionCount(
                            getIntegerAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setRunningFunctionCount(0);
                    continue;
                }
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT)) {
                cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS)) {
                cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED)) {
                cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK)) {
                cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE)) {
                cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE)) {
                try {
                    cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setUsedHeapSize((long) 0);
                    continue;
                }
                cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT)) {
                cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT)) {
                cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE)) {
                try {
                    cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setTotalBytesOnDisk((long) 0);
                    continue;
                }
                cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) {
                cluster.setDiskWritesRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
                cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) {
                try {
                    cluster.setWritePerSec(getFloatAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setWritePerSec(0);
                    continue;
                }
                cluster.getWritePerSecTrend().add(cluster.getWritePerSec());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) {
                try {
                    cluster.setReadPerSec(getFloatAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setReadPerSec(0);
                    continue;
                }
                cluster.getReadPerSecTrend().add(cluster.getReadPerSec());

            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE)) {
                cluster.setQueriesPerSec(getFloatAttribute(attribute.getValue(), attribute.getName()));
                cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec());

            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) {
                cluster.setDiskReadsRate(getFloatAttribute(attribute.getValue(), attribute.getName()));
                cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate());
            } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES)) {
                cluster.setGarbageCollectionCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount());

            }

            // For GemFireXD or GemFire
            if (PulseConstants.PRODUCT_NAME_GEMFIREXD
                    .equalsIgnoreCase(PulseController.getPulseProductSupport())) {
                // For GemFireXD
                // Do nothing
            } else {
                // For GemFire
                if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT)) {
                    cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                }
            }

        }

        // GEMFIREXD attributes
        if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) {

            try { // get GemFireXD cluster mbean

                ObjectName sfMemberMbeansObjectName = new ObjectName(PulseConstants.OBJECT_NAME_SF_CLUSTER);

                Set<ObjectName> sfCluserMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null);

                for (ObjectName sfCluserMBean : sfCluserMBeans) {

                    AttributeList attrList = this.mbs.getAttributes(sfCluserMBean,
                            PulseConstants.SF_CLUSTER_MBEAN_ATTRIBUTES);

                    for (int i = 0; i < attrList.size(); i++) {

                        Attribute attribute = (Attribute) attrList.get(i);

                        if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_PROCEDURECALLSINPROGRESS)) {
                            try {
                                cluster.setRunningFunctionCount(
                                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
                            } catch (Exception e) {
                                cluster.setRunningFunctionCount(0);
                                continue;
                            }
                        } else if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) {
                            // set number of cluster's clients
                            CompositeData nscConnStats = (CompositeData) attribute.getValue();

                            cluster.setClientConnectionCount(getLongAttribute(
                                    nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN),
                                    PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN));
                        }
                    }
                    break;
                }

            } catch (MalformedObjectNameException e) {
                LOGGER.warning(e);
            } catch (NullPointerException e) {
                LOGGER.warning(e);
            }

        }

    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create an <code>ObjectName</code> for this
 * <code>ContextResource</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param resource The ContextResource to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 *//*from   w  ww. j  a v  a2  s .  c o  m*/
public static ObjectName createObjectName(String domain, ContextResource resource)
        throws MalformedObjectNameException {

    ObjectName name = null;
    String encodedResourceName = encodeStr(resource.getName());
    Object container = resource.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType()
                + ",name=" + encodedResourceName);
    } else if (container instanceof Context) {
        String path = ((Context) container).getPath();
        if (path.length() < 1)
            path = "/";
        Host host = (Host) ((Context) container).getParent();
        Engine engine = (Engine) host.getParent();
        Service service = engine.getService();
        name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Context,path=" + path + ",host="
                + host.getName() + ",service=" + service.getName() + ",class=" + resource.getType() + ",name="
                + encodedResourceName);
    } else if (container instanceof DefaultContext) {
        container = ((DefaultContext) container).getParent();
        if (container instanceof Host) {
            Host host = (Host) container;
            Service service = ((Engine) host.getParent()).getService();
            name = new ObjectName(domain + ":type=Resource" + ",resourcetype=HostDefaultContext,host="
                    + host.getName() + ",service=" + service.getName() + ",class=" + resource.getType()
                    + ",name=" + encodedResourceName);
        } else if (container instanceof Engine) {
            Engine engine = (Engine) container;
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Resource" + ",resourcetype=ServiceDefaultContext,service="
                    + service.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName);
        }
    }

    return (name);

}

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

/**
 * function used to get attribute values of Cluster System and map them to
 * cluster vo//from www .  j a v a2 s  .c o  m
 *
 * @param mbeanName
 *          Cluster System MBean
 * @throws IOException
 *
 */
private void updateClusterSystem(ObjectName mbeanName) throws IOException {
    try {
        if (!this.isAddedNotiListner) {
            this.mbs.addNotificationListener(mbeanName, this, null, new Object());
            this.isAddedNotiListner = true;
        }

        if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) {
            // Reset to zero
            cluster.setServerCount(0);
            cluster.setTotalRegionCount(0);
        } else {
            String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName,
                    PulseConstants.MBEAN_OPERATION_LISTSERVERS, null, null));
            cluster.setServerCount(serverCnt.length);
        }

        TabularData table = (TabularData) (this.mbs.invoke(mbeanName,
                PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null));

        Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
        cluster.getWanInformationObject().clear();
        for (CompositeData row : rows) {
            final Object key = row.get("key");
            final Object value = row.get("value");
            cluster.getWanInformationObject().put((String) key, (Boolean) value);
        }

        AttributeList attributeList = this.mbs.getAttributes(mbeanName,
                PulseConstants.CLUSTER_MBEAN_ATTRIBUTES);

        for (int i = 0; i < attributeList.size(); i++) {

            Attribute attribute = (Attribute) attributeList.get(i);
            String name = attribute.getName();
            switch (name) {
            case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
                cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS:
                cluster.setClientConnectionCount(
                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID:
                cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT:
                cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION:
                try {
                    cluster.setRunningFunctionCount(
                            getIntegerAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setRunningFunctionCount(0);
                    continue;
                }
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT:
                cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS:
                cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED:
                cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK:
                cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE:
                cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE:
                try {
                    cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setUsedHeapSize((long) 0);
                    continue;
                }
                cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT:
                cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT:
                cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE:
                try {
                    cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setTotalBytesOnDisk((long) 0);
                    continue;
                }
                cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
                cluster.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES:
                try {
                    cluster.setWritePerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setWritePerSec(0);
                    continue;
                }
                cluster.getWritePerSecTrend().add(cluster.getWritePerSec());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS:
                try {
                    cluster.setReadPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                } catch (Exception e) {
                    cluster.setReadPerSec(0);
                    continue;
                }
                cluster.getReadPerSecTrend().add(cluster.getReadPerSec());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE:
                cluster.setQueriesPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
                cluster.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
                cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES:
                long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_CLUSTER, "",
                        getLongAttribute(attribute.getValue(), attribute.getName()));
                cluster.setGarbageCollectionCount(trendVal);
                cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount());
                break;
            case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT:
                if (!PulseConstants.PRODUCT_NAME_SQLFIRE
                        .equalsIgnoreCase(PulseController.getPulseProductSupport())) {
                    // for Gemfire
                    cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
                }
                break;
            }
        }

        // SQLFIRE attributes
        if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) {

            try { // get sqlfire cluster mbean

                ObjectName sfMemberMbeansObjectName = new ObjectName(PulseConstants.OBJECT_NAME_SF_CLUSTER);

                Set<ObjectName> sfCluserMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null);

                for (ObjectName sfCluserMBean : sfCluserMBeans) {

                    AttributeList attrList = this.mbs.getAttributes(sfCluserMBean,
                            PulseConstants.SF_CLUSTER_MBEAN_ATTRIBUTES);

                    for (int i = 0; i < attrList.size(); i++) {

                        Attribute attribute = (Attribute) attrList.get(i);

                        if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_PROCEDURECALLSINPROGRESS)) {
                            try {
                                cluster.setRunningFunctionCount(
                                        getIntegerAttribute(attribute.getValue(), attribute.getName()));
                            } catch (Exception e) {
                                cluster.setRunningFunctionCount(0);
                                continue;
                            }
                        } else if (attribute.getName()
                                .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) {
                            // set number of cluster's clients
                            CompositeData nscConnStats = (CompositeData) attribute.getValue();

                            cluster.setClientConnectionCount(getLongAttribute(
                                    nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSACTIVE),
                                    PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSACTIVE));
                        }
                    }
                    break;
                }

            } catch (MalformedObjectNameException e) {
                LOGGER.warning(e);
            } catch (NullPointerException e) {
                LOGGER.warning(e);
            }

        }

    } catch (InstanceNotFoundException infe) {
        LOGGER.warning(infe);
    } catch (ReflectionException re) {
        LOGGER.warning(re);
    } catch (MBeanException anfe) {
        LOGGER.warning(anfe);
    }
}

From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java

public void setJMXMBeanAttributeValue(String mBeanName, String attributeName, Object value) {

    try {/*from w w  w.  j a  v  a 2s .  c  o  m*/
        MBeanServerConnection mBeanServerConnection = getJMXConnection();
        ObjectName mbeanName = new ObjectName(mBeanName);
        Attribute attr = new Attribute(attributeName, value);
        mBeanServerConnection.setAttribute(mbeanName, attr);

    } catch (Exception e) {
        throw new RuntimeException(JMX_RETRIEVAL_ERROR + mBeanName + ": " + attributeName, e);
    }
}

From source file:org.red5.server.stream.ClientBroadcastStream.java

protected void registerJMX() {
    if (registerJMX) {
        // register with jmx
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {//w ww  . ja  v  a 2s .c om
            ObjectName oName = new ObjectName(
                    String.format("org.red5.server:type=ClientBroadcastStream,scope=%s,publishedName=%s",
                            getScope().getName(), publishedName));
            mbs.registerMBean(new StandardMBean(this, ClientBroadcastStreamMXBean.class, true), oName);
        } catch (InstanceAlreadyExistsException e) {
            log.debug("Instance already registered", e);
        } catch (Exception e) {
            log.warn("Error on jmx registration", e);
        }
    }
}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new StandardHost.//  ww  w. j a v a  2s . c  om
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployXML Should we deploy Context XML config files property?
 * @param liveDeploy Should we live deploy?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name, String appBase, boolean autoDeploy,
        boolean deployXML, boolean liveDeploy, boolean unpackWARs) throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployXML(deployXML);
    host.setLiveDeploy(liveDeploy);
    host.setUnpackWARs(unpackWARs);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardHost");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), host);
    return (oname.toString());

}

From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java

private Object getJMXMBeanAttributeValue(String mBeanName, String attributeName) {

    try {//from  w ww.ja va 2  s .  c o  m
        MBeanServerConnection mBeanServerConnection = getJMXConnection();
        ObjectName mbeanName = new ObjectName(mBeanName);
        return mBeanServerConnection.getAttribute(mbeanName, attributeName);

    } catch (Exception e) {
        throw new RuntimeException(JMX_RETRIEVAL_ERROR + mBeanName + ": " + attributeName, e);
    }
}

From source file:org.red5.server.stream.ClientBroadcastStream.java

protected void unregisterJMX() {
    if (registerJMX) {
        if (StringUtils.isNotEmpty(publishedName) && !"false".equals(publishedName)) {
            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            try {
                ObjectName oName = new ObjectName(
                        String.format("org.red5.server:type=ClientBroadcastStream,scope=%s,publishedName=%s",
                                getScope().getName(), publishedName));
                mbs.unregisterMBean(oName);
            } catch (Exception e) {
                log.warn("Exception unregistering", e);
            }/*from  w  w w . j av  a 2s. co m*/
        }
    }
}

From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java

private Object invokeJMXMBeanOperation(String mBeanName, String operationName, Object[] params,
        String[] signature) {//from ww w  .ja  v a2  s .c  om

    try {
        MBeanServerConnection mBeanServerConnection = getJMXConnection();
        return mBeanServerConnection.invoke(new ObjectName(mBeanName), operationName, params, signature);

    } catch (Exception e) {
        throw new RuntimeException(JMX_INVOKE_ERROR + mBeanName + ": " + operationName + " with arguments : "
                + Arrays.toString(params), e);
    }
}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new StandardManager./*w  ww  .j av a  2  s.c o m*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardManager(String parent) throws Exception {

    // Create a new StandardManager instance
    StandardManager manager = new StandardManager();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    String type = pname.getKeyProperty("type");
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if ((type != null) && (type.equals("Context"))) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setManager(manager);
    } else if ((type != null) && (type.equals("DefaultContext"))) {
        String hostName = pname.getKeyProperty("host");
        DefaultContext defaultContext = null;
        if (hostName == null) {
            defaultContext = engine.getDefaultContext();
        } else {
            Host host = (Host) engine.findChild(hostName);
            defaultContext = host.getDefaultContext();
        }
        if (defaultContext != null) {
            manager.setDefaultContext(defaultContext);
            defaultContext.setManager(manager);
        }
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardManager");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), manager);
    return (oname.toString());

}