@Override
  public void sendNotification(Notification aNotification) {
    PreparedStatement stmt = null;
    try {
      // prepare the insert statement
      stmt = connection.prepareStatement(NOTIF_INSERT_SQL);
      stmt.setString(1, aNotification.getMessage());
      stmt.setLong(2, aNotification.getSequenceNumber());
      if (aNotification.getSource() instanceof Serializable) {
        stmt.setObject(3, aNotification.getSource());
      } else {
        stmt.setObject(3, "No source");
      }
      stmt.setLong(4, aNotification.getTimeStamp());
      stmt.setString(5, aNotification.getType());
      if (aNotification.getUserData() instanceof Serializable) {
        stmt.setObject(6, aNotification.getUserData());
      } else {
        stmt.setObject(6, "No user data");
      }

      // execute amnd commit
      stmt.executeUpdate();

      // this should really be managed by the transaction
      // manager and connections
      connection.commit();
    } catch (Exception e) {
      LOG.error("Failed to persist notification", e);
    } finally {
      try {
        if (stmt != null) {
          stmt.close();
        }
      } catch (SQLException sqle) {
        LOG.error("failed to close statement", sqle);
      }
    }
    super.sendNotification(aNotification);
  }
 public void handleNotification(Notification notification, Object handback) {
   String type = notification.getType();
   if (type.equals(NotificationType.requestReceived)) {
     RequestNotificationData data = (RequestNotificationData) notification.getUserData();
     String key = keysList.get(data.getMethodName());
     if (key != null) {
       ((MethodStatisticsAbstract) statistics.get(key))
           .notifyArrivalOfRequest(notification.getTimeStamp());
     }
   } else if (type.equals(NotificationType.servingStarted)) {
     RequestNotificationData data = (RequestNotificationData) notification.getUserData();
     String key = keysList.get(data.getMethodName());
     if (key != null) {
       ((MethodStatisticsAbstract) statistics.get(key))
           .notifyDepartureOfRequest(notification.getTimeStamp());
     }
   } else if (type.equals(NotificationType.replySent)) {
     RequestNotificationData data = (RequestNotificationData) notification.getUserData();
     String key = keysList.get(data.getMethodName());
     if (key != null) {
       ((MethodStatisticsAbstract) statistics.get(key))
           .notifyReplyOfRequestSent(notification.getTimeStamp());
     }
   } else if (type.equals(NotificationType.voidRequestServed)) {
     RequestNotificationData data = (RequestNotificationData) notification.getUserData();
     String key = keysList.get(data.getMethodName());
     if (key != null) {
       ((MethodStatisticsAbstract) statistics.get(key))
           .notifyReplyOfRequestSent(notification.getTimeStamp());
     }
   } else if (type.equals(NotificationType.setOfNotifications)) {
     @SuppressWarnings("unchecked")
     ConcurrentLinkedQueue<Notification> notificationsList =
         (ConcurrentLinkedQueue<Notification>) notification.getUserData();
     for (Iterator<Notification> iterator = notificationsList.iterator(); iterator.hasNext(); ) {
       handleNotification(iterator.next(), handback);
     }
   }
 }
Exemplo n.º 3
0
  public void handleNotification(Notification ntfyObj, Object handback) {
    log.info("***************************************************");
    log.info("* Notification received at " + new Date().toString());
    log.info("* type      = " + ntfyObj.getType());
    log.info("* message   = " + ntfyObj.getMessage());

    if (ntfyObj.getMessage().contains(path)) {
      setSuccess(true);
    }

    log.info("* seqNum    = " + ntfyObj.getSequenceNumber());
    log.info("* source    = " + ntfyObj.getSource());
    log.info("* seqNum    = " + Long.toString(ntfyObj.getSequenceNumber()));
    log.info("* timeStamp = " + new Date(ntfyObj.getTimeStamp()));
    log.info("* userData  = " + ntfyObj.getUserData());
    log.info("***************************************************");
  }
 public void handleNotification(Notification notif, Object handback) {
   String type = notif.getType();
   if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
     GarbageCollectionNotificationInfo gcNotif =
         GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
     String source = ((ObjectName) notif.getSource()).getCanonicalName();
     synchronized (synchronizer) {
       if (listenerInvoked.get(source) == null) {
         listenerInvoked.put(((ObjectName) notif.getSource()).getCanonicalName(), gcNotif);
         count++;
         if (count >= number) {
           synchronizer.notify();
         }
       }
     }
   }
 }
Exemplo n.º 5
0
 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);
   }
 }
Exemplo n.º 6
0
  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)
              + ")");
    }
  }
  /**
   * Jesli otrzymana notyfikacja jest o stanie procesu deploymentu to aktualizuje licznik i
   * przekazuje notyfikacje do wszystkich listenerow postepu procesu deploymentu
   */
  @Override
  public synchronized void handleNotification(Notification notification, Object handback) {

    Object userData = notification.getUserData();

    log.info("Received notification from WorkerProgress ");

    if (notification.getUserData() != null
        && notification.getUserData() instanceof TaskCompletedNotification) {

      updateProgress(
          new ProgressNotification(
              ++index,
              totalTasks,
              ((TaskCompletedNotification) notification.getUserData()).getNodeIpAddress()));

    } else if (notification.getUserData() != null
        && notification.getUserData() instanceof LogNotification) {

      updateLogs(((LogNotification) notification.getUserData()).getLog());
    }
  }
