X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDelayedListenerRegistration.java;h=18d23aa0cd95fb2270d46ebd3a24b30814bbf959;hp=8f18cb74dc79c6cd7cb6c08b03640b9df173dcd8;hb=ec870dee9bacb971f11bc747b69e84ac37f5d746;hpb=6050fd28f2def659abb5bc9d7127eb748b5fb32a diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java index 8f18cb74dc..18d23aa0cd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java @@ -7,53 +7,48 @@ */ package org.opendaylight.controller.cluster.datastore; -import com.google.common.base.Optional; +import akka.actor.ActorRef; import java.util.EventListener; -import java.util.Map.Entry; import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.controller.cluster.datastore.messages.ListenerRegistrationMessage; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -abstract class DelayedListenerRegistration implements ListenerRegistration { - private final R registrationMessage; - private volatile ListenerRegistration delegate; +abstract class DelayedListenerRegistration + implements ListenerRegistration { + private final M registrationMessage; + private final ActorRef registrationActor; @GuardedBy("this") private boolean closed; - protected DelayedListenerRegistration(R registrationMessage) { + protected DelayedListenerRegistration(M registrationMessage, ActorRef registrationActor) { this.registrationMessage = registrationMessage; + this.registrationActor = registrationActor; } - R getRegistrationMessage() { + M getRegistrationMessage() { return registrationMessage; } - ListenerRegistration getDelegate() { - return delegate; - } - - synchronized > void createDelegate( - final LeaderLocalDelegateFactory> factory) { + synchronized void createDelegate(final AbstractDataListenerSupport support) { if (!closed) { - final Entry> res = factory.createDelegate(registrationMessage); - this.delegate = res.getKey(); + support.doRegistration(registrationMessage, registrationActor); } } @Override public L getInstance() { - final ListenerRegistration d = delegate; - return d == null ? null : (L)d.getInstance(); + // ObjectRegistration annotates this method as @Nonnull but we could return null if the delegate is not set yet. + // In reality, we do not and should not ever call this method on DelayedListenerRegistration instances anyway + // but, since we have to provide an implementation to satisfy the interface, we throw + // UnsupportedOperationException to honor the API contract of not returning null and to avoid a FindBugs error + // for possibly returning null. + throw new UnsupportedOperationException( + "getInstance should not be called on this instance since it could be null"); } @Override public synchronized void close() { - if (!closed) { - closed = true; - if (delegate != null) { - delegate.close(); - } - } + closed = true; } }