import com.google.common.base.Function;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Collection;
import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public void setDataBroker(final DataBroker dataBroker) {
this.dataBroker = dataBroker;
- dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(CONFIGURATION, TOASTER_IID), this);
+ }
+
+ public void init() {
+ LOG.info("Initializing...");
+
+ Preconditions.checkNotNull(dataBroker, "dataBroker must be set");
+ dataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
+ new DataTreeIdentifier<>(CONFIGURATION, TOASTER_IID), this);
setToasterStatusUp(null);
+
+ // Register our MXBean.
+ register();
}
/**
* Implemented from the AutoCloseable interface.
*/
@Override
- public void close() throws ExecutionException, InterruptedException {
+ public void close() {
+ LOG.info("Closing...");
+
+ // Unregister our MXBean.
+ unregister();
+
// When we close this service we need to shutdown our executor!
executor.shutdown();
- if (dataBroker != null) {
+ if (dataTreeChangeListenerRegistration != null) {
dataTreeChangeListenerRegistration.close();
+ }
+ if (dataBroker != null) {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.delete(OPERATIONAL,TOASTER_IID);
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
- LOG.debug("Delete Toaster commit result: " + result);
+ LOG.debug("Successfully deleted the operational Toaster");
}
@Override
public void onFailure(final Throwable failure) {
- LOG.error("Delete of Toaster failed", failure);
+ LOG.error("Delete of the operational Toaster failed", failure);
}
});
}
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
+ LOG.info("Successfully set ToasterStatus to Up");
notifyCallback(true);
}
import com.google.common.base.Optional;
import java.util.concurrent.Future;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-public class OpenDaylightToasterTest extends AbstractDataBrokerTest {
+public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest {
private static InstanceIdentifier<Toaster> TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build();
- OpendaylightToaster toaster;
+ private OpendaylightToaster toaster;
- @Override
- protected void setupWithDataBroker(DataBroker dataBroker) {
+ @Before
+ public void setupToaster() {
toaster = new OpendaylightToaster();
- toaster.setDataBroker(dataBroker);
+ toaster.setDataBroker(getDataBroker());
+ toaster.init();
- /**
- * Doesn't look like we have support for the NotificationProviderService yet, so mock it
- * for now.
- */
+ // We'll mock the NotificationProviderService.
NotificationPublishService mockNotification = mock(NotificationPublishService.class);
toaster.setNotificationProvider(mockNotification);
}