<configuration>
<instructions>
<Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
- <Bundle-Activator>org.opendaylight.controller.cluster.datastore.osgi.Activator</Bundle-Activator>
<Export-Package>
org.opendaylight.controller.cluster.datastore;
org.opendaylight.controller.cluster.datastore.config;
private final String restoreDirectoryPath;
private final Map<String, DatastoreSnapshot> datastoreSnapshots = new ConcurrentHashMap<>();
- public static void createInstance(String restoreDirectoryPath) {
+ public static DatastoreSnapshotRestore instance(String restoreDirectoryPath) {
instance.compareAndSet(null, new DatastoreSnapshotRestore(restoreDirectoryPath));
- }
-
- public static void removeInstance() {
- instance.set(null);
- }
-
- public static DatastoreSnapshotRestore instance() {
- DatastoreSnapshotRestore localInstance = instance.get();
- return Preconditions.checkNotNull(localInstance, "DatastoreSnapshotRestore instance was not created");
+ return instance.get();
}
private DatastoreSnapshotRestore(String restoreDirectoryPath) {
this.restoreDirectoryPath = Preconditions.checkNotNull(restoreDirectoryPath);
}
- // sychronize this method so that, in case of concurrent access to getAndRemove(),
+ // synchronize this method so that, in case of concurrent access to getAndRemove(),
// no one ends up with partially initialized data
private synchronized void initialize() {
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.datastore.osgi;
-
-import org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * Activator for the bundle.
- *
- * @author Thomas Pantelis
- */
-public class Activator implements BundleActivator {
- private static final String RESTORE_DIRECTORY_PATH = "./clustered-datastore-restore";
-
- @Override
- public void start(BundleContext context) {
- DatastoreSnapshotRestore.createInstance(RESTORE_DIRECTORY_PATH);
- }
-
- @Override
- public void stop(BundleContext context) {
- DatastoreSnapshotRestore.removeInstance();
- }
-}
<!-- Distributed Config Datastore -->
<bean id="datastoreSnapshotRestore" class="org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore"
- factory-method="instance" />
+ factory-method="instance">
+ <argument value="./clustered-datastore-restore"/>
+ </bean>
<bean id="configDatastoreContext" class="org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule"
factory-method="newDatastoreContext" />
SerializationUtils.serialize(snapshotList, fos);
}
- DatastoreSnapshotRestore.createInstance(restoreDirectoryPath);
+ DatastoreSnapshotRestore instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
- verifySnapshot(configSnapshot, DatastoreSnapshotRestore.instance().getAndRemove("config"));
- verifySnapshot(operSnapshot, DatastoreSnapshotRestore.instance().getAndRemove("oper"));
+ verifySnapshot(configSnapshot, instance.getAndRemove("config"));
+ verifySnapshot(operSnapshot, instance.getAndRemove("oper"));
- assertNull("DatastoreSnapshot was not removed", DatastoreSnapshotRestore.instance().getAndRemove("config"));
+ assertNull("DatastoreSnapshot was not removed", instance.getAndRemove("config"));
assertFalse(backupFile + " was not deleted", backupFile.exists());
- DatastoreSnapshotRestore.removeInstance();
- DatastoreSnapshotRestore.createInstance("target/does-not-exist");
- assertNull("Expected null DatastoreSnapshot", DatastoreSnapshotRestore.instance().getAndRemove("config"));
- assertNull("Expected null DatastoreSnapshot", DatastoreSnapshotRestore.instance().getAndRemove("oper"));
+ instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
+ assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("config"));
+ assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("oper"));
}
private static void verifySnapshot(DatastoreSnapshot expected, DatastoreSnapshot actual) {