2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore;
10 import java.util.EventListener;
11 import javax.annotation.concurrent.GuardedBy;
12 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 abstract class DelayedListenerRegistration<L extends EventListener, M> implements ListenerRegistration<L> {
15 private final M registrationMessage;
16 private volatile ListenerRegistration<L> delegate;
19 private boolean closed;
21 protected DelayedListenerRegistration(M registrationMessage) {
22 this.registrationMessage = registrationMessage;
25 M getRegistrationMessage() {
26 return registrationMessage;
29 ListenerRegistration<L> getDelegate() {
33 synchronized <R extends ListenerRegistration<L>> void createDelegate(
34 final LeaderLocalDelegateFactory<M, R> factory) {
36 this.delegate = factory.createDelegate(registrationMessage);
41 public L getInstance() {
42 // ObjectRegistration annotates this method as @Nonnull but we could return null if the delegate is not set yet.
43 // In reality, we do not and should not ever call this method on DelayedListenerRegistration instances anyway
44 // but, since we have to provide an implementation to satisfy the interface, we throw
45 // UnsupportedOperationException to honor the API contract of not returning null and to avoid a FindBugs error
46 // for possibly returning null.
47 throw new UnsupportedOperationException(
48 "getInstance should not be called on this instance since it could be null");
52 public synchronized void close() {
55 if (delegate != null) {