Пример #1
0
 @Override
 public int getLocalSize() {
   if (nc != null) {
     synchronized (this) {
       if (mBeanServer == null || jmxCacheName == null) {
         int nodeId = CacheFactory.getCluster().getLocalMember().getId();
         jmxCacheName = String.format(CACHE_JMX_NAME_TEMPLATE, serviceName, cacheName, nodeId);
         mBeanServer = MBeanHelper.findMBeanServer();
       }
     }
     try {
       AttributeList list =
           mBeanServer.getAttributes(
               new ObjectName(jmxCacheName), new String[] {"Units", "UnitFactor"});
       return ((Integer) ((Attribute) list.get(0)).getValue())
           * ((Integer) ((Attribute) list.get(1)).getValue());
     } catch (Exception e) {
       log.warn("Failed to retrieve JMX info from object " + jmxCacheName + "\n" + e);
       return -1;
     }
   } else {
     log.info("Cache is not available.");
     return -1;
   }
 }
Пример #2
0
  /** @see DynamicMBean#setAttributes */
  public AttributeList setAttributes(AttributeList attributes) {

    /* Sanity checking. */
    if (attributes == null) {
      throw new IllegalArgumentException("attribute list can't be null");
    }

    /* Set each attribute specified. */
    AttributeList results = new AttributeList();
    for (int i = 0; i < attributes.size(); i++) {
      Attribute attr = (Attribute) attributes.get(i);
      try {
        /* Set new value. */
        jeHelper.setAttribute(targetEnv, attr);

        /*
         * Add the name and new value to the result list. Be sure
         * to ask the MBean for the new value, rather than simply
         * using attr.getValue(), because the new value may not
         * be same if it is modified according to the JE
         * implementation.
         */
        String name = attr.getName();
        Object newValue = jeHelper.getAttribute(targetEnv, name);
        results.add(new Attribute(name, newValue));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return results;
  }
Пример #3
0
  private static boolean checkAttrs(String what, AttributeList attrs) {
    if (attrs.size() != 1) {
      System.out.println(
          "TEST FAILS: list returned by " + what + " does not have size 1: " + attrs);
      return false;
    }
    Attribute attr = (Attribute) attrs.get(0);
    if (!"Exotic".equals(attr.getName())) {
      System.out.println("TEST FAILS: " + what + " returned wrong " + "attribute: " + attr);
      return false;
    }

    return true;
  }
Пример #4
0
  public synchronized AttributeList setAttributes(AttributeList list) {
    AttributeList results = new AttributeList();
    for (int i = 0; i < list.size(); i++) {
      Attribute attr = (Attribute) list.get(i);

      if (setNamedAttribute(attr)) {
        results.add(attr);
      } else {
        if (log.isWarnEnabled()) {
          log.warn(
              "Failed to update attribute name "
                  + attr.getName()
                  + " with value "
                  + attr.getValue());
        }
      }
    }
    return results;
  }
Пример #5
0
 private static Object attrValue(AttributeList attrs) {
   return ((Attribute) attrs.get(0)).getValue();
 }