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:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Remote Address Filter Valve.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 *//*  ww w .  j  a  v  a2s .c  o m*/
public String createRemoteAddrValve(String parent) throws Exception {

    // Create a new RemoteAddrValve instance
    RemoteAddrValve valve = new RemoteAddrValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

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

}

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

public boolean makeServerConnection(JMXConnector jmxConnector)
        throws IOException, MBeanException, AttributeNotFoundException, InstanceNotFoundException,
        ReflectionException, MalformedObjectNameException {

    MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
    Set<ObjectName> mbeans = mBeanServerConnection.queryNames(new ObjectName("CoUGAR:name=healthChecker,*"),
            null);/*ww  w. j  a v  a 2 s.  c o m*/
    if (!mbeans.isEmpty()) {
        mBeanServerConnection.getAttribute(mbeans.iterator().next(), "SystemInService");
        return true;
    }
    return false;
}

From source file:com.app.server.SARDeployer.java

@Override
public ObjectName getObjectName() {
    // TODO Auto-generated method stub
    try {//from www  .j a va 2 s.  co m
        return new ObjectName(OBJECT_NAME);
    } catch (Exception e) {
        log.error("Could not able to create object name " + OBJECT_NAME, e);
        // TODO Auto-generated catch block
        //e.printStackTrace();
    }
    return null;
}

From source file:catalina.mbeans.MBeanFactory.java

/**
* Create a new Remote Host Filter Valve.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*///  w  w  w .j ava 2  s  . co  m
public String createRemoteHostValve(String parent) throws Exception {

    // Create a new RemoteHostValve instance
    RemoteHostValve valve = new RemoteHostValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

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

}

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

private void setJMXMBeanAttribute(String mBeanName, String attributeName, Object newMbeanValue) {

    try {/* w  w  w. j  a va  2  s  .  c  o  m*/
        MBeanServerConnection mBeanServerConnection = getJMXConnection();
        ObjectName mbeanName = new ObjectName(mBeanName);
        Object currentAttributeValue = mBeanServerConnection.getAttribute(mbeanName, attributeName);
        Object reflectedValue = reflect.getRealProperty(currentAttributeValue.getClass(), newMbeanValue);
        Attribute attribute = new Attribute(attributeName, reflectedValue);
        mBeanServerConnection.setAttribute(mbeanName, attribute);
    } catch (Exception e) {
        throw new RuntimeException(JMX_SETTING_ERROR + mBeanName + ": " + attributeName, e);
    }
}

From source file:catalina.mbeans.MBeanUtils.java

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

    ObjectName name = null;
    if (connector instanceof HttpConnector) {
        HttpConnector httpConnector = (HttpConnector) connector;
        Service service = httpConnector.getService();
        String serviceName = null;
        if (service != null)
            serviceName = service.getName();
        name = new ObjectName(domain + ":type=Connector" + ",service=" + serviceName + ",port="
                + httpConnector.getPort() + ",address=" + httpConnector.getAddress());
        return (name);
    } else if (connector instanceof org.apache.catalina.connector.http10.HttpConnector) {
        org.apache.catalina.connector.http10.HttpConnector httpConnector = (org.apache.catalina.connector.http10.HttpConnector) connector;
        Service service = httpConnector.getService();
        String serviceName = null;
        if (service != null)
            serviceName = service.getName();
        name = new ObjectName(domain + ":type=Connector" + ",service=" + serviceName + ",port="
                + httpConnector.getPort() + ",address=" + httpConnector.getAddress());
        return (name);
    } else if ("org.apache.ajp.tomcat4.Ajp13Connector".equals(connector.getClass().getName())) {
        try {
            String address = (String) PropertyUtils.getSimpleProperty(connector, "address");
            Integer port = (Integer) PropertyUtils.getSimpleProperty(connector, "port");
            Service service = connector.getService();
            String serviceName = null;
            if (service != null)
                serviceName = service.getName();
            name = new ObjectName(domain + ":type=Connector" + ",service=" + serviceName + ",port=" + port
                    + ",address=" + address);
            return (name);
        } catch (Exception e) {
            throw new MalformedObjectNameException("Cannot create object name for " + connector + e);
        }
    } else if ("org.apache.coyote.tomcat4.CoyoteConnector".equals(connector.getClass().getName())) {
        try {
            String address = (String) PropertyUtils.getSimpleProperty(connector, "address");
            Integer port = (Integer) PropertyUtils.getSimpleProperty(connector, "port");
            Service service = connector.getService();
            String serviceName = null;
            if (service != null)
                serviceName = service.getName();
            name = new ObjectName(domain + ":type=Connector" + ",service=" + serviceName + ",port=" + port
                    + ",address=" + address);
            return (name);
        } catch (Exception e) {
            throw new MalformedObjectNameException("Cannot create object name for " + connector + e);
        }
    } else {
        throw new MalformedObjectNameException("Cannot create object name for " + connector);
    }

}

