X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Ftoaster-provider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Ftoaster%2Fprovider%2FOpendaylightToaster.java;h=e475c320d1e11c45258ebb6415083589fcf0302d;hp=a7c9a7818535151b87db7d7f30193ebce6811c10;hb=390c714cdeae2efe67d55d5a401929653b534f5c;hpb=62d2f37a4e9ff4c637ff83e3d9dbbfd292552aaa;ds=sidebyside diff --git a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java index a7c9a78185..e475c320d1 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java @@ -15,6 +15,7 @@ import static org.opendaylight.yangtools.yang.common.RpcError.ErrorType.APPLICAT 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; @@ -22,7 +23,6 @@ import com.google.common.util.concurrent.ListenableFuture; 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; @@ -102,32 +102,49 @@ public class OpendaylightToaster extends AbstractMXBean 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() { @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); } }); } @@ -327,6 +344,7 @@ public class OpendaylightToaster extends AbstractMXBean Futures.addCallback(tx.submit(), new FutureCallback() { @Override public void onSuccess(final Void result) { + LOG.info("Successfully set ToasterStatus to Up"); notifyCallback(true); }