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