From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java

private void bounceConnections(BrokerVitalSigns broker, int number) throws Exception {
    if (number > 0) {
        ObjectName root = broker.getRoot();
        Hashtable<String, String> props = root.getKeyPropertyList();
        props.put("connector", "clientConnectors");
        props.put("connectorName", "*");
        String objectName = root.getDomain() + ":" + getOrderedProperties(props);

        /**/*from  w  w w.  j a v a 2 s . c o  m*/
         * not interested in StatisticsEnabled, just need a real attribute so we can get the root which we
         * can execute against
         */

        List<String> connectors = new ArrayList<>();
        J4pResponse<J4pReadRequest> response = broker.getClient()
                .execute(new J4pReadRequest(objectName, "StatisticsEnabled"));
        JSONObject value = response.getValue();
        for (Object key : value.keySet()) {
            connectors.add(key.toString());
        }

        List<String> targets = new ArrayList<>();
        for (String key : connectors) {
            ObjectName on = new ObjectName(key);
            Hashtable<String, String> p = on.getKeyPropertyList();
            p.put("connectionName", "*");
            p.put("connectionViewType", "clientId");
            String clientObjectName = root.getDomain() + ":" + getOrderedProperties(p);
            ObjectName on1 = new ObjectName(clientObjectName);
            J4pResponse<J4pReadRequest> response1 = broker.getClient().execute(new J4pReadRequest(on1, "Slow"));
            JSONObject value1 = response1.getValue();
            for (Object k : value1.keySet()) {
                targets.add(k.toString());
            }
        }

        int count = 0;
        for (String key : targets) {
            broker.getClient().execute(new J4pExecRequest(key, "stop"));
            LOG.info("Stopping Client " + key + " on broker " + broker.getBrokerIdentifier());
            if (++count >= number) {
                break;
            }
        }
    }

}

From source file:io.fabric8.cxf.endpoint.ManagedApi.java

public ObjectName getObjectName() throws JMException {
    String busId = bus.getId();/* w ww. j a  v a2s  .  c  o  m*/
    StringBuilder buffer = new StringBuilder();
    buffer.append(DOMAIN_NAME).append(':');
    buffer.append(ManagementConstants.BUS_ID_PROP).append('=').append(busId).append(',');
    buffer.append(ManagementConstants.TYPE_PROP).append('=').append("Bus.Service.Endpoint,");

    String serviceName = (String) endpoint.get(SERVICE_NAME);
    if (StringUtils.isEmpty(serviceName)) {
        serviceName = endpoint.getService().getName().toString();
    }
    serviceName = ObjectName.quote(serviceName);
    buffer.append(ManagementConstants.SERVICE_NAME_PROP).append('=').append(serviceName).append(',');

    String endpointName = (String) endpoint.get(ENDPOINT_NAME);
    if (StringUtils.isEmpty(endpointName)) {
        endpointName = endpoint.getEndpointInfo().getName().getLocalPart();
    }
    endpointName = ObjectName.quote(endpointName);
    buffer.append(ManagementConstants.PORT_NAME_PROP).append('=').append(endpointName).append(',');
    // Added the instance id to make the ObjectName unique
    buffer.append(ManagementConstants.INSTANCE_ID_PROP).append('=').append(endpoint.hashCode());

    //Use default domain name of server
    return new ObjectName(buffer.toString());
}

From source file:catalina.mbeans.MBeanFactory.java

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

    // Create a new RequestDumperValve instance
    RequestDumperValve valve = new RequestDumperValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

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

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Single Sign On Valve./*from  w  w w  .ja va 2 s.  c om*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createSingleSignOn(String parent) throws Exception {

    // Create a new SingleSignOn instance
    SingleSignOn valve = new SingleSignOn();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

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

}