2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.threadpool.util;
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;
22 * Closeable version of {@link AsyncEventBus}.
24 public class CloseableAsyncEventBus extends AsyncEventBus implements Closeable {
25 private final ThreadPool threadPool;
26 private final AsyncEventBusRuntimeRegistration rootRegistration;
28 public CloseableAsyncEventBus(String identifier, ThreadPool threadPool,
29 AsyncEventBusRuntimeRegistrator rootRegistrator) {
30 super(identifier, threadPool.getExecutor());
31 this.threadPool = threadPool;
32 rootRegistration = rootRegistrator.register(new AsyncEventBusRuntimeMXBean() {
33 private long deadEventsCounter = 0;
36 public void increaseDeadEvents(DeadEvent deadEvent) {
41 public Long countDeadEvents() {
42 return deadEventsCounter;
48 public ThreadPool getThreadPool() {
53 public void close() throws IOException {
54 rootRegistration.close();