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.DOMStoreReadWriteTransaction;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 * The ShardTransactionChain Actor represents a remote TransactionChain
25 public class ShardTransactionChain extends AbstractUntypedActor {
27 private final DOMStoreTransactionChain chain;
28 private final SchemaContext schemaContext;
30 public ShardTransactionChain(DOMStoreTransactionChain chain, SchemaContext schemaContext) {
32 this.schemaContext = schemaContext;
36 public void handleReceive(Object message) throws Exception {
37 if (message.getClass().equals(CreateTransaction.SERIALIZABLE_CLASS)) {
38 CreateTransaction createTransaction = CreateTransaction.fromSerializable( message);
39 createTransaction(createTransaction);
40 } else if (message.getClass().equals(CloseTransactionChain.SERIALIZABLE_CLASS)) {
42 getSender().tell(new CloseTransactionChainReply().toSerializable(), getSelf());
44 throw new Exception("Not recognized message recieved="+message);
48 private void createTransaction(CreateTransaction createTransaction) {
49 DOMStoreReadWriteTransaction transaction =
50 chain.newReadWriteTransaction();
51 ActorRef transactionActor = getContext().actorOf(ShardTransaction
52 .props(chain, transaction, getContext().parent(), schemaContext), "shard-" + createTransaction.getTransactionId());
54 .tell(new CreateTransactionReply(transactionActor.path().toString(),createTransaction.getTransactionId()).toSerializable(),
58 public static Props props(final DOMStoreTransactionChain chain, final SchemaContext schemaContext) {
59 return Props.create(new Creator<ShardTransactionChain>() {
62 public ShardTransactionChain create() throws Exception {
63 return new ShardTransactionChain(chain, schemaContext);