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 final ListenerRegistration<L> d = delegate;
43 return d == null ? null : (L)d.getInstance();
47 public synchronized void close() {
50 if (delegate != null) {