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

import akka.actor.ActorRef;
import akka.actor.UntypedActorContext;
import fucoin.supervisor.DistributedCommitedTransferRequest;
Michael Kmoch's avatar
Michael Kmoch committed

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, SuperVisorImpl 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);
		ActionPrepareDistributedCommittedTransfer apdct = new ActionPrepareDistributedCommittedTransfer(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);