2 * Copyright (c) 2014 Brocade Communications 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
8 package org.opendaylight.controller.cluster.datastore.compat;
10 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
11 import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction;
12 import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction;
13 import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction;
14 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransaction;
15 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransactionReply;
16 import akka.actor.PoisonPill;
17 import akka.actor.Props;
18 import akka.event.Logging;
19 import akka.event.LoggingAdapter;
20 import akka.japi.Creator;
23 * An actor to maintain backwards compatibility for the base Helium version where the 3-phase commit
24 * messages don't contain the transactionId. This actor just forwards a new message containing the
25 * transactionId to the parent Shard.
27 * @author Thomas Pantelis
29 public class BackwardsCompatibleThreePhaseCommitCohort extends AbstractUntypedActor {
31 private final LoggingAdapter LOG = Logging.getLogger(getContext().system(), this);
33 private final String transactionId;
35 private BackwardsCompatibleThreePhaseCommitCohort(String transactionId) {
36 this.transactionId = transactionId;
40 public void handleReceive(Object message) throws Exception {
41 if(message.getClass().equals(CanCommitTransaction.SERIALIZABLE_CLASS)) {
42 LOG.debug("BackwardsCompatibleThreePhaseCommitCohort CanCommitTransaction");
44 getContext().parent().forward(new CanCommitTransaction(transactionId).toSerializable(),
46 } else if(message.getClass().equals(PreCommitTransaction.SERIALIZABLE_CLASS)) {
47 LOG.debug("BackwardsCompatibleThreePhaseCommitCohort PreCommitTransaction");
49 // The Shard doesn't need the PreCommitTransaction message so just return the reply here.
50 getSender().tell(new PreCommitTransactionReply().toSerializable(), self());
51 } else if(message.getClass().equals(CommitTransaction.SERIALIZABLE_CLASS)) {
52 LOG.debug("BackwardsCompatibleThreePhaseCommitCohort CommitTransaction");
54 getContext().parent().forward(new CommitTransaction(transactionId).toSerializable(),
57 // We're done now - we can self-destruct
58 self().tell(PoisonPill.getInstance(), self());
59 } else if(message.getClass().equals(AbortTransaction.SERIALIZABLE_CLASS)) {
60 LOG.debug("BackwardsCompatibleThreePhaseCommitCohort AbortTransaction");
62 getContext().parent().forward(new AbortTransaction(transactionId).toSerializable(),
64 self().tell(PoisonPill.getInstance(), self());
68 public static Props props(String transactionId) {
69 return Props.create(new BackwardsCompatibleThreePhaseCommitCohortCreator(transactionId));
72 private static class BackwardsCompatibleThreePhaseCommitCohortCreator
73 implements Creator<BackwardsCompatibleThreePhaseCommitCohort> {
74 private static final long serialVersionUID = 1L;
76 private final String transactionId;
78 BackwardsCompatibleThreePhaseCommitCohortCreator(String transactionId) {
79 this.transactionId = transactionId;
83 public BackwardsCompatibleThreePhaseCommitCohort create() throws Exception {
84 return new BackwardsCompatibleThreePhaseCommitCohort(transactionId);