Newer
Older
Simon Könnecke
committed
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
Simon Könnecke
committed
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
import java.io.Serializable;
import java.util.HashMap;
public abstract class AbstractNode extends UntypedActor implements Serializable {
/**
* Returns the akka-style address as String,
* which could be converted to an ActorRef object later
*
* @return
*/
public String getAddress() {
return getAddress(getSelf());
}
public String getAddress(ActorRef self) {
return self.path().toSerializationFormatWithAddress(self.path().address());
}
/**
* The which receives Action objects
*
* @param message
*/
public abstract void onReceive(Object message);
/**
* Holds references to neighbors that were in contact with this wallet during runtime;
* The key corresponds to the WalletImpl's name
*/
private transient HashMap<String, ActorRef> knownNeighbors = new HashMap<String, ActorRef>();
/**
* Holds references to neighbors
* this wallet synchronizes itself to (the WalletImpl object);
* The key corresponds to the WalletImpl's name
*/
public transient HashMap<String, ActorRef> localNeighbors = new HashMap<String, ActorRef>();
/**
* Holds all Wallets from network participants
* which synchronize their state (WalletImpl object) with us;
* The key corresponds to the WalletImpl's name
*/
public transient HashMap<String, AbstractWallet> backedUpNeighbors =
new HashMap<String, AbstractWallet>();
public transient HashMap<ActorRef, Integer> amounts = new HashMap<ActorRef, Integer>();
public boolean addKnownNeighbor(String key, ActorRef value) {
if (!knownNeighbors.containsKey(key)) {
knownNeighbors.put(key, value);
return true;
}
return false;
}
public HashMap<String, ActorRef> getKnownNeighbors() {
return knownNeighbors;
}
public void log(String string) {
System.out.println(getSelf().path().name() + ": " + string);
}
}