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 throw new Exception("Not recognized message recieved="+message);
47 private ActorRef createTypedTransactionActor(CreateTransaction createTransaction,String transactionId){
48 if(createTransaction.getTransactionType()== TransactionProxy.TransactionType.READ_ONLY.ordinal()){
49 return getContext().actorOf(
50 ShardTransaction.props( chain.newReadOnlyTransaction(), getSelf(), schemaContext), transactionId);
52 }else if (createTransaction.getTransactionType()== TransactionProxy.TransactionType.READ_WRITE.ordinal()){
53 return getContext().actorOf(
54 ShardTransaction.props( chain.newReadWriteTransaction(), getSelf(), schemaContext), transactionId);
57 }else if (createTransaction.getTransactionType()== TransactionProxy.TransactionType.WRITE_ONLY.ordinal()){
58 return getContext().actorOf(
59 ShardTransaction.props( chain.newWriteOnlyTransaction(), getSelf(), schemaContext), transactionId);
61 throw new IllegalArgumentException ("CreateTransaction message has unidentified transaction type="+createTransaction.getTransactionType()) ;
65 private void createTransaction(CreateTransaction createTransaction) {
67 ActorRef transactionActor = createTypedTransactionActor(createTransaction, "shard-" + createTransaction.getTransactionId());
69 .tell(new CreateTransactionReply(transactionActor.path().toString(),createTransaction.getTransactionId()).toSerializable(),
73 public static Props props(final DOMStoreTransactionChain chain, final SchemaContext schemaContext) {
74 return Props.create(new Creator<ShardTransactionChain>() {
77 public ShardTransactionChain create() throws Exception {
78 return new ShardTransactionChain(chain, schemaContext);