| 78 | |
| 79 | |
| 80 | public List<ExternalEvent> readEvents(int nrof) { |
| 81 | ArrayList<ExternalEvent> events = new ArrayList<ExternalEvent>(nrof); |
| 82 | int eventsRead = 0; |
| 83 | // skip empty and comment lines |
| 84 | Pattern skipPattern = Pattern.compile("(#.*)|(^\\s*$)"); |
| 85 | |
| 86 | String line; |
| 87 | try { |
| 88 | line = this.reader.readLine(); |
| 89 | } catch (IOException e1) { |
| 90 | throw new SimError("Reading from external event file failed."); |
| 91 | } |
| 92 | while (eventsRead < nrof && line != null) { |
| 93 | Scanner lineScan = new Scanner(line); |
| 94 | if (skipPattern.matcher(line).matches()) { |
| 95 | // skip empty and comment lines |
| 96 | try { |
| 97 | line = this.reader.readLine(); |
| 98 | } catch (IOException e) { |
| 99 | throw new SimError("Reading from external event file " + |
| 100 | "failed."); |
| 101 | } |
| 102 | continue; |
| 103 | } |
| 104 | |
| 105 | double time; |
| 106 | String action; |
| 107 | String msgId; |
| 108 | int hostAddr; |
| 109 | int host2Addr; |
| 110 | |
| 111 | try { |
| 112 | time = lineScan.nextDouble(); |
| 113 | action = lineScan.next(); |
| 114 | |
| 115 | if (action.equals(DROP)) { |
| 116 | msgId = lineScan.next(); |
| 117 | hostAddr = getHostAddress(lineScan.next()); |
| 118 | events.add(new MessageDeleteEvent(hostAddr, msgId, |
| 119 | time, true)); |
| 120 | } |
| 121 | else if (action.equals(REMOVE)) { |
| 122 | msgId = lineScan.next(); |
| 123 | hostAddr = getHostAddress(lineScan.next()); |
| 124 | events.add(new MessageDeleteEvent(hostAddr, msgId, |
| 125 | time, false)); |
| 126 | } |
| 127 | else if (action.equals(CONNECTION)) { |
| 128 | String connEventType; |
| 129 | boolean isUp; |
| 130 | hostAddr = getHostAddress(lineScan.next()); |
| 131 | host2Addr = getHostAddress(lineScan.next()); |
| 132 | connEventType = lineScan.next(); |
| 133 | |
| 134 | String interfaceId = null; |
| 135 | if (lineScan.hasNext()) { |
| 136 | interfaceId = lineScan.next(); |
| 137 | } |