public String getAlarmId(NotificationSourceWrapper notificationSource, String alarmType, String instanceID) { AlarmPlaceHolder localAPH = new AlarmPlaceHolder(notificationSource, alarmType, instanceID); Alarm a = null; for (Map.Entry<String, AlarmPlaceHolder> e : this.alarmIdToAlarm.entrySet()) { if (e.getValue().equals(localAPH)) { a = e.getValue().getAlarm(); break; } } if (a != null) return a.getAlarmID(); else return null; }
public String[] getAlarms(NotificationSource notificationSource) throws NullPointerException, UnrecognizedNotificationSourceException, ManagementException { if (notificationSource == null) { throw new NullPointerException("NotificationSource must not be null"); } mandateSource(notificationSource); try { Set<String> ids = new HashSet<String>(); for (Map.Entry<AlarmPlaceHolder, NotificationSource> e : placeHolderToNotificationSource.entrySet()) { if (e.getValue().equals(notificationSource)) { ids.add(e.getKey().getAlarm().getAlarmID()); } } return ids.toArray(new String[ids.size()]); } catch (Exception e) { throw new ManagementException("Failed to get alarm id list due to: ", e); } }
public int clearAlarms(NotificationSource notificationSource, String alarmType) throws NullPointerException, UnrecognizedNotificationSourceException, ManagementException { if (notificationSource == null) { throw new NullPointerException("NotificationSource must not be null"); } if (alarmType == null) { throw new NullPointerException("AlarmType must not be null"); } mandateSource(notificationSource); int count = 0; try { for (Map.Entry<AlarmPlaceHolder, NotificationSource> e : placeHolderToNotificationSource.entrySet()) { if (e.getValue().equals(notificationSource) && e.getKey().getAlarmType().equals(alarmType)) { if (clearAlarm(e.getKey().getAlarm().getAlarmID())) { count++; } } } } catch (Exception e) { throw new ManagementException("Failed to get alarm id list due to: ", e); } return count; }
public int clearAlarms(NotificationSource notificationSource) throws NullPointerException, UnrecognizedNotificationSourceException, ManagementException { if (notificationSource == null) { throw new NullPointerException("NotificationSource must not be null"); } mandateSource(notificationSource); int count = 0; try { for (Map.Entry<AlarmPlaceHolder, NotificationSource> e : placeHolderToNotificationSource.entrySet()) { if (e.getValue().equals(notificationSource)) { if (clearAlarm(e.getKey().getAlarm().getAlarmID())) { count++; } } } } catch (Exception e) { throw new ManagementException("Failed to get alarm id list due to: ", e); } return count; }
return a.getAlarmID(); } else { return this.raiseAlarm(notificationSource, alarmType, instanceID, level, message, cause); Alarm a = new Alarm(UUID.randomUUID().toString(), notificationSource.getNotificationSource(), alarmType, instanceID, level, message, cause, System.currentTimeMillis()); AlarmPlaceHolder aph = new AlarmPlaceHolder(notificationSource, alarmType, instanceID, a); this.alarmIdToAlarm.put(a.getAlarmID(), aph); return a.getAlarmID();
private AlarmInfo toAlarmInfo(Alarm alarm) { AlarmLevel alarmLevel = alarm.getAlarmLevel(); Throwable cause = alarm.getCause(); String[] causeStringArray = null; if(cause != null) { Writer writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); cause.printStackTrace(printWriter); causeStringArray = writer.toString().split("\n"); } return new AlarmInfo(alarm.getAlarmID(), toTimestamp(alarm.getTimestamp()), (alarmLevel != null ? alarmLevel.toString() : null), alarm.getAlarmType(), alarm.getInstanceID(), cause, causeStringArray, alarm.getMessage()); }
private void generateNotification(AlarmPlaceHolder aph, boolean isCleared) { Alarm alarm = aph.getAlarm(); AlarmLevel generalLevel = isCleared ? AlarmLevel.CLEAR : alarm.getAlarmLevel(); AlarmNotification notification = new AlarmNotification(aph.getNotificationSource().getNotificationSource().getAlarmNotificationType(), this, alarm.getAlarmID(), aph.getNotificationSource() .getNotificationSource(), alarm.getAlarmType(), alarm.getInstanceID(), generalLevel, alarm.getMessage(), alarm.getCause(), aph.getNotificationSource().getNextSequence(), System .currentTimeMillis()); super.sendNotification(notification); }