Skip to content
Snippets Groups Projects
ActionInvokeDistributedCommitedTransfer.java 1.23 KiB
Newer Older
Michael Kmoch's avatar
Michael Kmoch committed
package fucoin.actions.transaction;

import java.util.HashMap;

import akka.actor.ActorRef;
import akka.actor.UntypedActorContext;
import fucoin.Wallet;
import fucoin.supervisor.DistributedCommitedTransferRequest;
import fucoin.supervisor.SuperVisor;

public class ActionInvokeDistributedCommitedTransfer extends CoordinatorTransaction{

	private ActorRef source;
	private ActorRef target;
	private int amount;

	public ActionInvokeDistributedCommitedTransfer(ActorRef source,
			ActorRef target, int amount) {
		this.source=source;
		this.target=target;
		this.amount=amount;
	}

	@Override
	protected void onAction(ActorRef sender, ActorRef self,
			UntypedActorContext context, SuperVisor superVisor) {
Michael Kmoch's avatar
Michael Kmoch committed
		log("invoke transaction "+source.path().name()+" sends "+amount+" to "+target.path().name());
		long timeout = System.currentTimeMillis()+500;
		DistributedCommitedTransferRequest ds = new DistributedCommitedTransferRequest(source,target,timeout);
Michael Kmoch's avatar
Michael Kmoch committed
		superVisor.addDistributedCommitedTransferRequest(ds);
Michael Kmoch's avatar
Michael Kmoch committed
		ActionPrepareDistributedCommitedTransfer apdct = new ActionPrepareDistributedCommitedTransfer(source,target,amount,timeout,ds.getId());
Michael Kmoch's avatar
Michael Kmoch committed
		for(ActorRef neighbor : superVisor.getKnownNeighbors().values()){
Michael Kmoch's avatar
Michael Kmoch committed
			neighbor.tell(apdct, self);