Bug 1022 - Add ability to lookup dependent Module's attribute.
[controller.git] / opendaylight / config / config-api / src / main / java / org / opendaylight / controller / config / api / DependencyResolver.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.api;
9
10 import javax.management.AttributeNotFoundException;
11 import javax.management.InstanceNotFoundException;
12 import javax.management.MBeanException;
13 import javax.management.ObjectName;
14 import javax.management.ReflectionException;
15 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
16 import org.opendaylight.yangtools.concepts.Identifiable;
17 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
18
19 /**
20  * Each new {@link org.opendaylight.controller.config.spi.Module} can receive
21  * resolver from {@link org.opendaylight.controller.config.spi.ModuleFactory}
22  * for looking up dependencies during validation and second phase commit.
23  *
24  * @see org.opendaylight.controller.config.spi.Module
25  */
26 public interface DependencyResolver extends Identifiable<ModuleIdentifier> {
27
28     /**
29      * To be used during validation phase to validate serice interface of
30      * dependent module.
31      *
32      * @param expectedServiceInterface MBean/MXBean interface which will back the proxy object.
33      * @param objectName               ObjectName of dependent module without transaction name
34      *                                 (platformON).
35      * @param jmxAttribute             for reporting
36      * @throws IllegalArgumentException when module is not found
37      * @throws IllegalStateException    if module does not export this
38      *                                  service interface.
39      */
40     void validateDependency(
41             Class<? extends AbstractServiceInterface> expectedServiceInterface,
42             ObjectName objectName, JmxAttribute jmxAttribute);
43
44     /**
45      * To be used during commit phase to wire actual dependencies.
46      *
47      * @return dependency instance using
48      * {@link org.opendaylight.controller.config.spi.Module#getInstance()}
49      * @throws IllegalArgumentException when module is not found
50      */
51     <T> T resolveInstance(Class<T> expectedType, ObjectName objectName,
52                           JmxAttribute jmxAttribute);
53
54     /**
55      * To be used during commit phase to resolve identity-ref config attributes.
56      *
57      * @return actual class object generated from identity
58      */
59     <T extends BaseIdentity> Class<? extends T> resolveIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass);
60
61
62     /**
63      * Validate identity-ref config attribute.
64      */
65     <T extends BaseIdentity> void validateIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass, JmxAttribute jmxAttribute);
66
67     /**
68      * Can be used during validation or commit phase to get attribute value of dependent module.
69      *
70      * @param name      either direct ObjectName of a Module (type=Module) or service reference (type=ServiceReference) of dependent Module
71      * @param attribute String identifying attribute name in JMX. Note that attributes start with upper case. See {@link org.opendaylight.controller.config.api.JmxAttribute#getAttributeName()}
72      */
73     Object getAttribute(ObjectName name, String attribute)
74             throws MBeanException, AttributeNotFoundException,
75             InstanceNotFoundException, ReflectionException;
76
77
78     /**
79      * Helper method around {@link javax.management.JMX#newMXBeanProxy(javax.management.MBeanServerConnection, javax.management.ObjectName, Class)} }.
80      * Returns MXBean proxy for dependent module. Can be used during validation or commit phase to inspect dependent module's attributes.
81      *
82      * @param objectName either direct ObjectName of a Module (type=Module) or service reference (type=ServiceReference) of dependent Module
83      * @param interfaceClass MXBean interface to be used as a proxy
84      * @param <T> type of proxy for type safe return value
85      * @return instance of MXBean proxy
86      */
87     <T> T newMXBeanProxy(ObjectName objectName, Class<T> interfaceClass);
88
89 }