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