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=8d73bc6155d2c664ba6448a1085bbf85850d9606;hb=cc7ef3a4cc3eb2027be5558c1564e580fd153087;hp=8eb595df03856decab3259ddfaa13a9fc96fd670;hpb=608760751ce7fcf4e84e86a8b33d43bc1d9984d6;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 8eb595df03..8d73bc6155 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * 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, @@ -7,49 +7,54 @@ */ package org.opendaylight.controller.cluster.datastore; -import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; +import java.util.EventListener; +import javax.annotation.concurrent.GuardedBy; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -final class DelayedListenerRegistration implements - ListenerRegistration>> { +abstract class DelayedListenerRegistration implements ListenerRegistration { + private final M registrationMessage; + private volatile ListenerRegistration delegate; - private volatile boolean closed; + @GuardedBy("this") + private boolean closed; - private final RegisterChangeListener registerChangeListener; - - private volatile ListenerRegistration>> delegate; - - DelayedListenerRegistration(final RegisterChangeListener registerChangeListener) { - this.registerChangeListener = registerChangeListener; + protected DelayedListenerRegistration(M registrationMessage) { + this.registrationMessage = registrationMessage; } - void setDelegate( final ListenerRegistration>> registration) { - this.delegate = registration; + M getRegistrationMessage() { + return registrationMessage; } - boolean isClosed() { - return closed; + ListenerRegistration getDelegate() { + return delegate; } - RegisterChangeListener getRegisterChangeListener() { - return registerChangeListener; + synchronized > void createDelegate( + final LeaderLocalDelegateFactory factory) { + if (!closed) { + this.delegate = factory.createDelegate(registrationMessage); + } } @Override - public AsyncDataChangeListener> getInstance() { - return delegate != null ? delegate.getInstance() : null; + public L 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 void close() { - closed = true; - if(delegate != null) { - delegate.close(); + public synchronized void close() { + if (!closed) { + closed = true; + if (delegate != null) { + delegate.close(); + } } } -} \ No newline at end of file +}