BUG-5280: add FrontendMetadata
[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 java.util.Collections;
12 import javax.annotation.concurrent.NotThreadSafe;
13 import org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
14 import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTreeChangePublisher;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Default implementation of ShardDataTreeChangeListenerPublisher that directly generates and publishes
24  * notifications for DataTreeChangeListeners.
25  *
26  * @author Thomas Pantelis
27  */
28 @NotThreadSafe
29 final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStoreTreeChangePublisher
30         implements ShardDataTreeChangeListenerPublisher {
31     private static final Logger LOG = LoggerFactory.getLogger(DefaultShardDataTreeChangeListenerPublisher.class);
32
33     @Override
34     public void publishChanges(final DataTreeCandidate candidate, String logContext) {
35         processCandidateTree(candidate);
36     }
37
38     @Override
39     public ShardDataTreeChangeListenerPublisher newInstance() {
40         return new DefaultShardDataTreeChangeListenerPublisher();
41     }
42
43     @Override
44     protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations,
45             final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
46         final Collection<DataTreeCandidate> changes = Collections.<DataTreeCandidate>singleton(
47                 DataTreeCandidates.newDataTreeCandidate(path, node));
48
49         for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) {
50             reg.getInstance().onDataTreeChanged(changes);
51         }
52     }
53
54     @Override
55     protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
56         LOG.debug("Registration {} removed", registration);
57     }
58 }