Ejemplo n.º 1
0
 public void handleNotification(Notification arg0, Object arg1) {
   // check notifications serializable.
   try {
     if (!(arg0.getSource() instanceof ObjectName)) {
       throw new ClassCastException("Doh!");
     }
     Notification copy = OddjobTestHelper.copy(arg0);
     if (!(copy.getSource() instanceof ObjectName)) {
       throw new ClassCastException("Doh!");
     }
   } catch (Exception e) {
     logger.error("Notification Listener failed.", e);
     throw new RuntimeException(e);
   }
   Pair p = new Pair(arg0, arg1);
   notifications.add(p);
 }
 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();
         }
       }
     }
   }
 }
  @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);
  }
Ejemplo n.º 4
0
 @Override
 public void handleNotification(Notification notification, Object handback) {
   notificationCount.incrementAndGet();
   System.out.println("\nReceived notification:");
   System.out.println("\tClassName: " + notification.getClass().getName());
   System.out.println("\tSource: " + notification.getSource());
   System.out.println("\tType: " + notification.getType());
   System.out.println("\tMessage: " + notification.getMessage());
   if (notification instanceof AttributeChangeNotification) {
     AttributeChangeNotification acn = (AttributeChangeNotification) notification;
     System.out.println("\tAttributeName: " + acn.getAttributeName());
     System.out.println("\tAttributeType: " + acn.getAttributeType());
     System.out.println("\tNewValue: " + acn.getNewValue());
     System.out.println("\tOldValue: " + acn.getOldValue());
   }
 }
Ejemplo n.º 5
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("***************************************************");
  }