2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.manager.impl.osgi;
10 import org.opendaylight.controller.config.api.ConflictingVersionException;
11 import org.opendaylight.controller.config.api.ValidationException;
12 import org.opendaylight.controller.config.api.jmx.CommitStatus;
13 import org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl;
14 import org.opendaylight.controller.config.spi.ModuleFactory;
15 import org.osgi.framework.ServiceReference;
16 import org.osgi.util.tracker.ServiceTrackerCustomizer;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import javax.management.ObjectName;
23 * Every time factory is added or removed, blank transaction is triggered to handle
24 * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory, org.osgi.framework.BundleContext)}
27 public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<ModuleFactory, Object> {
28 private static final Logger logger = LoggerFactory.getLogger(BlankTransactionServiceTracker.class);
30 private final ConfigRegistryImpl configRegistry;
32 public BlankTransactionServiceTracker(ConfigRegistryImpl configRegistry) {
33 this.configRegistry = configRegistry;
37 public Object addingService(ServiceReference<ModuleFactory> moduleFactoryServiceReference) {
42 synchronized void blankTransaction() {
43 // race condition check: config-persister might push new configuration while server is starting up.
44 ConflictingVersionException lastException = null;
46 for (int i = 0; i < maxAttempts; i++) {
49 boolean blankTransaction = true;
50 ObjectName tx = configRegistry.beginConfig(blankTransaction);
51 CommitStatus commitStatus = configRegistry.commitConfig(tx);
52 logger.debug("Committed blank transaction with status {}", commitStatus);
54 } catch (ConflictingVersionException e) {
58 } catch (InterruptedException interruptedException) {
59 Thread.currentThread().interrupt();
60 throw new IllegalStateException(interruptedException);
62 } catch (ValidationException e) {
63 logger.error("Validation exception while running blank transaction indicates programming error", e);
64 throw new RuntimeException("Validation exception while running blank transaction indicates programming error", e);
67 throw new RuntimeException("Maximal number of attempts reached and still cannot get optimistic lock from " +
68 "config manager",lastException);
72 public void modifiedService(ServiceReference <ModuleFactory> moduleFactoryServiceReference, Object o) {
77 public void removedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {