1 22 package org.jboss.monitor.alarm; 23 24 import javax.management.Notification ; 25 import javax.management.ObjectName ; 26 27 33 public class AlarmNotification extends Notification 34 { 35 37 38 private static final long serialVersionUID = -7041616127511632675L; 39 40 41 private ObjectName target; 42 43 44 private int severity; 45 46 47 private int alarmState; 48 49 51 62 public AlarmNotification( 63 String type, Object source, 64 ObjectName target, int severity, int alarmState, 65 long sequenceNumber, long timeStamp, String message 66 ) 67 { 68 super(type, source, sequenceNumber, timeStamp, message); 69 70 this.target = target; 71 72 switch (alarmState) 73 { 74 case Alarm.STATE_CLEARED: 75 this.alarmState = Alarm.STATE_CLEARED; 76 this.severity = Alarm.SEVERITY_NORMAL; 78 break; 79 80 case Alarm.STATE_CREATED: 81 case Alarm.STATE_CHANGED: 82 this.alarmState = alarmState; 83 if (severity > Alarm.SEVERITY_NORMAL && severity <= Alarm.SEVERITY_UNKNOWN) 85 { 86 this.severity = severity; 87 } 88 else { 90 this.severity = Alarm.SEVERITY_UNKNOWN; 91 } 92 break; 93 94 case Alarm.STATE_NONE: 95 default: this.alarmState = Alarm.STATE_NONE; 97 if (severity >= Alarm.SEVERITY_NORMAL && severity <= Alarm.SEVERITY_UNKNOWN) 98 { 99 this.severity = severity; 100 } 101 else { 103 this.severity = Alarm.SEVERITY_UNKNOWN; 104 } 105 break; 106 } 107 } 108 109 111 114 public static Object createKey(Notification n) 115 { 116 Object source = getEffectiveSource(n); 117 return AlarmKey.createKey(source, n.getType()); 118 } 119 120 125 public static Object getEffectiveSource(Notification n) 126 { 127 Object source = n.getSource(); 128 if (n instanceof AlarmNotification) 129 { 130 ObjectName target = ((AlarmNotification)n).getTarget(); 131 if (target != null) 132 { 133 source = target; 134 } 135 } 136 return source; 137 } 138 139 141 145 public ObjectName getTarget() 146 { 147 return target; 148 } 149 150 153 public int getSeverity() 154 { 155 return this.severity; 156 } 157 158 161 public int getAlarmState() 162 { 163 return this.alarmState; 164 } 165 166 168 171 public String toString() 172 { 173 StringBuffer sbuf = new StringBuffer (256); 174 175 sbuf.append(AlarmNotification.class.getName()); 176 sbuf.append(" [ type=").append(getType()); 177 sbuf.append(", source=").append(getSource()); 178 sbuf.append(", target=").append(target); 179 sbuf.append(", severity=").append(Alarm.SEVERITY_STRINGS[severity]); 180 sbuf.append(", alarmState=").append(Alarm.STATE_STRINGS[alarmState]); 181 sbuf.append(", sequenceNumber=").append(getSequenceNumber()); 182 sbuf.append(", timeStamp=").append(getTimeStamp()); 183 sbuf.append(", message=").append(getMessage()); 184 sbuf.append(", userData={").append(getUserData()); 185 sbuf.append("} ]"); 186 187 return sbuf.toString(); 188 } 189 } 190 | Popular Tags |