Пример #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;
   }
 }