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.protobuff.messages.transaction.ShardTransactionMessages;
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 instanceof CreateTransaction) {
38 CreateTransaction createTransaction = (CreateTransaction) message;
39 createTransaction(createTransaction);
40 } else if (message instanceof CloseTransactionChain) {
42 getSender().tell(new CloseTransactionChainReply(), getSelf());
46 private void createTransaction(CreateTransaction createTransaction) {
47 DOMStoreReadWriteTransaction transaction =
48 chain.newReadWriteTransaction();
49 ActorRef transactionActor = getContext().actorOf(ShardTransaction
50 .props(chain, transaction, getContext().parent(), schemaContext), "shard-" + createTransaction.getTransactionId());
52 .tell(ShardTransactionMessages.CreateTransactionReply.newBuilder()
53 .setTransactionActorPath(transactionActor.path().toString())
54 .setTransactionId(createTransaction.getTransactionId())
59 public static Props props(final DOMStoreTransactionChain chain, final SchemaContext schemaContext) {
60 return Props.create(new Creator<ShardTransactionChain>() {
63 public ShardTransactionChain create() throws Exception {
64 return new ShardTransactionChain(chain, schemaContext);