Fix duplicate dependency warnings
[controller.git] / opendaylight / config / threadpool-config-impl / src / main / java / org / opendaylight / controller / config / threadpool / util / CloseableAsyncEventBus.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.AsyncEventBus;
12 import com.google.common.eventbus.DeadEvent;
13 import com.google.common.eventbus.Subscribe;
14
15 import java.io.Closeable;
16 import java.io.IOException;
17
18 import org.opendaylight.controller.config.threadpool.ThreadPool;
19 import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeMXBean;
20 import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeRegistration;
21 import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeRegistrator;
22
23 /**
24  * Closeable version of {@link AsyncEventBus}.
25  */
26 public class CloseableAsyncEventBus extends AsyncEventBus implements Closeable {
27     private final ThreadPool threadPool;
28     private final AsyncEventBusRuntimeRegistration rootRegistration;
29
30     public CloseableAsyncEventBus(String identifier, ThreadPool threadPool,
31             AsyncEventBusRuntimeRegistrator rootRegistrator) {
32         super(identifier, threadPool.getExecutor());
33         this.threadPool = threadPool;
34         rootRegistration = rootRegistrator.register(new AsyncEventBusRuntimeMXBean() {
35             private long deadEventsCounter = 0;
36
37             @Subscribe
38             public void increaseDeadEvents(DeadEvent deadEvent) {
39                 deadEventsCounter++;
40             }
41
42             @Override
43             public Long countDeadEvents() {
44                 return deadEventsCounter;
45             }
46
47         });
48     }
49
50     public ThreadPool getThreadPool() {
51         return threadPool;
52     }
53
54     @Override
55     public void close() throws IOException {
56         rootRegistration.close();
57     }
58
59 }