a17c603596d1e9b0d8045f521bfb08b23c3953fa
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardDataChangeListenerPublisherActorProxy.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.common.api.data.AsyncDataBroker.DataChangeScope;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
22
23 /**
24  * Implementation of ShardDataChangeListenerPublisher that offloads the generation and publication
25  * of data change notifications to an actor.
26  *
27  * @author Thomas Pantelis
28  */
29 @NotThreadSafe
30 class ShardDataChangeListenerPublisherActorProxy extends AbstractShardDataTreeNotificationPublisherActorProxy
31         implements ShardDataChangeListenerPublisher {
32
33     ShardDataChangeListenerPublisherActorProxy(ActorContext actorContext, String actorName, String logContext) {
34         super(actorContext, actorName, logContext);
35     }
36
37     @Override
38     public void registerDataChangeListener(YangInstanceIdentifier path,
39             AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener, DataChangeScope scope,
40             Optional<DataTreeCandidate> initialState,
41             Consumer<ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>>>
42                 onRegistration) {
43         notifierActor().tell(new ShardDataChangePublisherActor.RegisterListener(path, listener, scope, initialState,
44                 onRegistration), ActorRef.noSender());
45     }
46
47     @Override
48     protected Props props() {
49         return ShardDataChangePublisherActor.props(actorName(), logContext());
50     }
51 }