@Override
 public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) throws IOException {
   try {
     return connection.queryMBeans(name, query);
   } catch (IOException e) {
     checkConnection();
     return connection.queryMBeans(name, query);
   }
 }
  @Test(groups = "wso2.esb", description = "JMS Consumer Test after resume")
  public void testJMSResume() throws Exception {

    // redeploy proxy service
    addProxyService(AXIOMUtil.stringToOM(getJMSProxy()));
    // give it max time to deploy
    Thread.sleep(16000);

    // JMS should still be paused.
    assertTrue(!stringExistsInLog(msgAfter));

    // resume JMS Listener from JMXClient
    Set<ObjectInstance> objSet =
        mbsc.queryMBeans(
            new ObjectName("org.apache.axis2:Type=Transport,ConnectorName=jms-listener-*"), null);
    Iterator i = objSet.iterator();
    while (i.hasNext()) {
      ObjectInstance obj = (ObjectInstance) i.next();
      mbsc.invoke(obj.getObjectName(), "resume", null, null);
    }

    Thread.sleep(10000);
    assertTrue(stringExistsInLog("Listener resumed"));
    assertTrue(stringExistsInLog(msgAfter));
  }
Example #3
0
  public static JSONObject loadMemoryInfo(String app) {
    try {
      MemoryMXBean mBean = JMConnManager.getMemoryMBean(app);
      MemoryUsage nonHeap = mBean.getNonHeapMemoryUsage();
      MemoryUsage heap = mBean.getHeapMemoryUsage();

      JSONObject map = new JSONObject(true);
      buildMemoryJSon(heap, "heap", map);
      buildMemoryJSon(nonHeap, "nonheap", map);

      JSONObject heapChild = new JSONObject();
      JSONObject nonheapChild = new JSONObject();

      JSONObject heapUsed = new JSONObject();
      JSONObject heapMax = new JSONObject();
      heapUsed.put("used", heap.getUsed());
      heapMax.put("used", heap.getCommitted());
      heapChild.put("HeapUsed", heapUsed);
      heapChild.put("HeapCommit", heapMax);

      JSONObject nonheapUsed = new JSONObject();
      JSONObject noheapMax = new JSONObject();
      nonheapUsed.put("used", nonHeap.getUsed());
      noheapMax.put("used", nonHeap.getCommitted());

      nonheapChild.put("NonheapUsed", nonheapUsed);
      nonheapChild.put("NonheapCommit", noheapMax);

      ObjectName obj = new ObjectName("java.lang:type=MemoryPool,*");
      MBeanServerConnection conn = JMConnManager.getConn(app);
      Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null);
      for (ObjectInstance objx : MBeanset) {
        String name = objx.getObjectName().getCanonicalName();
        String keyName = objx.getObjectName().getKeyProperty("name");
        MemoryPoolMXBean bean = JMConnManager.getServer(app, name, MemoryPoolMXBean.class);
        JSONObject item = toJson(bean.getUsage());
        if (JMConnManager.HEAP_ITEM.contains(keyName)) {
          heapChild.put(keyName, item);
        } else {
          nonheapChild.put(keyName, item);
        }
      }
      map.getJSONObject("heap").put("childs", heapChild);
      map.getJSONObject("nonheap").put("childs", nonheapChild);

      return map;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  @Test(groups = "wso2.esb", description = "JMS Consumer Test after pause")
  public void testJMSPause() throws Exception {

    // pause JMS Listener from JMXClient
    Set<ObjectInstance> objSet =
        mbsc.queryMBeans(
            new ObjectName("org.apache.axis2:Type=Transport,ConnectorName=jms-listener-*"), null);
    Iterator i = objSet.iterator();
    while (i.hasNext()) {
      ObjectInstance obj = (ObjectInstance) i.next();
      mbsc.invoke(obj.getObjectName(), "pause", null, null);
    }

    Thread.sleep(10000);
    assertTrue(stringExistsInLog("Listener paused"));

    // Put message in queue.
    sendMessage(msgAfter);
    Thread.sleep(10000);
    assertTrue(!stringExistsInLog(msgAfter));
  }