Merge topic 'archetype'
[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     /**
56      * To be used during commit phase to resolve identity-ref config attributes.
57      *
58      * @return actual class object generated from identity
59      */
60     <T extends BaseIdentity> Class<? extends T> resolveIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass);
61
62
63     /**
64      * Validate identity-ref config attribute.
65      */
66     <T extends BaseIdentity> void validateIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass, JmxAttribute jmxAttribute);
67
68     /**
69      * Can be used during validation or commit phase to get attribute value of dependent module.
70      *
71      * @param name      either direct ObjectName of a Module (type=Module) or service reference (type=ServiceReference) of dependent Module
72      * @param attribute String identifying attribute name in JMX. Note that attributes start with upper case. See {@link org.opendaylight.controller.config.api.JmxAttribute#getAttributeName()}
73      */
74     Object getAttribute(ObjectName name, String attribute)
75             throws MBeanException, AttributeNotFoundException,
76             InstanceNotFoundException, ReflectionException;
77
78
79     /**
80      * Helper method around {@link javax.management.JMX#newMXBeanProxy(javax.management.MBeanServerConnection, javax.management.ObjectName, Class)} }.
81      * Returns MXBean proxy for dependent module. Can be used during validation or commit phase to inspect dependent module's attributes.
82      *
83      * @param objectName either direct ObjectName of a Module (type=Module) or service reference (type=ServiceReference) of dependent Module
84      * @param interfaceClass MXBean interface to be used as a proxy
85      * @param <T> type of proxy for type safe return value
86      * @return instance of MXBean proxy
87      */
88     <T> T newMXBeanProxy(ObjectName objectName, Class<T> interfaceClass);
89
90     /**
91      * Check whether a dependency will be reused or (re)created. Useful when deciding if current module could be also reused.
92      *
93      * @param objectName ObjectName ID of a dependency
94      * @param jmxAttribute JMXAttribute ID of a dependency
95      * @return true if the dependency will be reused false otherwise
96      */
97     boolean canReuseDependency(ObjectName objectName, JmxAttribute jmxAttribute);
98 }