X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDelayedListenerRegistration.java;h=b0024153d37603a072cd002f9158051ddcf19ac9;hb=4447f81c26b851e46acd3f111768bb498f0d553f;hp=ac132721c5dcc9954a152f0fcc5d1a94787e0fe5;hpb=013a6679470bf692753f2e04ab4398c97fd9f5d0;p=controller.git 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 ac132721c5..b0024153d3 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,49 +7,46 @@ */ package org.opendaylight.controller.cluster.datastore; +import akka.actor.ActorRef; import java.util.EventListener; import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.controller.cluster.datastore.messages.ListenerRegistrationMessage; import org.opendaylight.yangtools.concepts.ListenerRegistration; -abstract class DelayedListenerRegistration implements ListenerRegistration { +abstract class DelayedListenerRegistration + implements ListenerRegistration { private final M registrationMessage; - private volatile ListenerRegistration delegate; + private final ActorRef registrationActor; @GuardedBy("this") private boolean closed; - protected DelayedListenerRegistration(M registrationMessage) { + protected DelayedListenerRegistration(M registrationMessage, ActorRef registrationActor) { this.registrationMessage = registrationMessage; + this.registrationActor = registrationActor; } M getRegistrationMessage() { return registrationMessage; } - ListenerRegistration getDelegate() { - return delegate; - } - - synchronized > void createDelegate( - final LeaderLocalDelegateFactory factory) { + synchronized void createDelegate(final AbstractDataListenerSupport support) { if (!closed) { - this.delegate = factory.createDelegate(registrationMessage); + support.doRegistration(registrationMessage, registrationActor); } } @Override public L getInstance() { - final ListenerRegistration d = delegate; - return d == null ? null : (L)d.getInstance(); + // We could return null if the delegate is not set yet. In reality though, we do not and should not ever call + // this method on DelayedListenerRegistration instances but, since we have to provide an implementation to + // satisfy the interface, we throw UnsupportedOperationException to avoid 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; } }