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 akka.actor.ActorRef;
11 import akka.actor.ActorSelection;
12 import com.google.common.base.Preconditions;
13 import java.util.Collection;
14 import org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Internal implementation of a {@link DOMDataTreeChangeListener} which
22 * encapsulates received notifications into a {@link DataTreeChanged}
23 * message and forwards them towards the client's {@link DataTreeChangeListenerActor}.
25 final class ForwardingDataTreeChangeListener implements DOMDataTreeChangeListener {
26 private static final Logger LOG = LoggerFactory.getLogger(ForwardingDataTreeChangeListener.class);
28 private final ActorSelection actor;
30 ForwardingDataTreeChangeListener(final ActorSelection actor) {
31 this.actor = Preconditions.checkNotNull(actor, "actor should not be null");
35 public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
36 LOG.debug("Sending DataTreeChanged to {}", actor);
37 actor.tell(new DataTreeChanged(changes), ActorRef.noSender());
41 public String toString() {
42 return "ForwardingDataTreeChangeListener [actor=" + actor + "]";