| 39 | import java.util.List; |
| 40 | |
| 41 | public class ConnectionStat implements IStatPoster, IEventHandler { |
| 42 | |
| 43 | private static final Logger logger = Logger.getLogger(ConnectionStatData.class); |
| 44 | private final String statPath = FtnTools.getInbound() + File.separator |
| 45 | + "connstat.xml"; |
| 46 | |
| 47 | |
| 48 | public ConnectionStat() { |
| 49 | Notifier.INSTANSE.register(ConnectionEndEvent.class, this); |
| 50 | } |
| 51 | |
| 52 | public void handle(IEvent event) { |
| 53 | synchronized (ConnectionStat.class) { |
| 54 | |
| 55 | if (event instanceof ConnectionEndEvent) { |
| 56 | ConnectionEndEvent evt = (ConnectionEndEvent) event; |
| 57 | |
| 58 | ConnectionStatData data = new ConnectionStatData(statPath); |
| 59 | |
| 60 | ConnectionStatData.ConnectionStatDataElement current; |
| 61 | |
| 62 | List<ConnectionStatData.ConnectionStatDataElement> elements = data.load(); |
| 63 | |
| 64 | int pos = data.findPos(evt.getAddress(), elements); |
| 65 | if (pos == -1) { |
| 66 | current = new ConnectionStatData.ConnectionStatDataElement(); |
| 67 | current.linkStr = evt.getAddress() != null ? evt.getAddress().toString() : null; |
| 68 | } else { |
| 69 | current = elements.get(pos); |
| 70 | } |
| 71 | |
| 72 | if (evt.isIncoming()) { |
| 73 | if (evt.isSuccess()) { |
| 74 | current.incomingOk++; |
| 75 | } else { |
| 76 | current.incomingFailed++; |
| 77 | } |
| 78 | } else { |
| 79 | if (evt.isSuccess()) { |
| 80 | current.outgoingOk++; |
| 81 | } else { |
| 82 | current.outgoingFailed++; |
| 83 | } |
| 84 | } |
| 85 | current.bytesReceived += evt.getBytesReceived(); |
| 86 | current.bytesSended += evt.getBytesSended(); |
| 87 | |
| 88 | data.store(evt.getAddress(), current); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public String getSubject() { |
| 95 | return "Daily connection stat"; |
| 96 | } |
| 97 | |
| 98 | public static String getText(String path, boolean reset){ |
nothing calls this directly
no test coverage detected