740aef92b8d38bf61ab8e59316f20397efd4ace0
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DelayedDataTreeChangeListenerRegistration.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 org.checkerframework.checker.lock.qual.GuardedBy;
12 import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener;
13 import org.opendaylight.yangtools.concepts.Registration;
14
15 class DelayedDataTreeChangeListenerRegistration implements Registration {
16     private final RegisterDataTreeChangeListener registrationMessage;
17     private final ActorRef registrationActor;
18
19     @GuardedBy("this")
20     private boolean closed;
21
22     DelayedDataTreeChangeListenerRegistration(final RegisterDataTreeChangeListener registrationMessage,
23             final ActorRef registrationActor) {
24         this.registrationMessage = registrationMessage;
25         this.registrationActor = registrationActor;
26     }
27
28     synchronized void doRegistration(final DataTreeChangeListenerSupport support) {
29         if (!closed) {
30             support.doRegistration(registrationMessage, registrationActor);
31         }
32     }
33
34     @Override
35     public synchronized void close() {
36         closed = true;
37     }
38 }