public void handleNotification(Notification notification, Object handback) {

    log.warn("================================================================================");

    String message = notification.getMessage();
    log.warn("Message: " + message);

    String type = notification.getType();
    log.warn("Type: " + type);

    if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
        || type.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {

      CompositeData cd = (CompositeData) notification.getUserData();
      MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);

      String poolName = info.getPoolName();
      log.warn("Pool Name: " + poolName);

      long count = info.getCount();
      log.warn("Count: " + count);

      MemoryUsage usage = info.getUsage();

      long maxMemory = usage.getMax();
      long maxMB = maxMemory / (1024 * 1024);

      long usedMemory = usage.getUsed();
      long usedMB = usedMemory / (1024 * 1024);

      double percentUsed = (double) usedMemory / maxMemory;
      log.debug(
          "Used Memory : "
              + usedMB
              + "/"
              + maxMB
              + " MB ("
              + percentFormat.format(percentUsed)
              + ")");
    }
  }
 private void thresholdNotificationLogger(Notification notification) {
   CompositeData cd = (CompositeData) notification.getUserData();
   MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
   MemoryPoolMXBean memPool = memoryPoolMap.get(info.getPoolName());
   log.error(
       "memory threshold "
           + getPercentFormat(getThresholdPercent(memPool))
           + " exceeded on memory pool "
           + info.getPoolName()
           + ", count:"
           + info.getCount()
           + ", "
           + getUsagePercent(memPool)
           + "["
           + info.getUsage()
           + "]");
   if (verbose) {
     logStats(memoryPoolMap.get(info.getPoolName()), Level.WARN);
   }
 }
    public void handleNotification(Notification notification, Object handback) {
      log.debug("handleNotification", "Received notification [ " + notification.getType() + "]");

      String type = notification.getType();
      if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
          || type.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
        MemoryNotificationInfo minfo =
            MemoryNotificationInfo.from((CompositeData) notification.getUserData());
        SnmpCounter64 count = new SnmpCounter64(minfo.getCount());
        SnmpCounter64 used = new SnmpCounter64(minfo.getUsage().getUsed());
        SnmpString poolName = new SnmpString(minfo.getPoolName());
        SnmpOid entryIndex = getJvmMemPoolEntryIndex(minfo.getPoolName());

        if (entryIndex == null) {
          log.error(
              "handleNotification",
              "Error: Can't find entry index for Memory Pool: "
                  + minfo.getPoolName()
                  + ": "
                  + "No trap emitted for "
                  + type);
          return;
        }

        SnmpOid trap = null;

        final SnmpOidTable mibTable = getOidTable();
        try {
          SnmpOid usedOid = null;
          SnmpOid countOid = null;

          if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
            trap = new SnmpOid(mibTable.resolveVarName("jvmLowMemoryPoolUsageNotif").getOid());
            usedOid =
                new SnmpOid(mibTable.resolveVarName("jvmMemPoolUsed").getOid() + "." + entryIndex);
            countOid =
                new SnmpOid(
                    mibTable.resolveVarName("jvmMemPoolThreshdCount").getOid() + "." + entryIndex);
          } else if (type.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
            trap = new SnmpOid(mibTable.resolveVarName("jvmLowMemoryPoolCollectNotif").getOid());
            usedOid =
                new SnmpOid(
                    mibTable.resolveVarName("jvmMemPoolCollectUsed").getOid() + "." + entryIndex);
            countOid =
                new SnmpOid(
                    mibTable.resolveVarName("jvmMemPoolCollectThreshdCount").getOid()
                        + "."
                        + entryIndex);
          }

          // Datas
          SnmpVarBindList list = new SnmpVarBindList();
          SnmpOid poolNameOid =
              new SnmpOid(mibTable.resolveVarName("jvmMemPoolName").getOid() + "." + entryIndex);

          SnmpVarBind varCount = new SnmpVarBind(countOid, count);
          SnmpVarBind varUsed = new SnmpVarBind(usedOid, used);
          SnmpVarBind varPoolName = new SnmpVarBind(poolNameOid, poolName);

          list.add(varPoolName);
          list.add(varCount);
          list.add(varUsed);

          sendTrap(trap, list);
        } catch (Exception e) {
          log.error("handleNotification", "Exception occured : " + e);
        }
      }
    }