c71c3bb4701c040e825e33807b979a60ff1d6aa3
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / ModuleInternalTransactionalInfo.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.manager.impl;
9
10 import javax.annotation.Nullable;
11
12 import org.opendaylight.controller.config.api.ModuleIdentifier;
13 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
14 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator;
15 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator
16         .TransactionModuleJMXRegistration;
17 import org.opendaylight.controller.config.spi.Module;
18 import org.opendaylight.controller.config.spi.ModuleFactory;
19 import org.opendaylight.protocol.concepts.NamedObject;
20
21 public class ModuleInternalTransactionalInfo implements
22         NamedObject<ModuleIdentifier> {
23     private final ModuleIdentifier name;
24     private final Module module;
25     private final ModuleFactory moduleFactory;
26     @Nullable
27     private final ModuleInternalInfo maybeOldInternalInfo;
28     private final TransactionModuleJMXRegistration transactionModuleJMXRegistration;
29
30     ModuleInternalTransactionalInfo(ModuleIdentifier name, Module module,
31             ModuleFactory moduleFactory,
32             ModuleInternalInfo maybeOldInternalInfo,
33             TransactionModuleJMXRegistration transactionModuleJMXRegistration) {
34         this.name = name;
35         this.module = module;
36         this.moduleFactory = moduleFactory;
37         this.maybeOldInternalInfo = maybeOldInternalInfo;
38         this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
39     }
40
41     @Override
42     public ModuleIdentifier getName() {
43         return name;
44     }
45
46     public boolean hasOldModule() {
47         return maybeOldInternalInfo != null;
48     }
49
50     public DestroyedModule toDestroyedModule() {
51         if (maybeOldInternalInfo == null) {
52             throw new IllegalStateException("Cannot destoy uncommitted module");
53         }
54         DynamicReadableWrapper oldModule = maybeOldInternalInfo
55                 .getReadableModule();
56         return new DestroyedModule(name, oldModule.getInstance(),
57                 maybeOldInternalInfo.getModuleJMXRegistrator(),
58                 maybeOldInternalInfo.getOsgiRegistration(),
59                 maybeOldInternalInfo.getOrderingIdx());
60     }
61
62     public Module getModule() {
63         return module;
64     }
65
66     public ModuleFactory getModuleFactory() {
67         return moduleFactory;
68     }
69
70     @Nullable
71     public ModuleInternalInfo getOldInternalInfo() {
72         if (maybeOldInternalInfo == null)
73             throw new NullPointerException();
74         return maybeOldInternalInfo;
75     }
76
77     public TransactionModuleJMXRegistration getTransactionModuleJMXRegistration() {
78         return transactionModuleJMXRegistration;
79     }
80 }