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 com.google.common.base.Optional;
11 import java.util.EventListener;
12 import java.util.Map.Entry;
13 import javax.annotation.concurrent.GuardedBy;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
17 abstract class DelayedListenerRegistration<L extends EventListener, M> implements ListenerRegistration<L> {
18 private final M registrationMessage;
19 private volatile ListenerRegistration<L> delegate;
22 private boolean closed;
24 protected DelayedListenerRegistration(M registrationMessage) {
25 this.registrationMessage = registrationMessage;
28 M getRegistrationMessage() {
29 return registrationMessage;
32 ListenerRegistration<L> getDelegate() {
36 synchronized <R extends ListenerRegistration<L>> void createDelegate(
37 final LeaderLocalDelegateFactory<M, R, Optional<DataTreeCandidate>> factory) {
39 final Entry<R, Optional<DataTreeCandidate>> res = factory.createDelegate(registrationMessage);
40 this.delegate = res.getKey();
45 public L getInstance() {
46 final ListenerRegistration<L> d = delegate;
47 return d == null ? null : (L)d.getInstance();
51 public synchronized void close() {
54 if (delegate != null) {