Remove yang-test
[controller.git] / opendaylight / config / config-api / src / main / java / org / opendaylight / controller / config / api / DependencyResolver.java
1 /*
2  * Copyright (c) 2013, 2017 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 service interface of dependent
30      * module.
31      *
32      * @param expectedServiceInterface
33      *            MBean/MXBean interface which will back the proxy object.
34      * @param objectName
35      *            ObjectName of dependent module without transaction name
36      *            (platformON).
37      * @param jmxAttribute
38      *            for reporting
39      * @throws IllegalArgumentException
40      *             when module is not found
41      * @throws IllegalStateException
42      *             if module does not export this service interface.
43      */
44     void validateDependency(Class<? extends AbstractServiceInterface> expectedServiceInterface, ObjectName objectName,
45             JmxAttribute jmxAttribute);
46
47     /**
48      * To be used during commit phase to wire actual dependencies.
49      *
50      * @return dependency instance using
51      *         {@link org.opendaylight.controller.config.spi.Module#getInstance()}
52      * @throws IllegalArgumentException
53      *             when module is not found
54      */
55     <T> T resolveInstance(Class<T> expectedType, ObjectName objectName, JmxAttribute jmxAttribute);
56
57     /**
58      * To be used during commit phase to resolve identity-ref config attributes.
59      *
60      * @return actual class object generated from identity
61      */
62     <T extends BaseIdentity> Class<? extends T> resolveIdentity(IdentityAttributeRef identityRef,
63             Class<T> expectedBaseClass);
64
65     /**
66      * Validate identity-ref config attribute.
67      */
68     <T extends BaseIdentity> void validateIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass,
69             JmxAttribute jmxAttribute);
70
71     /**
72      * Can be used during validation or commit phase to get attribute value of
73      * dependent module.
74      *
75      * @param name
76      *            either direct ObjectName of a Module (type=Module) or service
77      *            reference (type=ServiceReference) of dependent Module
78      * @param attribute
79      *            String identifying attribute name in JMX. Note that attributes
80      *            start with upper case. See
81      *            {@link org.opendaylight.controller.config.api.JmxAttribute#getAttributeName()}
82      */
83     Object getAttribute(ObjectName name, String attribute)
84             throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException;
85
86     /**
87      * Helper method around.
88      * {@link javax.management
89      * .JMX#newMXBeanProxy(javax.management.MBeanServerConnection, javax.management.ObjectName, Class)}}.
90      *
91      * Returns MXBean proxy for dependent module. Can be used during validation or
92      * commit phase to inspect dependent module's attributes.
93      *
94      * @param objectName
95      *            either direct ObjectName of a Module (type=Module) or service
96      *            reference (type=ServiceReference) of dependent Module
97      * @param interfaceClass
98      *            MXBean interface to be used as a proxy
99      * @param <T>
100      *            type of proxy for type safe return value
101      * @return instance of MXBean proxy
102      */
103     <T> T newMXBeanProxy(ObjectName objectName, Class<T> interfaceClass);
104
105     /**
106      * Check whether a dependency will be reused or (re)created. Useful when
107      * deciding if current module could be also reused.
108      *
109      * @param objectName
110      *            ObjectName ID of a dependency
111      * @param jmxAttribute
112      *            JMXAttribute ID of a dependency
113      * @return true if the dependency will be reused false otherwise
114      */
115     boolean canReuseDependency(ObjectName objectName, JmxAttribute jmxAttribute);
116 }