01: package vicazh.hyperpool.stream;
02:
03: import java.util.*;
04:
05: /**
06: * The priorities list
07: *
08: * @author Victor Zhigunov
09: * @version 0.4.0
10: */
11: public class Priorities extends ArrayList<List<Object>> implements
12: List<List<Object>> {
13:
14: public void serverwrite(Priority priority)
15: throws InterruptedException {
16: priority.serverindex++;
17: if (priority.getServer() == Priority.NO_LIMIT_PRIORITY)
18: return;
19: // all parts
20: int i = 0;
21: // all counts
22: long l = 0;
23: // current priority count
24: long pc = 0;
25: // current priority part
26: int s = 0;
27: for (Object o : this ) {
28: // priority count
29: long c = ((Priority) o).getServerCount();
30: // priority part
31: int d = ((Priority) o).getServer();
32: if (c > 0 || o == priority) {
33: // add priority part
34: i += d;
35: if (o == priority) {
36: pc = c;
37: s = d;
38: }
39: }
40: // add priority count
41: l += c;
42: }
43: // System.out.println(priority.getServer() +"
44: // "+priority.getServerCount()/priority.getServer() +" "+ l / i);
45: if (pc / (s + .5) > l / (double) i)
46: // System.out.println(priority.getServer() +"
47: // "+priority.getServerCount()/priority.getServer() +" "+ l / i);
48: Thread.sleep(10);
49: }
50:
51: public void clientwrite(Priority priority)
52: throws InterruptedException {
53: priority.clientindex++;
54: if (priority.getClient() == Priority.NO_LIMIT_PRIORITY)
55: return;
56: // all parts
57: int i = 0;
58: // all counts
59: long l = 0;
60: // current priority count
61: long pc = 0;
62: // current priority part
63: int s = 0;
64: for (Object o : this ) {
65: // priority count
66: long c = ((Priority) o).getClientCount();
67: // priority part
68: int d = ((Priority) o).getClient();
69: if (c > 0 || ((Priority) o) == priority) {
70: // add priority part
71: i += d;
72: if (o == priority) {
73: pc = c;
74: s = d;
75: }
76: }
77: // add priority count
78: l += c;
79: }
80: if (pc / (s + .5) > l / (double) i)
81: Thread.sleep(10);
82: }
83: }
|