Migrate Queue stats collection
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / concurrent / QueuedNotificationManagerMXBeanImpl.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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 package org.opendaylight.yangtools.util.concurrent;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.List;
13 import java.util.stream.Collectors;
14
15 final class QueuedNotificationManagerMXBeanImpl implements QueuedNotificationManagerMXBean {
16     private final AbstractQueuedNotificationManager<?, ?, ?> manager;
17
18     QueuedNotificationManagerMXBeanImpl(final AbstractQueuedNotificationManager<?, ?, ?> manager) {
19         this.manager = requireNonNull(manager);
20     }
21
22     /**
23      * Returns a list of stat instances for each current listener notification task in progress.
24      */
25     @Override
26     public List<ListenerNotificationQueueStats> getCurrentListenerQueueStats() {
27         return manager.streamTasks().map(t -> new ListenerNotificationQueueStats(t.key().toString(), t.size()))
28                 .collect(Collectors.toList());
29     }
30
31     /**
32      * Returns the configured maximum listener queue size.
33      */
34     @Override
35     public int getMaxListenerQueueSize() {
36         return manager.getMaxQueueCapacity();
37     }
38 }