示例#1
0
  public synchronized Collection<GarbageCollectorMXBean> getGarbageCollectorMXBeans()
      throws IOException {

    // TODO: How to deal with changes to the list??
    if (garbageCollectorMBeans == null) {
      ObjectName gcName = null;
      try {
        gcName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
      } catch (MalformedObjectNameException e) {
        // should not reach here
        assert (false);
      }
      Set<ObjectName> mbeans = server.queryNames(gcName, null);
      if (mbeans != null) {
        garbageCollectorMBeans = new ArrayList<GarbageCollectorMXBean>();
        Iterator<ObjectName> iterator = mbeans.iterator();
        while (iterator.hasNext()) {
          ObjectName on = (ObjectName) iterator.next();
          String name = GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",name=" + on.getKeyProperty("name");

          GarbageCollectorMXBean mBean =
              newPlatformMXBeanProxy(server, name, GarbageCollectorMXBean.class);
          garbageCollectorMBeans.add(mBean);
        }
      }
    }
    return garbageCollectorMBeans;
  }
示例#2
0
  /**
   * Returns a map of MBeans with ObjectName as the key and MBeanInfo value of a given domain. If
   * domain is <tt>null</tt>, all MBeans are returned. If no MBean found, an empty map is returned.
   */
  public Map<ObjectName, MBeanInfo> getMBeans(String domain) throws IOException {

    ObjectName name = null;
    if (domain != null) {
      try {
        name = new ObjectName(domain + ":*");
      } catch (MalformedObjectNameException e) {
        // should not reach here
        assert (false);
      }
    }
    Set<ObjectName> mbeans = server.queryNames(name, null);
    Map<ObjectName, MBeanInfo> result = new HashMap<ObjectName, MBeanInfo>(mbeans.size());
    Iterator<ObjectName> iterator = mbeans.iterator();
    while (iterator.hasNext()) {
      Object object = iterator.next();
      if (object instanceof ObjectName) {
        ObjectName o = (ObjectName) object;
        try {
          MBeanInfo info = server.getMBeanInfo(o);
          result.put(o, info);
        } catch (IntrospectionException e) {
          // TODO: should log the error
        } catch (InstanceNotFoundException e) {
          // TODO: should log the error
        } catch (ReflectionException e) {
          // TODO: should log the error
        }
      }
    }
    return result;
  }
  /**
   * Get Component MBeans. Creates, registers and deregisters MBeans for an array of components. On
   * each call the passed map is used to determine components that have already been registers and
   * those that need to be deregistered.
   *
   * @param components the components.
   * @param map A map of previously registered components to object name. If null is passed, a
   *     default map for the mbean is used.
   * @return An array of ObjectNames for each component.
   */
  protected ObjectName[] getComponentMBeans(Object[] components, Map map) {
    if (map == null) map = _components;
    ObjectName[] beans = null;
    if (components == null) beans = new ObjectName[0];
    else {
      beans = new ObjectName[components == null ? 0 : components.length];

      // Add new beans
      for (int i = 0; i < components.length; i++) {
        ObjectName on = (ObjectName) map.get(components[i]);
        if (on == null) {
          ModelMBean mbean = mbeanFor(components[i]);
          if (mbean == null) log.warn("No mbean for " + components[i]);
          else {
            try {
              if (mbean instanceof ModelMBeanImpl) {
                ((ModelMBeanImpl) mbean).setBaseObjectName(getObjectName().toString());
                on = getMBeanServer().registerMBean(mbean, null).getObjectName();
              } else {
                on = uniqueObjectName(getMBeanServer(), components[i], getObjectName().toString());
                on = getMBeanServer().registerMBean(mbean, on).getObjectName();
              }
              map.put(components[i], on);
            } catch (Exception e) {
              log.warn(LogSupport.EXCEPTION, e);
            }
          }
        }
        beans[i] = on;
      }
    }

    // Delete old beans
    if (components == null || map.size() > components.length) {
      Object[] to_delete = new Object[map.size() - beans.length];
      int d = 0;
      Iterator iter = map.keySet().iterator();
      keys:
      while (iter.hasNext()) {
        Object bean = iter.next();
        if (components != null) {
          for (int i = 0; i < components.length; i++) if (components[i] == bean) continue keys;
        }
        to_delete[d++] = bean;
      }

      for (; d-- > 0; ) {
        try {
          getMBeanServer().unregisterMBean((ObjectName) map.remove(to_delete[d]));
        } catch (Exception e) {
          log.warn(LogSupport.EXCEPTION, e);
        }
      }
    }

    return beans;
  }
