jeudi 28 mai 2015

Getting same JMX result with different provider urls

I am currently developing an app with websphere 8.5, however i encountered a very strange problem with JMX. Here is the code:

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
    env.put(Context.PROVIDER_URL, "iiop://%host1%:9815");

    JMXServiceURL url = new JMXServiceURL("service:jmx:http://rmi/jndi/cell/persistent/%serverName%");
    JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    Hashtable<String, String> keys = new Hashtable<String, String>();
    keys.put("Type", "Service");
    keys.put("Name", "*");
    keys.put("ServiceName", "*");
    ObjectName on = new ObjectName(%domain%, keys);
    Set<ObjectName> objNames = mbsc.queryNames(on, null);

    Iterator<ObjectName> it = objNames.iterator();
    while (it.hasNext()) {
        ObjectName mb = (ObjectName) it.next();
        String serviceName = mb.getKeyProperty("Name");
        try {
            logger.info(serviceName + ": " + mbsc.invoke(mb, "getState", null, null).toString());
        } catch (Exception e) {
        }
    }

    jmxc.close();

    env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
    env.put(Context.PROVIDER_URL, "iiop://%host2%:9815");

    url = new JMXServiceURL("service:jmx:http://rmi/jndi/cell/persistent/%serverName%");
    jmxc = JMXConnectorFactory.connect(url, env);
    mbsc = jmxc.getMBeanServerConnection();

    keys = new Hashtable<String, String>();
    keys.put("Type", "Service");
    keys.put("Name", "*");
    keys.put("ServiceName", "*");
    on = new ObjectName(%domain%, keys);
    objNames = mbsc.queryNames(on, null);

    it = objNames.iterator();
    while (it.hasNext()) {
        ObjectName mb = (ObjectName) it.next();
        String serviceName = mb.getKeyProperty("Name");
        try {
            logger.info(serviceName + ": " + mbsc.invoke(mb, "getState", null, null).toString());
        } catch (Exception e) {
        }
    }

    jmxc.close();

Basically I just try to get information from one WAS client to two WAS servers via JMX. The piece of code is doing exactly the same thing on two different hosts(host1 and host2). The two hosts have same configuration, same JMX url, same services, different service states. This is working perfectly running as normal java application, where the output from host1 is different from host2. However when i deploy it to WAS client, it returns exactly same output from different servers. Just like the two MBeanServerConnection objects are both come from host1. Is it because of some strange settings on websphere client that have some kind of cache for the same JMX url?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire