Example usage for javax.management Query match

List of usage examples for javax.management Query match

Introduction

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

Prototype

public static QueryExp match(AttributeValueExp a, StringValueExp s) 

Source Link

Document

Returns a query expression that represents a matching constraint on a string argument.

Usage

From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java

public static List<String> getEndPoints()
        throws MalformedObjectNameException, NullPointerException, UnknownHostException,
        AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
            Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    String hostname = InetAddress.getLocalHost().getHostName();
    InetAddress[] addresses = InetAddress.getAllByName(hostname);
    ArrayList<String> endPoints = new ArrayList<>();
    for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
        ObjectName obj = i.next();
        String scheme = mbs.getAttribute(obj, "scheme").toString();
        String port = obj.getKeyProperty("port");
        for (InetAddress addr : addresses) {
            String host = addr.getHostAddress();
            String ep = scheme + "://" + host + ":" + port;
            endPoints.add(ep);//from   w ww. j  a  v a  2 s. c  o m
        }
    }
    return endPoints;
}

From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java

/**
 * This command try to get Port which the service is listening to. The port should be in the parameter -httpPort when running, or Tomcat port
 *
 * @return//www  .ja v  a 2 s.  co m
 */
public static String getPort() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
                Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
        for (ObjectName obj : objs) {
            String port = obj.getKeyProperty("port");
            return port;
        }
    } catch (MalformedObjectNameException e) {
        EngineLogger.logger
                .error("Cannot get listening port of salsa-engine service. return 8080 as default. Error: "
                        + e.toString());
    }
    EngineLogger.logger.error("Cannot find listening port of salsa-engine service. return 8080 as default");
    return "8080";
}

From source file:org.lobzik.home_sapiens.pi.AppData.java

public static List<String> getHTTPEndPoints() throws Exception { //tomcat-specific
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
            Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    String hostname = InetAddress.getLocalHost().getHostName();
    InetAddress[] addresses = InetAddress.getAllByName(hostname);
    ArrayList<String> endPoints = new ArrayList<String>();
    for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
        ObjectName obj = i.next();
        String scheme = mbs.getAttribute(obj, "scheme").toString();
        if (!scheme.toLowerCase().equals("http")) {
            continue;
        }//from  w w  w  .ja  v a 2s . c o  m
        String port = obj.getKeyProperty("port");
        for (InetAddress addr : addresses) {
            String host = addr.getHostAddress();
            String ep = scheme + "://" + host + ":" + port;
            endPoints.add(ep);
        }
    }
    return endPoints;
}