Refactor Register*ListenerReply classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardDataTreeChangeListenerPublisherActorProxy.java
1 /*
2  * Copyright (c) 2016 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.ActorContext;
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import com.google.common.base.Optional;
14 import java.util.function.Consumer;
15 import javax.annotation.concurrent.NotThreadSafe;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
20
21 /**
22  * Implementation of ShardDataTreeChangeListenerPublisher that offloads the generation and publication
23  * of data tree change notifications to an actor.
24  *
25  * @author Thomas Pantelis
26  */
27 @NotThreadSafe
28 class ShardDataTreeChangeListenerPublisherActorProxy extends AbstractShardDataTreeNotificationPublisherActorProxy
29         implements ShardDataTreeChangeListenerPublisher {
30
31     ShardDataTreeChangeListenerPublisherActorProxy(ActorContext actorContext, String actorName, String logContext) {
32         super(actorContext, actorName, logContext);
33     }
34
35     @Override
36     public void registerTreeChangeListener(YangInstanceIdentifier treeId,
37             DOMDataTreeChangeListener listener, Optional<DataTreeCandidate> currentState,
38             Consumer<ListenerRegistration<DOMDataTreeChangeListener>> onRegistration) {
39         final ShardDataTreeChangePublisherActor.RegisterListener regMessage =
40                 new ShardDataTreeChangePublisherActor.RegisterListener(treeId, listener, currentState, onRegistration);
41         log.debug("{}: Sending {} to publisher actor {}", logContext(), regMessage, publisherActor());
42         publisherActor().tell(regMessage, ActorRef.noSender());
43     }
44
45     @Override
46     protected Props props() {
47         return ShardDataTreeChangePublisherActor.props(actorName(), logContext());
48     }
49 }