Skip to content
Snippets Groups Projects
ActionSearchMyWallet.java 1.07 KiB
Newer Older
Michael Kmoch's avatar
Michael Kmoch committed
package fucoin.actions.persist;

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

// Used to search a WalletImpl by name, i.e. the own wallet if we just
// joined the network; If a receiving participant holds the stored WalletImpl,
Michael Kmoch's avatar
Michael Kmoch committed
// he returns it, otherwise, he might use gossiping methods to go on 
// with the search;
// Note: You should also forward the sender (the participant who actually
// searches for this WalletImpl, so that it can be returnd the direct way)
public class ActionSearchMyWallet extends Persist {
Michael Kmoch's avatar
Michael Kmoch committed
    public final String name;
Michael Kmoch's avatar
Michael Kmoch committed
    public ActionSearchMyWallet(String name) {
        this.name = name;
    }

    @Override
    protected void onAction(ActorRef sender, ActorRef self,
                            UntypedActorContext context, AbstractWallet wallet) {
        wallet.addKnownNeighbor(name, sender);
        AbstractWallet storedWallet = wallet.backedUpNeighbors.get(name);
        if (storedWallet != null) {
            sender.tell(new ActionSearchMyWalletAnswer(storedWallet), self);
        }
    }
Michael Kmoch's avatar
Michael Kmoch committed
}