2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import akka.japi.Creator;
14 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain;
15 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply;
16 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
17 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 * The ShardTransactionChain Actor represents a remote TransactionChain
24 public class ShardTransactionChain extends AbstractUntypedActor {
26 private final DOMStoreTransactionChain chain;
27 private final SchemaContext schemaContext;
29 public ShardTransactionChain(DOMStoreTransactionChain chain, SchemaContext schemaContext) {
31 this.schemaContext = schemaContext;
35 public void handleReceive(Object message) throws Exception {
36 if (message.getClass().equals(CreateTransaction.SERIALIZABLE_CLASS)) {
37 CreateTransaction createTransaction = CreateTransaction.fromSerializable( message);
38 createTransaction(createTransaction);
39 } else if (message.getClass().equals(CloseTransactionChain.SERIALIZABLE_CLASS)) {
41 getSender().tell(new CloseTransactionChainReply().toSerializable(), getSelf());
43 unknownMessage(message);
47 private ActorRef getShardActor(){
48 return getContext().parent();
51 private ActorRef createTypedTransactionActor(CreateTransaction createTransaction,String transactionId){
52 if(createTransaction.getTransactionType()== TransactionProxy.TransactionType.READ_ONLY.ordinal()){
53 return getContext().actorOf(
54 ShardTransaction.props( chain.newReadOnlyTransaction(), getShardActor(), schemaContext), transactionId);
56 }else if (createTransaction.getTransactionType()== TransactionProxy.TransactionType.READ_WRITE.ordinal()){
57 return getContext().actorOf(
58 ShardTransaction.props( chain.newReadWriteTransaction(), getShardActor(), schemaContext), transactionId);
61 }else if (createTransaction.getTransactionType()== TransactionProxy.TransactionType.WRITE_ONLY.ordinal()){
62 return getContext().actorOf(
63 ShardTransaction.props( chain.newWriteOnlyTransaction(), getShardActor(), schemaContext), transactionId);
65 throw new IllegalArgumentException ("CreateTransaction message has unidentified transaction type="+createTransaction.getTransactionType()) ;
69 private void createTransaction(CreateTransaction createTransaction) {
71 ActorRef transactionActor = createTypedTransactionActor(createTransaction, "shard-" + createTransaction.getTransactionId());
73 .tell(new CreateTransactionReply(transactionActor.path().toString(),createTransaction.getTransactionId()).toSerializable(),
77 public static Props props(final DOMStoreTransactionChain chain, final SchemaContext schemaContext) {
78 return Props.create(new Creator<ShardTransactionChain>() {
81 public ShardTransactionChain create() throws Exception {
82 return new ShardTransactionChain(chain, schemaContext);