Skip to content
Snippets Groups Projects
Commit 9c09dff0 authored by Simon Könnecke's avatar Simon Könnecke
Browse files

rename Factory to Creator, typos, code formatting

parent fe89c93b
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
......@@ -28,15 +28,16 @@ public class SuperVisorImpl extends AbstractNode {
if (msg instanceof ActionGetAmountAnswer) {
ActionGetAmountAnswer answer = (ActionGetAmountAnswer) msg;
amountTableModel.updateTable(answer.address, answer.name, answer.amount);
} else if (msg instanceof SuperVisorAction) {
} /* TODO: Whats happened here?? Why we can invoke doAction of abstract class? */
else if (msg instanceof SuperVisorAction) {
((Action) msg).doAction(this);
}
}
private Map<Long, DistributedCommitedTransferRequest> requestQueue;
private Map<Long, DistributedCommittedTransferRequest> requestQueue;
public static Props props() {
return Props.create(SuperVisorImpl.class, new SuperVisorFactory());
return Props.create(new SuperVisorCreator());
}
public void updateValues() {
......@@ -53,7 +54,7 @@ public class SuperVisorImpl extends AbstractNode {
}
public void addDistributedCommitedTransferRequest(
DistributedCommitedTransferRequest request) {
DistributedCommittedTransferRequest request) {
System.out.println("Add request to queue: " + request.getId());
requestQueue.put(request.getId(), request);
}
......@@ -70,10 +71,10 @@ public class SuperVisorImpl extends AbstractNode {
*
* @return deleted outdated request
*/
public List<DistributedCommitedTransferRequest> updateList() {
List<Long> deletesIds = new ArrayList<Long>();
List<DistributedCommitedTransferRequest> deletes = new ArrayList<DistributedCommitedTransferRequest>();
for (Entry<Long, DistributedCommitedTransferRequest> outdatedRequest : requestQueue.entrySet()) {
public List<DistributedCommittedTransferRequest> updateList() {
List<Long> deletesIds = new ArrayList<>();
List<DistributedCommittedTransferRequest> deletes = new ArrayList<>();
for (Entry<Long, DistributedCommittedTransferRequest> outdatedRequest : requestQueue.entrySet()) {
if (outdatedRequest.getValue().getTimeout() < System.currentTimeMillis()) {
deletesIds.add(outdatedRequest.getKey());
deletes.add(outdatedRequest.getValue());
......@@ -86,12 +87,11 @@ public class SuperVisorImpl extends AbstractNode {
return deletes;
}
public DistributedCommitedTransferRequest getRequest(Long id) {
DistributedCommitedTransferRequest searchedrequest = requestQueue.get(id);
return searchedrequest;
public DistributedCommittedTransferRequest getRequest(Long id) {
return requestQueue.get(id);
}
public void deleteRequest(DistributedCommitedTransferRequest request) {
public void deleteRequest(DistributedCommittedTransferRequest request) {
requestQueue.remove(request.getId());
}
}
......@@ -4,14 +4,14 @@ import akka.actor.ActorRef;
public abstract class AbstractWallet extends AbstractNode {
/**
* The amount this wallet currently holds
* Currently amount of this wallet
*/
protected int amount;
/**
* The name of this wallet (does never change, no duplicates in network assumed)
*/
public final String name;
protected final String name;
/**
* Init. a wallet with a name.
......@@ -60,7 +60,7 @@ public abstract class AbstractWallet extends AbstractNode {
public abstract void setActive(boolean isActive);
public abstract ActorRef getPreknownNeighbour();
public abstract ActorRef getPreKnownNeighbour();
public abstract ActorRef getRemoteSuperVisorActor();
......
......@@ -5,16 +5,16 @@ import akka.japi.Creator;
import fucoin.gui.WalletGuiController;
import fucoin.gui.WalletGuiControllerImpl;
public class WalletFactory implements Creator<AbstractWallet> {
private ActorRef preknownNeighbour;
public class WalletCreator implements Creator<AbstractWallet> {
private ActorRef preKnownNeighbour;
private String walletName;
private ActorRef remoteSuperVisorActor;
private String preknownNeighbourName;
private String preKnownNeighbourName;
public WalletFactory(ActorRef preknownNeighbour, String preknownNeighbourName, String walletName, ActorRef remoteSuperVisorActor) {
this.preknownNeighbour = preknownNeighbour;
this.preknownNeighbourName = preknownNeighbourName;
public WalletCreator(ActorRef preKnownNeighbour, String preKnownNeighbourName,
String walletName, ActorRef remoteSuperVisorActor) {
this.preKnownNeighbour = preKnownNeighbour;
this.preKnownNeighbourName = preKnownNeighbourName;
this.walletName = walletName;
this.remoteSuperVisorActor = remoteSuperVisorActor;
......@@ -22,9 +22,10 @@ public class WalletFactory implements Creator<AbstractWallet> {
@Override
public WalletImpl create() throws Exception {
WalletImpl wallet = new WalletImpl(preknownNeighbour, preknownNeighbourName, walletName, remoteSuperVisorActor);
WalletImpl wallet = new WalletImpl(preKnownNeighbour, preKnownNeighbourName,
walletName, remoteSuperVisorActor);
WalletGuiController gui = new WalletGuiControllerImpl(wallet);
WalletGuiControllerImpl gui = new WalletGuiControllerImpl(wallet);
wallet.setGui(gui);
return wallet;
}
......
......@@ -14,22 +14,32 @@ import fucoin.gui.WalletGuiController;
public class WalletImpl extends AbstractWallet implements WalletController {
private ActorRef preknownNeighbour;
private ActorRef preKnownNeighbour;
private ActorRef remoteSuperVisorActor;
private WalletGuiController gui;
private String preknownNeighbourName;
private String preKnownNeighbourName;
private boolean isActive;
public WalletImpl(ActorRef preknownNeighbour, String preknownNeighbourName, String walletName, ActorRef remoteSuperVisorActor) {
public WalletImpl(String name) {
super(name);
}
public WalletImpl(ActorRef preKnownNeighbour, String preKnownNeighbourName,
String walletName, ActorRef remoteSuperVisorActor) {
super(walletName);
this.preknownNeighbourName = preknownNeighbourName;
this.preknownNeighbour = preknownNeighbour;
this.preKnownNeighbourName = preKnownNeighbourName;
this.preKnownNeighbour = preKnownNeighbour;
this.remoteSuperVisorActor = remoteSuperVisorActor;
}
public static Props props(ActorRef preKnownNeighbour, String preKnownNeighbourName,
String walletName, ActorRef remoteSuperVisorActor) {
return Props.create(new WalletCreator(preKnownNeighbour, preKnownNeighbourName, walletName, remoteSuperVisorActor));
}
public void addAmount(int amount) {
setAmount(this.amount + amount);
log(" My amount is now " + this.amount);
setAmount(this.getAmount() + amount);
log(" My amount is now " + this.getAmount());
}
@Override
......@@ -61,17 +71,17 @@ public class WalletImpl extends AbstractWallet implements WalletController {
String path = "akka.tcp://Core@127.0.0.1:1234/user/Main";
//System.out.println(getContext().provider().getExternalAddressFor(getSelf().path().address()));
//log("my address should be "+getAddress());
//log(""+preknownNeighbour);
//log(""+preKnownNeighbour);
//knownNeighbors.put(getName(),getSelf());
//System.out.println(knownNeighbors);
if (preknownNeighbour != null) {
addKnownNeighbor(preknownNeighbourName, preknownNeighbour);
preknownNeighbour.tell(new ActionJoin(), getSelf());
if (preKnownNeighbour != null) {
addKnownNeighbor(preKnownNeighbourName, preKnownNeighbour);
preKnownNeighbour.tell(new ActionJoin(), getSelf());
ActionJoinAnswer aja = new ActionJoinAnswer();
aja.someNeighbors.putAll(getKnownNeighbors());
aja.someNeighbors.put(name, getSelf());
preknownNeighbour.tell(aja, getSelf());
preKnownNeighbour.tell(aja, getSelf());
}
//setAmount(100);
......@@ -85,22 +95,17 @@ public class WalletImpl extends AbstractWallet implements WalletController {
}
public static Props props(ActorRef preknownNeighbour, String preknownNeighbourName, String walletName, ActorRef remoteSuperVisorActor) {
return Props.create(WalletImpl.class, new WalletFactory(preknownNeighbour, preknownNeighbourName, walletName, remoteSuperVisorActor));
}
@Override
public boolean equals(Object obj) {
if (obj instanceof WalletImpl) {
WalletImpl wobj = (WalletImpl) obj;
return amount == wobj.amount && name.equals(wobj.name);
return amount == wobj.getAmount() && name.equals(wobj.getName());
}
return false;
}
public void setGui(WalletGuiController gui) {
this.gui = gui;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
......@@ -113,30 +118,46 @@ public class WalletImpl extends AbstractWallet implements WalletController {
}
}
public int getAmount() {
return amount;
public ActorRef getPreKnownNeighbour() {
return preKnownNeighbour;
}
public ActorRef getPreknownNeighbour() {
return preknownNeighbour;
public void setPreKnownNeighbour(ActorRef preKnownNeighbour) {
this.preKnownNeighbour = preKnownNeighbour;
}
public ActorRef getRemoteSuperVisorActor() {
return remoteSuperVisorActor;
}
public void setRemoteSuperVisorActor(ActorRef remoteSuperVisorActor) {
this.remoteSuperVisorActor = remoteSuperVisorActor;
}
public WalletGuiController getGui() {
return gui;
}
public String getPreknownNeighbourName() {
return preknownNeighbourName;
public void setGui(WalletGuiController gui) {
this.gui = gui;
}
public String getPreKnownNeighbourName() {
return preKnownNeighbourName;
}
public void setPreKnownNeighbourName(String preKnownNeighbourName) {
this.preKnownNeighbourName = preKnownNeighbourName;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
@Override
public boolean addKnownNeighbor(String key, ActorRef value) {
System.out.println(key + " is newNeighbor of " + name + "?" + !getKnownNeighbors().containsKey(key));
......@@ -151,18 +172,6 @@ public class WalletImpl extends AbstractWallet implements WalletController {
return newNeighbor;
}
public void setPreknownNeighbour(ActorRef preknownNeighbour) {
this.preknownNeighbour = preknownNeighbour;
}
public void setRemoteSuperVisorActor(ActorRef remoteSuperVisorActor) {
this.remoteSuperVisorActor = remoteSuperVisorActor;
}
public void setPreknownNeighbourName(String preknownNeighbourName) {
this.preknownNeighbourName = preknownNeighbourName;
}
@Override
public void log(String msg) {
if (gui != null) {
......@@ -180,10 +189,6 @@ public class WalletImpl extends AbstractWallet implements WalletController {
}
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
@Override
public void send(String address, int amount) {
getSelf().tell(new ActionInvokeSentMoney(address, amount), getSelf());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment