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.collector;
23
24 import access.getstatus.conversation.StatusCompleteContributorEvent;
25 import org.bitrepository.client.eventhandler.EventHandler;
26 import org.bitrepository.client.eventhandler.OperationEvent;
27 import org.bitrepository.monitoringservice.alarm.MonitorAlerter;
28 import org.bitrepository.monitoringservice.status.StatusStore;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33 * The eventhandler for handling the events by the GetStatusClient.
34 */
35 public class GetStatusEventHandler implements EventHandler {
36 /** The log.*/
37 private final Logger log = LoggerFactory.getLogger(GetStatusEventHandler.class);
38 /** The store for the status results. */
39 private final StatusStore statusStore;
40 /** The alarm dispatcher*/
41 private final MonitorAlerter alerter;
42
43 /**
44 * Constructor.
45 * @param statusStore The store for the status results.
46 * @param alarmDispatcher The alarm dispatcher.
47 */
48 public GetStatusEventHandler(StatusStore statusStore, MonitorAlerter alarmDispatcher) {
49 this.statusStore = statusStore;
50 this.alerter = alarmDispatcher;
51 }
52
53 @Override
54 public void handleEvent(OperationEvent event) {
55 log.debug("Got event: " + event);
56
57 switch(event.getEventType()) {
58 case COMPONENT_COMPLETE:
59 StatusCompleteContributorEvent statusEvent = (StatusCompleteContributorEvent) event;
60 statusStore.updateStatus(statusEvent.getContributorID(), statusEvent.getStatus());
61 break;
62 case COMPLETE:
63 alerter.checkStatuses();
64 break;
65 case FAILED:
66 alerter.checkStatuses();
67 break;
68 default:
69 break;
70 }
71 }
72 }