Newer
Older
package fucoin.actions.join;
import akka.actor.ActorRef;
import akka.actor.UntypedActorContext;
import fucoin.actions.ClientAction;
import fucoin.actions.persist.ActionSearchMyWallet;
import fucoin.actions.transaction.ActionGetAmount;
Simon Könnecke
committed
import fucoin.wallet.AbstractWallet;
import java.util.HashMap;
import java.util.Map.Entry;
// Returns some neighbors that might be used as known
// and/or local neighbors
Simon Könnecke
committed
public class ActionJoinAnswer extends ClientAction {
public final HashMap<String, ActorRef> someNeighbors = new HashMap<>();
public final ActorRef supervisor;
public ActionJoinAnswer(ActorRef supervisor) {
this.supervisor = supervisor;
}
Simon Könnecke
committed
protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, AbstractWallet wallet) {
wallet.log("Addressed to " + self.path().name() + " from " + sender.path().name() + ": someNeighbors:" + someNeighbors);
Simon Könnecke
committed
for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) {
wallet.addKnownNeighbor(neighbor.getKey(), neighbor.getValue());
}
for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) {
neighbor.getValue().tell(new ActionSearchMyWallet(wallet.getName()), self);
}
if (wallet.getRemoteSuperVisorActor() == null) {
wallet.setRemoteSuperVisorActor(supervisor);
supervisor.tell(new ServerActionJoin(wallet.getName()), self);
}
Simon Könnecke
committed
}