- }
- }, getContext().dispatcher());
-
- }
-
- private void canCommit(CanCommitTransaction message) {
- final ListenableFuture<Boolean> future = cohort.canCommit();
- final ActorRef sender = getSender();
- final ActorRef self = getSelf();
-
- future.addListener(new Runnable() {
- @Override
- public void run() {
- try {
- Boolean canCommit = future.get();
- sender.tell(new CanCommitTransactionReply(canCommit), self);
- } catch (InterruptedException | ExecutionException e) {
- log.error(e, "An exception happened when aborting");
+ shardActor.forward(new ForwardedCommitTransaction(cohort, modification),
+ getContext());
+
+ getContext().parent().tell(PoisonPill.getInstance(), getSelf());
+
+ }
+
+ private void preCommit(PreCommitTransaction message) {
+ final ListenableFuture<Void> future = cohort.preCommit();
+ final ActorRef sender = getSender();
+ final ActorRef self = getSelf();
+ Futures.addCallback(future, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void v) {
+ sender
+ .tell(new PreCommitTransactionReply().toSerializable(),
+ self);
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error(t, "An exception happened during pre-commit");
+ sender
+ .tell(new akka.actor.Status.Failure(t), self);
+ }
+ });
+
+ }
+
+ private void canCommit(CanCommitTransaction message) {
+ final ListenableFuture<Boolean> future = cohort.canCommit();
+ final ActorRef sender = getSender();
+ final ActorRef self = getSelf();
+ Futures.addCallback(future, new FutureCallback<Boolean>() {
+ @Override
+ public void onSuccess(Boolean canCommit) {
+ sender.tell(new CanCommitTransactionReply(canCommit)
+ .toSerializable(), self);
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error(t, "An exception happened during canCommit");
+ sender
+ .tell(new akka.actor.Status.Failure(t), self);
+ }
+ });
+ }
+
+ private static class ThreePhaseCommitCohortCreator implements Creator<ThreePhaseCommitCohort> {
+ final DOMStoreThreePhaseCommitCohort cohort;
+ final ActorRef shardActor;
+ final CompositeModification modification;
+ final ShardStats shardStats;
+
+ ThreePhaseCommitCohortCreator(DOMStoreThreePhaseCommitCohort cohort,
+ ActorRef shardActor, CompositeModification modification, ShardStats shardStats) {
+ this.cohort = cohort;
+ this.shardActor = shardActor;
+ this.modification = modification;
+ this.shardStats = shardStats;