Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / jmx / TransactionModuleJMXRegistrator.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 package org.opendaylight.controller.config.manager.impl.jmx;
9
10 import java.io.Closeable;
11 import java.util.Set;
12 import javax.management.InstanceAlreadyExistsException;
13 import javax.management.ObjectName;
14 import javax.management.QueryExp;
15 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
16
17 public class TransactionModuleJMXRegistrator implements Closeable, NestableJMXRegistrator {
18     private final InternalJMXRegistrator currentJMXRegistrator;
19     private final String transactionName;
20
21     public TransactionModuleJMXRegistrator(
22             final InternalJMXRegistrator internalJMXRegistrator,
23             final String transactionName) {
24         this.currentJMXRegistrator = internalJMXRegistrator.createChild();
25         this.transactionName = transactionName;
26     }
27
28     public static class TransactionModuleJMXRegistration implements
29             AutoCloseable {
30         private final InternalJMXRegistration registration;
31
32         TransactionModuleJMXRegistration(final InternalJMXRegistration registration) {
33             this.registration = registration;
34         }
35
36         @Override
37         public void close() {
38             registration.close();
39         }
40     }
41
42     public TransactionModuleJMXRegistration registerMBean(final Object object,
43             final ObjectName on) throws InstanceAlreadyExistsException {
44         if (!transactionName.equals(ObjectNameUtil.getTransactionName(on))) {
45             throw new IllegalArgumentException("Transaction name mismatch between expected "
46                             + transactionName + " " + "and " + on);
47         }
48         ObjectNameUtil.checkTypeOneOf(on, ObjectNameUtil.TYPE_MODULE);
49         return new TransactionModuleJMXRegistration(
50                 currentJMXRegistrator.registerMBean(object, on));
51     }
52
53     public Set<ObjectName> queryNames(final ObjectName name, final QueryExp query) {
54         return currentJMXRegistrator.queryNames(name, query);
55     }
56
57     @Override
58     public void close() {
59         currentJMXRegistrator.close();
60     }
61
62     public String getTransactionName() {
63         return transactionName;
64     }
65
66     @Override
67     public InternalJMXRegistrator createChild() {
68         return currentJMXRegistrator.createChild();
69     }
70 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.