-
Notifications
You must be signed in to change notification settings - Fork 131
/
Link.java
135 lines (112 loc) · 3.69 KB
/
Link.java
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package diskCacheV111.poolManager;
import diskCacheV111.poolManager.PoolSelectionUnit.SelectionLink;
import diskCacheV111.poolManager.PoolSelectionUnit.SelectionPool;
import diskCacheV111.poolManager.PoolSelectionUnit.SelectionPoolGroup;
import diskCacheV111.poolManager.PoolSelectionUnit.SelectionUnitGroup;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
class Link implements SelectionLink, Serializable {
private static final long serialVersionUID = 4480385941491281821L;
private final String _name;
final Map<String, PoolCore> _poolList = new ConcurrentHashMap<>();
final Map<String, UGroup> _uGroupList = new ConcurrentHashMap<>();
private int _readPref;
private int _writePref;
private int _cachePref;
private int _p2pPref = -1;
private String _tag;
private LinkGroup _linkGroup;
Link(String name) {
_name = name;
}
@Override
public String getTag() {
return _tag;
}
@Override
public Collection<SelectionPoolGroup> getPoolGroupsPointingTo() {
Collection<SelectionPoolGroup> pGroups = new ArrayList<>();
for (PoolCore pcore : _poolList.values()) {
if (pcore instanceof PGroup) {
PGroup original = (PGroup) pcore;
PGroup newPGroup = new PGroup(original.getName(),
original.isPrimary());
pGroups.add(newPGroup);
}
}
return pGroups;
}
@Override
public Collection<SelectionUnitGroup> getUnitGroupsTargetedBy() {
return new ArrayList<>(_uGroupList.values());
}
@Override
public String getName() {
return _name;
}
@Override
public LinkReadWritePreferences getPreferences() {
return new LinkReadWritePreferences(getReadPref(), getWritePref(), getCachePref(),
getP2pPref());
}
@Override
public String toString() {
return getName() + " (pref=" + getReadPref() + "/" + getCachePref() + "/" + getP2pPref()
+ "/" + getWritePref() + ";" + (getTag() == null ? "" : getTag()) + ";" + "ugroups="
+ _uGroupList.size() + ";pools=" + _poolList.size() + ")";
}
public String getAttraction() {
return "-readpref=" + getReadPref() + " -writepref=" + getWritePref() + " -cachepref="
+ getCachePref() + " -p2ppref=" + getP2pPref() + (getTag() == null ? ""
: " -section=" + getTag());
}
@Override
public Collection<SelectionPool> getPools() {
List<SelectionPool> list = new ArrayList<>();
for (Object o : _poolList.values()) {
if (o instanceof Pool) {
list.add((Pool) o);
} else if (o instanceof PGroup) {
list.addAll(((PGroup)o).getPools());
}
}
return list;
}
public void setLinkGroup(LinkGroup lg) {
_linkGroup = lg;
}
public LinkGroup getLinkGroup() {
return _linkGroup;
}
public int getReadPref() {
return _readPref;
}
public void setReadPref(int readPref) {
_readPref = readPref;
}
public int getWritePref() {
return _writePref;
}
public void setWritePref(int writePref) {
_writePref = writePref;
}
public int getCachePref() {
return _cachePref;
}
public void setCachePref(int cachePref) {
_cachePref = cachePref;
}
public int getP2pPref() {
return _p2pPref;
}
public void setP2pPref(int p2pPref) {
_p2pPref = p2pPref;
}
public void setTag(String tag) {
_tag = tag;
}
}