efa471360897b34409b592ed8a7bd6625d192fe7
[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
9 package org.opendaylight.netconf.topology.singleton.impl.actors;
10
11 import akka.actor.Props;
12 import akka.actor.UntypedActor;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
14 import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadActorMessage;
15
16 /**
17  * ReadTransactionActor is an interface to device's {@link DOMDataReadOnlyTransaction} for cluster nodes.
18  */
19 public final class ReadTransactionActor extends UntypedActor {
20
21     private final ReadAdapter readAdapter;
22
23     private ReadTransactionActor(final DOMDataReadOnlyTransaction tx) {
24         readAdapter = new ReadAdapter(tx);
25     }
26
27     /**
28      * Creates new actor Props.
29      *
30      * @param tx delegate device read transaction
31      * @return props
32      */
33     static Props props(final DOMDataReadOnlyTransaction tx) {
34         return Props.create(ReadTransactionActor.class, () -> new ReadTransactionActor(tx));
35     }
36
37     @Override
38     public void onReceive(final Object message) throws Throwable {
39         if (message instanceof ReadActorMessage) {
40             readAdapter.handle(message, sender(), self());
41         } else {
42             unhandled(message);
43         }
44     }
45
46 }