2 * Copyright (c) 2015 Cisco 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 static java.util.Objects.requireNonNull;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSelection;
14 import java.util.Collection;
15 import org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged;
16 import org.opendaylight.controller.cluster.datastore.messages.OnInitialData;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Internal implementation of a {@link DOMDataTreeChangeListener} which
24 * encapsulates received notifications into a {@link DataTreeChanged}
25 * message and forwards them towards the client's {@link DataTreeChangeListenerActor}.
27 final class ForwardingDataTreeChangeListener implements DOMDataTreeChangeListener {
28 private static final Logger LOG = LoggerFactory.getLogger(ForwardingDataTreeChangeListener.class);
30 private final ActorSelection actor;
32 ForwardingDataTreeChangeListener(final ActorSelection actor) {
33 this.actor = requireNonNull(actor, "actor should not be null");
37 public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
38 LOG.debug("Sending DataTreeChanged to {}", actor);
39 actor.tell(new DataTreeChanged(changes), ActorRef.noSender());
43 public void onInitialData() {
44 LOG.debug("Sending OnInitialData to {}", actor);
45 actor.tell(OnInitialData.INSTANCE, ActorRef.noSender());
49 public String toString() {
50 return "ForwardingDataTreeChangeListener [actor=" + actor + "]";