Fix javadoc formatting
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DelayedListenerRegistration.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
10 import akka.actor.ActorRef;
11 import java.util.EventListener;
12 import javax.annotation.concurrent.GuardedBy;
13 import org.opendaylight.controller.cluster.datastore.messages.ListenerRegistrationMessage;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15
16 class DelayedListenerRegistration<L extends EventListener, M extends ListenerRegistrationMessage>
17         implements ListenerRegistration<L> {
18     private final M registrationMessage;
19     private final ActorRef registrationActor;
20
21     @GuardedBy("this")
22     private boolean closed;
23
24     protected DelayedListenerRegistration(M registrationMessage, ActorRef registrationActor) {
25         this.registrationMessage = registrationMessage;
26         this.registrationActor = registrationActor;
27     }
28
29     M getRegistrationMessage() {
30         return registrationMessage;
31     }
32
33     synchronized void doRegistration(final AbstractDataListenerSupport<L, M> support) {
34         if (!closed) {
35             support.doRegistration(registrationMessage, registrationActor);
36         }
37     }
38
39     @Override
40     public L getInstance() {
41         // ObjectRegistration annotates this method as @Nonnull but we could return null if the delegate is not set yet.
42         // In reality, we do not and should not ever call this method on DelayedListenerRegistration instances anyway
43         // but, since we have to provide an implementation to satisfy the interface, we throw
44         // UnsupportedOperationException to honor the API contract of not returning null and to avoid a FindBugs error
45         // for possibly returning null.
46         throw new UnsupportedOperationException(
47                 "getInstance should not be called on this instance since it could be null");
48     }
49
50     @Override
51     public synchronized void close() {
52         closed = true;
53     }
54 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.