Exemplo n.º 8
0
 public void handleNotification(Notification notif, Object handback) {
   String spsuid = (String) notif.getUserData();
   Dataset pps = DcmObjectFactory.getInstance().newDataset();
   try {
     Dataset sps;
     GPWLManager gpwlmgr = getGPWLManager();
     sps = gpwlmgr.getWorklistItem(spsuid);
     String ppsiuid = spsuid + ppsuidSuffix;
     String status = sps.getString(Tags.GPSPSStatus);
     pps.putCS(Tags.GPPPSStatus, status);
     pps.putUI(Tags.SOPInstanceUID, ppsiuid);
     Date now = new Date();
     if ("IN PROGRESS".equals(status)) {
       try {
         getGPPPSManager().getGPPPS(ppsiuid);
         return; // avoid duplicate N_CREATE
       } catch (Exception e) {
       }
       pps.putSH(Tags.PPSID, "PPS" + ppsiuid.hashCode());
       pps.putDA(Tags.PPSStartDate, now);
       pps.putTM(Tags.PPSStartTime, now);
       pps.putDA(Tags.PPSEndDate);
       pps.putTM(Tags.PPSEndTime);
       for (int i = 0; i < N_CREATE_TYPE2_ATTRS.length; i++) {
         pps.putXX(N_CREATE_TYPE2_ATTRS[i]);
       }
       pps.putAll(sps.subSet(N_CREATE_SPS_ATTRS));
       copyCode(
           copyWorkitemCode,
           sps.getItem(Tags.ScheduledWorkitemCodeSeq),
           pps.putSQ(Tags.PerformedWorkitemCodeSeq));
       copyCode(
           copyStationNameCode,
           sps.getItem(Tags.ScheduledStationNameCodeSeq),
           pps.putSQ(Tags.PerformedStationNameCodeSeq));
       copyCode(
           copyStationClassCode,
           sps.getItem(Tags.ScheduledStationClassCodeSeq),
           pps.putSQ(Tags.PerformedStationClassCodeSeq));
       copyCode(
           copyStationGeographicLocationCode,
           sps.getItem(Tags.ScheduledStationGeographicLocationCodeSeq),
           pps.putSQ(Tags.PerformedStationGeographicLocationCodeSeq));
       copyCode(
           copyProcessingApplicationsCode,
           sps.getItem(Tags.ScheduledProcessingApplicationsCodeSeq),
           pps.putSQ(Tags.PerformedProcessingApplicationsCodeSeq));
     } else if ("COMPLETED".equals(status) || "DISCONTINUED".equals(status)) {
       pps.putDA(Tags.PPSEndDate, now);
       pps.putTM(Tags.PPSEndTime, now);
       pps.putAll(gpwlmgr.getOutputInformation(spsuid));
     } else {
       return;
     }
   } catch (Exception e) {
     log.error("Failed to access GP-SPS[" + spsuid + "]", e);
     return;
   }
   for (int i = 0; i < destAETs.length; i++) {
     PPSOrder order = new PPSOrder(pps, destAETs[i]);
     try {
       log.info("Scheduling " + order);
       jmsDelegate.queue(queueName, order, Message.DEFAULT_PRIORITY, 0L);
     } catch (Exception e) {
       log.error("Failed to schedule " + order, e);
     }
   }
 }
    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);
        }
      }
    }
    public void handleNotification(Notification notification, Object handback) {
      try {
        String type = notification.getType();

        if (NotificationType.GCMRuntimeRegistered.equals(type)) {
          if (debug) {
            System.out.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Notification received");
            outDebug.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Notification received");
          }
          GCMRuntimeRegistrationNotificationData data =
              (GCMRuntimeRegistrationNotificationData) notification.getUserData();
          if (data.getDeploymentId() != listener.getDeployID()) {
            return;
          }
          if (debug) {
            System.out.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Notification accepted");
            outDebug.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Notification accepted");
            outDebug.flush();
          }

          ProActiveRuntime childRuntime = data.getChildRuntime();
          if (debug) {
            System.out.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Creating Node");
            outDebug.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Creating Node");
          }
          Node scilabNode = null;
          try {
            scilabNode =
                childRuntime.createLocalNode(
                    nodeBaseName + "_" + nodeName + "_" + nodeCount, true, null, null);
          } catch (Exception e) {
            if (debug) {
              e.printStackTrace();
              e.printStackTrace(outDebug);
            }
            throw e;
          }
          nodeCount++;
          if (debug) {
            System.out.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Node Created : "
                    + scilabNode.getNodeInformation().getURL());
            outDebug.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Node Created :"
                    + scilabNode.getNodeInformation().getURL());
          }
          listener.setNode(scilabNode);

          if (debug) {
            System.out.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Waking up main thread");
            outDebug.println(
                "["
                    + new java.util.Date()
                    + " "
                    + host
                    + " "
                    + this.getClass().getSimpleName()
                    + "] Waking up main thread");
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
        if (debug) {
          e.printStackTrace(outDebug);
        }
      } finally {
        semaphore.release();
      }
    }