Add case for READY in RemoteProxyTransaction
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DefaultShardDataTreeChangeListenerPublisher.java
1 /*
2  * Copyright (c) 2015 Cisco 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 java.util.Collection;
11 import javax.annotation.concurrent.NotThreadSafe;
12 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
13 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
14 import org.opendaylight.mdsal.dom.spi.store.AbstractDOMStoreTreeChangePublisher;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * Default implementation of ShardDataTreeChangeListenerPublisher that directly generates and publishes
23  * notifications for DataTreeChangeListeners.
24  *
25  * @author Thomas Pantelis
26  */
27 @NotThreadSafe
28 final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStoreTreeChangePublisher
29         implements ShardDataTreeChangeListenerPublisher {
30     private static final Logger LOG = LoggerFactory.getLogger(DefaultShardDataTreeChangeListenerPublisher.class);
31
32     @Override
33     public void publishChanges(final DataTreeCandidate candidate, String logContext) {
34         processCandidateTree(candidate);
35     }
36
37     @Override
38     public ShardDataTreeChangeListenerPublisher newInstance() {
39         return new DefaultShardDataTreeChangeListenerPublisher();
40     }
41
42     @Override
43     protected void notifyListener(AbstractDOMDataTreeChangeListenerRegistration<?> registration,
44             Collection<DataTreeCandidate> changes) {
45         registration.getInstance().onDataTreeChanged(changes);
46     }
47
48     @Override
49     protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
50         LOG.debug("Registration {} removed", registration);
51     }
52
53     @Override
54     public <L extends org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener> ListenerRegistration<L>
55             registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener) {
56         final AbstractDOMDataTreeChangeListenerRegistration<DOMDataTreeChangeListener> registration =
57             super.registerTreeChangeListener(treeId, (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)
58                 changes -> listener.onDataTreeChanged(changes));
59
60         return new org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration<L>(
61                 listener) {
62             @Override
63             protected void removeRegistration() {
64                 registration.close();
65             }
66         };
67     }
68 }