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
8 package org.opendaylight.controller.config.manager.impl.jmx;
10 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
11 import org.opendaylight.controller.config.manager.impl.jmx.InternalJMXRegistrator.InternalJMXRegistration;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
16 public interface ServiceReferenceRegistrator extends AutoCloseable {
18 public String getNullableTransactionName();
20 ServiceReferenceJMXRegistration registerMBean(ServiceReferenceMXBeanImpl object,
21 ObjectName on) throws InstanceAlreadyExistsException;
26 public static class ServiceReferenceJMXRegistration implements AutoCloseable {
27 private final InternalJMXRegistration registration;
29 ServiceReferenceJMXRegistration(InternalJMXRegistration registration) {
30 this.registration = registration;
39 public static interface ServiceReferenceTransactionRegistratorFactory {
40 public ServiceReferenceRegistrator create();
43 public static class ServiceReferenceRegistratorImpl implements ServiceReferenceRegistrator {
44 private final InternalJMXRegistrator currentJMXRegistrator;
45 private final String nullableTransactionName;
47 public ServiceReferenceRegistratorImpl(NestableJMXRegistrator parentRegistrator, String nullableTransactionName){
48 currentJMXRegistrator = parentRegistrator.createChild();
49 this.nullableTransactionName = nullableTransactionName;
52 public String getNullableTransactionName() {
53 return nullableTransactionName;
57 public ServiceReferenceJMXRegistration registerMBean(ServiceReferenceMXBeanImpl object,
58 ObjectName on) throws InstanceAlreadyExistsException {
59 String actualTransactionName = ObjectNameUtil.getTransactionName(on);
60 boolean broken = false;
61 broken |= (nullableTransactionName == null) != (actualTransactionName == null);
62 broken |= (nullableTransactionName != null) && nullableTransactionName.equals(actualTransactionName) == false;
64 throw new IllegalArgumentException("Transaction name mismatch between expected "
65 + nullableTransactionName + ", got " + actualTransactionName + " in " + on);
67 if (ObjectNameUtil.isServiceReference(on) == false) {
68 throw new IllegalArgumentException("Invalid type of " + on);
70 return new ServiceReferenceJMXRegistration(currentJMXRegistrator.registerMBean(object, on));
76 currentJMXRegistrator.close();
78 public static interface ServiceReferenceTransactionRegistratorFactory {
79 public ServiceReferenceRegistrator create();
84 public static class ServiceReferenceTransactionRegistratorFactoryImpl implements ServiceReferenceTransactionRegistratorFactory {
85 private final NestableJMXRegistrator parentRegistrator;
86 private final String nullableTransactionName;
88 public ServiceReferenceTransactionRegistratorFactoryImpl(TransactionModuleJMXRegistrator parentRegistrator,
89 String nullableTransactionName) {
90 this.parentRegistrator = parentRegistrator;
91 this.nullableTransactionName = nullableTransactionName;
94 public ServiceReferenceTransactionRegistratorFactoryImpl(BaseJMXRegistrator baseJMXRegistrator) {
95 this.parentRegistrator = baseJMXRegistrator;
96 this.nullableTransactionName = null;
99 public ServiceReferenceRegistrator create() {
100 return new ServiceReferenceRegistratorImpl(parentRegistrator, nullableTransactionName);