Skip to content
Snippets Groups Projects
Commit 4cb34ef9 authored by Luca Keidel's avatar Luca Keidel
Browse files

Unified logging (no more chaos on stdout)

parent 8339994d
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
Showing
with 35 additions and 18 deletions
...@@ -66,7 +66,13 @@ public abstract class AbstractNode extends UntypedActor implements Serializable ...@@ -66,7 +66,13 @@ public abstract class AbstractNode extends UntypedActor implements Serializable
} }
public void log(String string) { public void log(String string) {
System.out.println(getSelf().path().name() + ": " + string); if (this instanceof AbstractWallet){
System.out.println("Yes: "+string);
((AbstractWallet) this).log(string);
}else{
System.out.println("No: "+this.getClass());
System.out.println(getSelf().path().name() + ": " + string);
}
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ import java.util.List; ...@@ -16,7 +16,7 @@ import java.util.List;
public class Main { public class Main {
private static int numberOfWallets = 4; private static int numberOfWallets = 1;
private static ActorSystem cSystem; private static ActorSystem cSystem;
......
...@@ -15,9 +15,4 @@ public abstract class Action<T extends AbstractNode> { ...@@ -15,9 +15,4 @@ public abstract class Action<T extends AbstractNode> {
protected abstract void onAction(ActorRef sender, ActorRef self, protected abstract void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, T abstractNode); UntypedActorContext context, T abstractNode);
public void log(String string) {
System.out.println(self.path().name() + ": " + string);
}
} }
...@@ -16,7 +16,7 @@ public class ActionJoinAnswer extends ClientAction { ...@@ -16,7 +16,7 @@ public class ActionJoinAnswer extends ClientAction {
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, AbstractWallet wallet) { UntypedActorContext context, AbstractWallet wallet) {
log("Addressed to " + self.path().name() + " from " + sender.path().name() + ": someNeighbors:" + someNeighbors); wallet.log("Addressed to " + self.path().name() + " from " + sender.path().name() + ": someNeighbors:" + someNeighbors);
for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) { for (Entry<String, ActorRef> neighbor : someNeighbors.entrySet()) {
wallet.addKnownNeighbor(neighbor.getKey(), neighbor.getValue()); wallet.addKnownNeighbor(neighbor.getKey(), neighbor.getValue());
} }
......
...@@ -23,7 +23,7 @@ public class ActionSearchWalletReference extends Search { ...@@ -23,7 +23,7 @@ public class ActionSearchWalletReference extends Search {
@Override @Override
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, AbstractWallet wallet) { UntypedActorContext context, AbstractWallet wallet) {
log(wallet.getKnownNeighbors() + "contains " + name + "?"); wallet.log(wallet.getKnownNeighbors() + "contains " + name + "?");
ttl.add(self); ttl.add(self);
ActionSearchWalletReferenceAnswer answer = null; ActionSearchWalletReferenceAnswer answer = null;
if (this.name.equals(wallet.getName())) { if (this.name.equals(wallet.getName())) {
......
...@@ -39,7 +39,7 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { ...@@ -39,7 +39,7 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction {
@Override @Override
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, AbstractWallet wallet) { UntypedActorContext context, AbstractWallet wallet) {
System.out.println(self.path().name() + ": ActionCommitDistributedCommittedTransfer is granted?" + granted); wallet.log("ActionCommitDistributedCommittedTransfer is granted? " + granted);
if (granted) { if (granted) {
Integer sourceAmount = wallet.amounts.getOrDefault(source, 0); Integer sourceAmount = wallet.amounts.getOrDefault(source, 0);
...@@ -56,9 +56,9 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction { ...@@ -56,9 +56,9 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction {
} }
} else { } else {
log("abort transaction with id" + id); wallet.log("abort transaction with id" + id);
} }
log("wallet.amounts:" + wallet.amounts); wallet.log("wallet.amounts:" + wallet.amounts);
} }
} }
...@@ -21,7 +21,7 @@ public class ActionInvokeDistributedCommittedTransfer extends CoordinatorTransac ...@@ -21,7 +21,7 @@ public class ActionInvokeDistributedCommittedTransfer extends CoordinatorTransac
@Override @Override
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, SuperVisorImpl superVisor) { UntypedActorContext context, SuperVisorImpl superVisor) {
log("invoke transaction " + source.path().name() + superVisor.log("invoke transaction " + source.path().name() +
" sends " + amount + " sends " + amount +
" to " + target.path().name()); " to " + target.path().name());
......
...@@ -18,7 +18,7 @@ public class ActionInvokeSentMoney extends Transaction { ...@@ -18,7 +18,7 @@ public class ActionInvokeSentMoney extends Transaction {
@Override @Override
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, AbstractWallet wallet) { UntypedActorContext context, AbstractWallet wallet) {
log(wallet.getKnownNeighbors() + ""); wallet.log(wallet.getKnownNeighbors() + "");
if (wallet.getKnownNeighbors().containsKey(name)) { if (wallet.getKnownNeighbors().containsKey(name)) {
wallet.getRemoteSuperVisorActor().tell( wallet.getRemoteSuperVisorActor().tell(
new ActionInvokeDistributedCommittedTransfer(self, wallet.getKnownNeighbors().get(name), amount), sender); new ActionInvokeDistributedCommittedTransfer(self, wallet.getKnownNeighbors().get(name), amount), sender);
......
...@@ -27,14 +27,14 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator ...@@ -27,14 +27,14 @@ public class ActionPrepareDistributedCommittedTransferAnswer extends Coordinator
@Override @Override
protected void onAction(ActorRef sender, ActorRef self, protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, SuperVisorImpl superVisor) { UntypedActorContext context, SuperVisorImpl superVisor) {
log(""+superVisor.getKnownNeighbors()); superVisor.log(""+superVisor.getKnownNeighbors());
log("granted?"+granted); superVisor.log("granted?"+granted);
DistributedCommittedTransferRequest request = superVisor.getRequest(id); DistributedCommittedTransferRequest request = superVisor.getRequest(id);
if(granted){ if(granted){
if(request==null)//unknown DistributedCommittedTransferRequest ignore if(request==null)//unknown DistributedCommittedTransferRequest ignore
return; return;
int newCount = request.addPositiveAnswer(sender); int newCount = request.addPositiveAnswer(sender);
System.out.println(newCount+" have agreed on request"+id);
if(newCount == superVisor.getKnownNeighbors().size()){ if(newCount == superVisor.getKnownNeighbors().size()){
ActionCommitDistributedCommittedTransfer acdct = new ActionCommitDistributedCommittedTransfer(source,target,amount,true,timestamp,id); ActionCommitDistributedCommittedTransfer acdct = new ActionCommitDistributedCommittedTransfer(source,target,amount,true,timestamp,id);
for(ActorRef neighbor : request.getAnswers()){ for(ActorRef neighbor : request.getAnswers()){
......
...@@ -5,4 +5,6 @@ public interface SuperVisorGuiControl { ...@@ -5,4 +5,6 @@ public interface SuperVisorGuiControl {
* Call from SuperVisorImpl after poison pill or kill * Call from SuperVisorImpl after poison pill or kill
*/ */
void onLeave(); void onLeave();
void log(String message);
} }
...@@ -59,4 +59,11 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl { ...@@ -59,4 +59,11 @@ public class SuperVisorGuiControlImpl implements SuperVisorGuiControl {
public void onLeave() { public void onLeave() {
frame.dispose(); frame.dispose();
} }
@Override
public void log(String message) {
// One day, we may have a server log GUI as well..
// Until then, we just print it to the console
System.out.println(message);
}
} }
...@@ -69,7 +69,6 @@ public class SuperVisorImpl extends AbstractNode { ...@@ -69,7 +69,6 @@ public class SuperVisorImpl extends AbstractNode {
public void addDistributedCommitedTransferRequest( public void addDistributedCommitedTransferRequest(
DistributedCommittedTransferRequest request) { DistributedCommittedTransferRequest request) {
System.out.println("Add request to queue: " + request.getId());
requestQueue.put(request.getId(), request); requestQueue.put(request.getId(), request);
} }
...@@ -116,4 +115,12 @@ public class SuperVisorImpl extends AbstractNode { ...@@ -116,4 +115,12 @@ public class SuperVisorImpl extends AbstractNode {
public void setAmountTableModel(AmountTableModel amountTableModel) { public void setAmountTableModel(AmountTableModel amountTableModel) {
this.amountTableModel = amountTableModel; this.amountTableModel = amountTableModel;
} }
public void log(String message){
if (this.gui != null){
this.gui.log(message);
} else {
System.out.println(message);
}
}
} }
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