Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.util.HashMap;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import java.io.Serializable;
public abstract class AbstractWallet extends UntypedActor implements Serializable {
// Returns some neighbors that might be used as local
// and/or local neighborsUntypedActor
public static class ActionJoin implements Serializable {}
public class ActionJoinAnswer implements Serializable {
public final HashMap<String, ActorRef> someNeighbors = new HashMap<>();
}
// Used to push the state of my/a wallet to another participant
public static class ActionStoreOrUpdate implements Serializable {
public final AbstractWallet w;
public ActionStoreOrUpdate(AbstractWallet w) {
this.w = w;
}
}
// May be used to delete a stored Wallet on another participant
public static class ActionInvalidate implements Serializable {
final String name;
public ActionInvalidate(String name) {
this.name = name;
}
}
// Used to send (positive amount) or retreive money (negative amount)
public static class ActionReceiveTransaction implements Serializable {
final public int amount;
public ActionReceiveTransaction(int amount) {
this.amount = amount;
}
}
// Used to search a Wallet by name, i.e. when we want to
// perform a transaction on it
public static class ActionSearchWalletReference implements Serializable {
final String name;
public ActionSearchWalletReference(String name) {
this.name = name;
}
}
// Used to return a Wallet
public static class ActionSearchWalletReferenceAnswer implements Serializable {
final AbstractWallet w;
public ActionSearchWalletReferenceAnswer(AbstractWallet w) {
this.w = w;
}
}
// Used to search a Wallet by name, i.e. the own wallet if we just
// joined the network
public static class ActionSearchMyWallet implements Serializable {
final String name;
public ActionSearchMyWallet(String name) {
this.name = name;
}
}
// Constructor
public AbstractWallet(String name) {
this.name = name;
}
// Returns the name of this wallet, e.g. "Lieschen Müller"
public String getName() {
return this.name;
}
// Returns the akka-style address as String, which
// could be converted to an ActorRef object later
public abstract String getAddress();
// Performs housekeeping operations, e.g. pushes
// backedUpNeighbor-entries to other neighbors
public abstract void leave();
// The which receives Action objects
public abstract void onReceive(Object message);
// Holds references to neighbors that were in
// contact with this wallet during runtime;
// The key corresponds to the Wallet's name
public transient HashMap<String, ActorRef> knownNeighbors;
// Holds references to neighbors this wallet
// synchronizes itself to (the Wallet object);
// The key corresponds to the Wallet's name
public transient HashMap<String, ActorRef> localNeighbors;
// Holds all Wallets from network participants
// which synchronize their state (Wallet object)
// with us;
// The key corresponds to the Wallet's name
public transient HashMap<String, AbstractWallet> backedUpNeighbors;
// The name of this wallet (does never change, no
// duplicates in network assumed)
public final String name;
// The amount this wallet currently holds
public int amount;
}