1 14 package org.jmanage.core.alert.source; 15 16 import org.jmanage.core.config.AlertSourceConfig; 17 import org.jmanage.core.management.*; 18 import org.jmanage.core.util.Loggers; 19 import org.jmanage.core.alert.AlertSource; 20 import org.jmanage.core.alert.AlertInfo; 21 22 import java.util.logging.Logger ; 23 import java.util.logging.Level ; 24 import java.io.IOException ; 25 26 31 public class NotificationAlertSource extends AlertSource { 32 33 private static final Logger logger = 34 Loggers.getLogger(NotificationAlertSource.class); 35 36 private ObjectNotificationListener listener; 37 private ObjectNotificationFilterSupport filter; 38 39 public NotificationAlertSource(AlertSourceConfig sourceConfig){ 40 super(sourceConfig); 41 } 42 43 protected void registerInternal() { 44 45 46 listener = new ObjectNotificationListener(){ 47 public void handleNotification(ObjectNotification notification, 48 Object handback) { 49 try { 50 NotificationAlertSource.this.handler.handle( 51 new AlertInfo(notification)); 52 } catch (Exception e) { 53 logger.log(Level.SEVERE, "Error while handling alert", e); 54 } 55 } 56 }; 57 filter = new ObjectNotificationFilterSupport(); 58 filter.enableType(sourceConfig.getNotificationType()); 59 connection.addNotificationListener(new ObjectName(sourceConfig.getObjectName()), 60 listener, filter, null); 61 } 62 63 protected void unregisterInternal() { 64 65 assert connection != null; 66 67 try { 68 69 connection.removeNotificationListener( 70 new ObjectName(sourceConfig.getObjectName()), 71 listener, filter, null); 72 } catch (Exception e) { 73 logger.log(Level.WARNING, 74 "Error while Removing Notification Listener. error: " + 75 e.getMessage()); 76 } 77 78 listener = null; 79 filter = null; 80 } 81 } 82 | Popular Tags |