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


import akka.actor.ActorRef;
import akka.actor.UntypedActorContext;
import fucoin.Wallet;
import fucoin.actions.search.ActionSearchWalletReference;

public class ActionInvokeSentMoney extends Transaction{
	public final String name;
	public final int amount;
    public ActionInvokeSentMoney(String name, int amount) {
    	this.name=name;
        this.amount = amount;
    }
	@Override
	protected void onAction(ActorRef sender, ActorRef self,
			UntypedActorContext context, Wallet wallet) {
		log(wallet.getKnownNeighbors()+"");
		if(wallet.getKnownNeighbors().containsKey(name)){
			wallet.getRemoteSuperVisorActor().tell(
					new ActionInvokeDistributedCommitedTransfer(self,wallet.getKnownNeighbors().get(name),amount), sender);
		}else{
Michael Kmoch's avatar
Michael Kmoch committed
			ActionSearchWalletReference aswr = new ActionSearchWalletReference(name);
Michael Kmoch's avatar
Michael Kmoch committed
			for(ActorRef neighbor : wallet.getKnownNeighbors().values()){
Michael Kmoch's avatar
Michael Kmoch committed
				neighbor.tell(aswr, self);
Michael Kmoch's avatar
Michael Kmoch committed
			}
Michael Kmoch's avatar
Michael Kmoch committed
			sleep(self, context, 200);
			self.tell(this, self);
		}
	}
	private void sleep(ActorRef self, UntypedActorContext context, int sleeptime) {
		try {
			context.unwatch(self);
			Thread.sleep(sleeptime);
			context.watch(self);
		} catch (InterruptedException e) {
			e.printStackTrace();