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); } } }
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("***************************************************"); }
@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); }