ab61bfe723fab79f58c564bd2a6d3ec1dd2b7f6c
[controller.git] / opendaylight / config / threadpool-config-impl / src / main / java / org / opendaylight / controller / config / threadpool / util / CloseableEventBus.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.config.threadpool.util;
10
11 import com.google.common.eventbus.DeadEvent;
12 import com.google.common.eventbus.EventBus;
13 import com.google.common.eventbus.Subscribe;
14 import java.io.Closeable;
15 import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeMXBean;
16 import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeRegistration;
17 import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeRegistrator;
18
19 /**
20  * Closeable {@link EventBus}.
21  */
22 /**
23  * To be removed in Nitrogen
24  */
25 @Deprecated
26 public class CloseableEventBus extends EventBus implements Closeable {
27
28     private final EventBusRuntimeRegistration rootRegistration;
29
30     public CloseableEventBus(String identifier, EventBusRuntimeRegistrator rootRegistrator) {
31         super(identifier);
32         rootRegistration = rootRegistrator.register(new EventBusRuntimeMXBean() {
33             private long deadEventsCounter = 0;
34
35             @Subscribe
36             public void increaseDeadEvents(DeadEvent deadEvent) {
37                 deadEventsCounter++;
38             }
39
40             @Override
41             public Long countDeadEvents() {
42                 return deadEventsCounter;
43             }
44         });
45
46     }
47
48     @Override
49     public void close() {
50         rootRegistration.close();
51
52     }
53 }