-
David Bohn authoredDavid Bohn authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
SuperVisorImpl.java 4.22 KiB
package fucoin.supervisor;
import akka.actor.Props;
import fucoin.actions.Action;
import fucoin.actions.persist.ActionInvokeUpdate;
import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.actions.transaction.SuperVisorAction;
import fucoin.gui.SuperVisorGuiControl;
import fucoin.AbstractNode;
import fucoin.gui.TransactionLogger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import static akka.dispatch.Futures.future;
public class SuperVisorImpl extends AbstractNode implements TransactionLogger{
private AmountTableModel amountTableModel;
private Map<Long, DistributedCommittedTransferRequest> requestQueue;
private SuperVisorGuiControl gui;
public SuperVisorImpl() {
this.amountTableModel = new AmountTableModel();
}
public void setGuiControl(SuperVisorGuiControl gui) {
this.gui = gui;
}
public SuperVisorImpl(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel;
}
@Override
public void onReceive(Object msg) {
// dirty but necessary since ActionGetAmountAnswer is a
// ClientAction for some reason
if (msg instanceof ActionGetAmountAnswer) {
ActionGetAmountAnswer answer = (ActionGetAmountAnswer) msg;
amountTableModel.updateTable(answer.address, answer.name, answer.amount);
} /* TODO: Whats happened here?? Why we can invoke doAction of abstract class? */ else if (msg instanceof SuperVisorAction) {
((Action) msg).doAction(this);
}
}
public static Props props() {
return Props.create(new SuperVisorCreator());
}
public void updateValues() {
getSelf().tell(new ActionInvokeUpdate(), getSelf());
}
public void exit() {
getContext().stop(getSelf());
if (gui != null) {
gui.onLeave();
}
}
@Override
public void postStop() throws Exception {
super.postStop();