Bug-2827: role switch proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / openflow / common / config / impl / rev140326 / ConfigurableOpenFlowProviderModule.java
1 /**
2 * Generated file
3
4 * Generated from: yang module name: openflow-provider-impl  yang module local name: openflow-provider-impl
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Wed Apr 02 16:59:36 PDT 2014
7 *
8 * Do not modify this file unless it is present under src/main directory
9 */
10 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326;
11
12 import javax.management.ObjectName;
13
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
15
16 import com.google.common.base.MoreObjects;
17
18 /**
19 *
20 */
21 public final class ConfigurableOpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.AbstractConfigurableOpenFlowProviderModule {
22
23     private OpenflowPluginProvider pluginProvider;
24
25     /**
26      * @param identifier
27      * @param dependencyResolver
28      */
29     public ConfigurableOpenFlowProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
30         super(identifier, dependencyResolver);
31     }
32
33     /**
34      * @param identifier
35      * @param dependencyResolver
36      * @param oldModule
37      * @param oldInstance
38      */
39     public ConfigurableOpenFlowProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
40             ConfigurableOpenFlowProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
41
42         super(identifier, dependencyResolver, oldModule, oldInstance);
43     }
44
45     @Override
46     protected void customValidation() {
47         // Add custom validation for module attributes here.
48     }
49
50     @Override
51     public java.lang.AutoCloseable createInstance() {
52         pluginProvider =  new OpenflowPluginProvider();
53         pluginProvider.setBroker(getBindingAwareBrokerDependency());
54         pluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
55         pluginProvider.setRole(getRole());
56         pluginProvider.initialization();
57         return pluginProvider;
58     }
59
60     @Override
61     public boolean canReuseInstance(
62             AbstractConfigurableOpenFlowProviderModule oldModule) {
63         // we can reuse if only the role field changed
64         boolean noChangeExceptRole = true;
65         noChangeExceptRole &= dependencyResolver.canReuseDependency(
66                 getBindingAwareBroker(), bindingAwareBrokerJmxAttribute);
67         for (ObjectName ofSwitchProvider : getOpenflowSwitchConnectionProvider()) {
68             noChangeExceptRole &= dependencyResolver.canReuseDependency(
69                     ofSwitchProvider, openflowSwitchConnectionProviderJmxAttribute); 
70         }
71         return noChangeExceptRole;
72     }
73
74     @Override
75     public AutoCloseable reuseInstance(AutoCloseable oldInstance) {
76         OpenflowPluginProvider recycled = (OpenflowPluginProvider) super.reuseInstance(oldInstance);
77         // change role if different
78         recycled.fireRoleChange(MoreObjects.firstNonNull(getRole(), getRole()));
79
80         return recycled;
81     }
82 }