示例#4
0
文件: Q2.java 项目: rlishtaba/jPOS
 private void deployBundle(File bundle, boolean encrypt)
     throws JDOMException, IOException, ISOException, GeneralSecurityException {
   SAXBuilder builder = createSAXBuilder();
   Document doc = builder.build(bundle);
   Iterator iter = doc.getRootElement().getChildren().iterator();
   for (int i = 1; iter.hasNext(); i++) {
     Element e = (Element) iter.next();
     deployElement(e, String.format("%02d_%s.xml", i, e.getName()), encrypt, !encrypt);
     // the !encrypt above is tricky and deserves an explanation
     // if we are encrypting a QBean, we want it to stay in the deploy
     // directory for future runs. If on the other hand we are deploying
     // a bundle, we want it to be transient.
   }
 }
示例#5
0
文件: Q2.java 项目: rlishtaba/jPOS
 private void checkModified() {
   Iterator iter = dirMap.entrySet().iterator();
   while (iter.hasNext()) {
     Map.Entry entry = (Map.Entry) iter.next();
     File f = (File) entry.getKey();
     QEntry qentry = (QEntry) entry.getValue();
     if (qentry.isQBean() && qentry.isQPersist()) {
       ObjectName name = qentry.getObjectName();
       if (getState(name) == QBean.STARTED && isModified(name)) {
         qentry.setDeployed(persist(f, name));
       }
     }
   }
 }
  /* ------------------------------------------------------------ */
  public AttributeList setAttributes(AttributeList attrs) {
    log.debug("setAttributes");

    AttributeList results = new AttributeList(attrs.size());
    Iterator iter = attrs.iterator();
    while (iter.hasNext()) {
      try {
        Attribute attr = (Attribute) iter.next();
        setAttribute(attr);
        results.add(new Attribute(attr.getName(), getAttribute(attr.getName())));
      } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
      }
    }
    return results;
  }
示例#7
0
文件: Q2.java 项目: rlishtaba/jPOS
 private void deploy() {
   List startList = new ArrayList();
   Iterator iter = dirMap.entrySet().iterator();
   try {
     while (iter.hasNext() && !shutdown) {
       Map.Entry entry = (Map.Entry) iter.next();
       File f = (File) entry.getKey();
       QEntry qentry = (QEntry) entry.getValue();
       long deployed = qentry.getDeployed();
       if (deployed == 0) {
         if (deploy(f)) {
           if (qentry.isQBean()) startList.add(qentry.getInstance());
           qentry.setDeployed(f.lastModified());
         } else {
           // deploy failed, clean up.
           iter.remove();
         }
       } else if (deployed != f.lastModified()) {
         undeploy(f);
         iter.remove();
         loader.forceNewClassLoaderOnNextScan();
       }
     }
     iter = startList.iterator();
     while (iter.hasNext()) {
       start((ObjectInstance) iter.next());
     }
   } catch (Exception e) {
     log.error("deploy", e);
   }
 }
  /**
   * Unregister mbeans for already registered components
   *
   * @param map
   */
  protected void destroyComponentMBeans(Map map) {
    // if no map of registered mbean names is passed,
    // use the default map
    if (null == map) map = _components;

    if (map == null) return;

    Iterator itor = map.values().iterator();
    while (itor.hasNext()) {
      try {
        ObjectName o = (ObjectName) itor.next();
        getMBeanServer().unregisterMBean(o);
        itor.remove();
      } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
      }
    }
  }
 public String[] getjavaVMs() {
   // get the internal VM name
   // App Clients never run on the internal VM
   Set res = new HashSet();
   if (!(this instanceof AppClientModuleMdl)) {
     // res.addAll(findNames("j2eeType=JVM,name=" + MOAgentFactory.getAgent().getJVMId()));
   }
   // get the external VM names
   Iterator vmNames = externalVMs.iterator();
   while (vmNames.hasNext()) {
     String vmName = (String) vmNames.next();
     Set x = findNames("j2eeType=JVM,name=" + vmName);
     if (x.size() > 0) {
       res.addAll(x);
     } else {
       // no longer an active VM
       externalVMs.remove(vmName);
       vmNames = externalVMs.iterator();
     }
   }
   Iterator it = res.iterator();
   String[] vms = new String[res.size()];
   int i = 0;
   while (it.hasNext()) {
     vms[i++] = ((ObjectName) it.next()).toString();
   }
   return vms;
 }
示例#10
0
  public Collection<MemoryPoolProxy> getMemoryPoolProxies() throws IOException {

    // TODO: How to deal with changes to the list??
    if (memoryPoolProxies == null) {
      ObjectName poolName = null;
      try {
        poolName = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*");
      } catch (MalformedObjectNameException e) {
        // should not reach here
        assert (false);
      }
      Set<ObjectName> mbeans = server.queryNames(poolName, null);
      if (mbeans != null) {
        memoryPoolProxies = new ArrayList<MemoryPoolProxy>();
        Iterator<ObjectName> iterator = mbeans.iterator();
        while (iterator.hasNext()) {
          ObjectName objName = (ObjectName) iterator.next();
          MemoryPoolProxy p = new MemoryPoolProxy(this, objName);
          memoryPoolProxies.add(p);
        }
      }
    }
    return memoryPoolProxies;
  }