1 26 27 package org.objectweb.alarm.beans; 28 29 import java.rmi.RemoteException ; 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 import java.util.LinkedList ; 33 34 import javax.ejb.FinderException ; 35 import javax.rmi.PortableRemoteObject ; 36 37 38 44 public class Profil { 45 46 49 private String device; 50 51 54 private int maxsev; 56 59 private String name; 60 61 64 private boolean fromAll; 65 66 69 private AlarmRecordHome arh; 70 71 74 private LinkedList alarmList = new LinkedList (); 75 76 82 83 public Profil(String device, String sev, AlarmRecordHome arh) { 84 85 this.device = device; 87 this.arh = arh; 88 fromAll = device.equals("all"); 89 if (sev.startsWith("S")) { 90 maxsev = 1; 91 sev = "S"; 92 } else if (sev.startsWith("W")) { 93 maxsev = 2; 94 sev = "W"; 95 } else { 96 maxsev = 3; 97 sev = "I"; 98 } 99 name = device + "-" + sev; 100 101 Collection knal = null; 103 try { 104 if (fromAll) { 105 knal = arh.findBySeverity(maxsev); 106 } else { 107 knal = arh.findByInterest(device, maxsev); 108 } 109 alarmList.addAll(knal); 110 } catch (FinderException e) { 111 System.out.println("Profil constructor: No Alarm found"); 112 } catch (RemoteException e) { 113 System.out.println("Error getting AlarmRecords:" + e); 114 } 115 } 116 117 120 public String getDevice() { 121 return device; 122 } 123 124 127 public String getSeverity() { 128 switch (maxsev) { 129 case 1: 130 return "S"; 131 case 2: 132 return "W"; 133 case 3: 134 return "I"; 135 default: 136 return "A"; 137 } 138 } 139 140 143 public String getName() { 144 return name; 145 } 146 147 152 public synchronized Collection getAlarms(boolean all) { 153 LinkedList ret = new LinkedList (); 154 Iterator it = alarmList.iterator(); 155 while (it.hasNext()) { 156 AlarmRecord arec = (AlarmRecord) PortableRemoteObject.narrow(it.next(), AlarmRecord.class); 157 AlarmData ad = null; 158 try { 159 ad = arec.getAlarmData(); 160 if (all || (ad.getState() == 1)) { 161 ret.add(ad); 162 } 163 } catch (RemoteException e) { 164 System.out.println("Error getting AlarmRecord:" + e); 165 } 166 } 167 return ret; 168 } 169 170 174 public synchronized int getCurrentLevel() { 175 int ret = 1000; 176 Iterator it = alarmList.iterator(); 177 while (it.hasNext()) { 178 AlarmRecord arec = (AlarmRecord) PortableRemoteObject.narrow(it.next(), AlarmRecord.class); 179 try { 180 AlarmData ad = arec.getAlarmData(); 181 if (ad.getState() == 1 && ad.getSev() <= ret) { 182 ret = ad.getSev(); 183 } 184 } catch (RemoteException e) { 185 System.out.println("Error getting AlarmRecord:" + e); 186 } 187 } 188 return ret; 189 } 190 191 195 public boolean interestedBy(AlarmData ad) { 196 return ((fromAll || ad.getDevice().equals(device)) && ad.getSev() <= maxsev); 197 } 198 199 203 public synchronized void noticeAlarm(AlarmRecord arec) { 204 alarmList.add(arec); 205 } 206 } | Popular Tags |