Clean all unused and redundant imports in controller.
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / BlankTransactionServiceTracker.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.osgi;
9
10 import org.opendaylight.controller.config.api.jmx.CommitStatus;
11 import org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl;
12 import org.opendaylight.controller.config.spi.ModuleFactory;
13 import org.osgi.framework.ServiceReference;
14 import org.osgi.util.tracker.ServiceTrackerCustomizer;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import javax.management.ObjectName;
19
20 /**
21  * Every time factory is added or removed, blank transaction is triggered to handle
22  * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory)}
23  * functionality.
24  */
25 public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<ModuleFactory, Object> {
26     private static final Logger logger = LoggerFactory.getLogger(BlankTransactionServiceTracker.class);
27
28     private final ConfigRegistryImpl configRegistry;
29
30     public BlankTransactionServiceTracker(ConfigRegistryImpl configRegistry) {
31         this.configRegistry = configRegistry;
32     }
33
34     @Override
35     public Object addingService(ServiceReference<ModuleFactory> moduleFactoryServiceReference) {
36         blankTransaction();
37         return null;
38     }
39
40     private void blankTransaction() {
41         // create transaction
42         ObjectName tx = configRegistry.beginConfig();
43         CommitStatus commitStatus = configRegistry.commitConfig(tx);
44         logger.debug("Committed blank transaction with status {}", commitStatus);
45     }
46
47     @Override
48     public void modifiedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {
49         blankTransaction();
50     }
51
52     @Override
53     public void removedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {
54         blankTransaction();
55     }
56 }