Migrate netconf to MD-SAL APIs
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / actors / ReadTransactionActor.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.netconf.topology.singleton.impl.actors;
9
10 import akka.actor.Props;
11 import akka.actor.UntypedAbstractActor;
12 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
13 import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadActorMessage;
14
15 /**
16  * ReadTransactionActor is an interface to device's {@link DOMDataTreeReadTransaction} for cluster nodes.
17  */
18 public final class ReadTransactionActor extends UntypedAbstractActor {
19
20     private final ReadAdapter readAdapter;
21
22     private ReadTransactionActor(final DOMDataTreeReadTransaction tx) {
23         readAdapter = new ReadAdapter(tx);
24     }
25
26     /**
27      * Creates new actor Props.
28      *
29      * @param tx delegate device read transaction
30      * @return props
31      */
32     static Props props(final DOMDataTreeReadTransaction tx) {
33         return Props.create(ReadTransactionActor.class, () -> new ReadTransactionActor(tx));
34     }
35
36     @Override
37     public void onReceive(final Object message) {
38         if (message instanceof ReadActorMessage) {
39             readAdapter.handle(message, sender(), self());
40         } else {
41             unhandled(message);
42         }
43     }
44
45 }