Implement basic ShardTransactionChain#CloseTransactionChain
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardTransactionChain.java
1 /*
2  * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.cluster.datastore;
10
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import akka.actor.UntypedActor;
14 import akka.japi.Creator;
15 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain;
16 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply;
17 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
18 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
21
22 /**
23  * The ShardTransactionChain Actor represents a remote TransactionChain
24  */
25 public class ShardTransactionChain extends UntypedActor{
26
27   private final DOMStoreTransactionChain chain;
28
29   public ShardTransactionChain(DOMStoreTransactionChain chain) {
30     this.chain = chain;
31   }
32
33   @Override
34   public void onReceive(Object message) throws Exception {
35     if(message instanceof CreateTransaction){
36       DOMStoreReadWriteTransaction transaction = chain.newReadWriteTransaction();
37       ActorRef transactionActor = getContext().actorOf(ShardTransaction.props(transaction));
38       getSender().tell(new CreateTransactionReply(transactionActor.path()), getSelf());
39     } else if (message instanceof CloseTransactionChain){
40       chain.close();
41       getSender().tell(new CloseTransactionChainReply(), getSelf());
42     }
43   }
44
45   public static Props props(final DOMStoreTransactionChain chain){
46     return Props.create(new Creator<ShardTransactionChain>(){
47
48       @Override
49       public ShardTransactionChain create() throws Exception {
50         return new ShardTransactionChain(chain);
51       }
52     });
53   }
54 }