Skip to content
Snippets Groups Projects
Select Git revision
  • a1edc5617178319e6414799f191df4e8d9e509de
  • master default
  • dev-group3-qdigest
  • dev-group2-all-aggregations
  • dev-group2-graphs
  • dev-group2-limit-neighbors
  • dev-group1-stefan
  • dev-group3-kim
  • dev-group1-simon
9 results

ActionPrepareDistributedCommittedTransferAnswer.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ActionPrepareDistributedCommittedTransferAnswer.java 2.52 KiB
    package fucoin.actions.transaction;
    
    import fucoin.supervisor.DistributedCommittedTransferRequest;
    import fucoin.supervisor.SuperVisorImpl;
    import akka.actor.ActorRef;
    import akka.actor.UntypedActorContext;
    
    public class ActionPrepareDistributedCommittedTransferAnswer extends CoordinatorTransaction {
    
        private ActorRef source;
        private ActorRef target;
        private int amount;
        private boolean granted;
        private long timestamp;
        private long id;
    
        public ActionPrepareDistributedCommittedTransferAnswer(ActorRef source,
                                                               ActorRef target, int amount, long timestamp, boolean granted, long id) {
            this.source = source;
            this.target = target;
            this.amount = amount;
            this.granted = granted;
            this.timestamp = timestamp;
            this.id = id;
        }
    
        @Override
        protected void onAction(ActorRef sender, ActorRef self,
                                UntypedActorContext context, SuperVisorImpl superVisor) {
            //superVisor.addLogMsg("" + superVisor.getKnownNeighbors());
            superVisor.addLogMsg("granted?" + granted);
            DistributedCommittedTransferRequest request = superVisor.getRequest(id);
            if (granted) {
                if (request == null)//unknown DistributedCommittedTransferRequest ignore
                    return;
                int newCount = request.addPositiveAnswer(sender);
    
                if (newCount == superVisor.getKnownNeighbors().size()) {
                    ActionCommitDistributedCommittedTransfer acdct = new ActionCommitDistributedCommittedTransfer(source, target, amount, true, timestamp, id);
                    superVisor.addTransactionLogMessageSuccess("Transfer of " + amount + " FUC from" + source.path().name() + " to " + target.path().name());
                    for (ActorRef neighbor : request.getAnswers()) {
                        neighbor.tell(acdct, self);
                    }
                    superVisor.deleteRequest(request);
                }
            } else {
                //A client wants to rollback
                if (request != null) {
                    superVisor.addTransactionLogMessageFail("Client does not grant commit of " + amount + " FUC (" + source.path().name() + " -> " + target.path().name() + ")");
                    ActionCommitDistributedCommittedTransfer acdct = new ActionCommitDistributedCommittedTransfer(source, target, amount, false, timestamp, id);
                    for (ActorRef neighbor : request.getAnswers()) {
                        neighbor.tell(acdct, self);
                    }
                }
            }
        }
    
    }