@@ -0,0 +1,2263 @@
+package org.bitrepository.monitoringservice;%0A%0Aimport java.math.BigInteger;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.bitrepository.common.settings.Settings;%0Aimport org.bitrepository.protocol.messagebus.MessageSender;%0A%0A/**%0A * Class for the monitoring service keep a watch on non responding components, and send alarms if needed.%0A */%0Apublic class MonitoringServiceAlerter %7B%0A%0A%09private final MessageSender messageSender;%0A%09private final Settings settings;%0A%09private final BigInteger maxRetries;%09%0A%09private final Map%3CString, Integer%3E expectedContributors;%0A%09%0A%09public MonitoringServiceAlerter(Settings settings, MessageSender messageSender) %7B%0A%09%09this.settings = settings;%0A%09%09this.messageSender = messageSender;%0A%09%09expectedContributors = new HashMap%3CString, Integer%3E(%0A%09%09%09%09settings.getCollectionSettings().getGetStatusSettings().getContributorIDs().size());%0A%09%09for(String ID : settings.getCollectionSettings().getGetStatusSettings().getContributorIDs()) %7B%0A%09%09%09expectedContributors.put(ID, 0);%0A%09%09%7D%0A%09%09maxRetries = settings.getReferenceSettings().getMonitoringServiceSettings().getMaxRetries();%0A%09%7D%0A%09%0A%09/**%0A%09 *  Method to reload counters when status is requested.%0A%09 */%0A%09public void reload() %7B%0A%09%09for(String ID : expectedContributors.keySet()) %7B%0A%09%09%09Integer i = expectedContributors.get(ID);%0A%09%09%09i++; %0A%09%09%09expectedContributors.put(ID, i);%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * A component has responded, reset it's not responding count. %0A%09 */%0A%09public void checkInComponent(String componentID) %7B%0A%09%09if(!expectedContributors.containsKey(componentID)) %7B%0A%09%09%09//log unexpected contributor%0A%09%09%09return ;%0A%09%09%7D else %7B%0A%09%09%09expectedContributors.put(componentID, 0);%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * Check for components that have not responded withing the given constraints, and send alarm%0A%09 * message if there is any. %0A%09 */%0A%09public void checkNonRespondingAndSendAlarm() %7B%0A%09%09List%3CString%3E nonRespondingComponents = new ArrayList%3CString%3E();%0A%09%09for(String ID : expectedContributors.keySet()) %7B%0A%09%09%09if(expectedContributors.get(ID) == maxRetries.intValue()) %7B%0A%09%09%09%09nonRespondingComponents.add(ID);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if(!nonRespondingComponents.isEmpty()) %7B%0A%09%09%09sendAlarm(nonRespondingComponents);%0A%09%09%7D%0A%09%7D%0A%09%0A%09private void sendAlarm(List%3CString%3E components) %7B%0A%09%09//Erhm, send alarm...%0A%09%7D%0A%09%0A%7D%0A

Add begining of alarm sending in monitoring service