1 /*
2 * #%L
3 * Bitrepository Monitoring Service
4 * %%
5 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 2.1 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Lesser Public License for more details.
16 *
17 * You should have received a copy of the GNU General Lesser Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20 * #L%
21 */
22 package org.bitrepository.monitoringservice.status;
23
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.concurrent.ConcurrentHashMap;
27 import java.util.concurrent.ConcurrentMap;
28
29 import org.bitrepository.bitrepositoryelements.ResultingStatus;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34 * Storage for the status of the different components.
35 */
36 public class ComponentStatusStore implements StatusStore {
37 /** The log.*/
38 private Logger log = LoggerFactory.getLogger(getClass());
39 /** The mapping between components and their respective status.*/
40 private final ConcurrentMap<String, ComponentStatus> statusMap;
41
42 /**
43 * Constructor.
44 * @param components The components whose status are to be stored in this store.
45 */
46 public ComponentStatusStore(Set<String> components) {
47 statusMap = new ConcurrentHashMap<String, ComponentStatus>();
48 for(String component : components) {
49 statusMap.put(component, new ComponentStatus());
50 }
51 }
52
53 @Override
54 public synchronized void updateStatus(String componentID, ResultingStatus status) {
55 if(statusMap.containsKey(componentID)) {
56 statusMap.get(componentID).updateStatus(status);
57 } else {
58 log.warn("Got status from an unexpected component: " + componentID);
59 }
60 }
61
62 @Override
63 public synchronized void updateReplyCounts() {
64 for(String ID : statusMap.keySet()) {
65 statusMap.get(ID).updateReplys();
66 }
67 }
68
69 @Override
70 public synchronized Map<String, ComponentStatus> getStatusMap() {
71 return statusMap;
72 }
73 }