Source code: plugins/PingTasklet.java
1 package plugins;
2
3
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Collections;
7 import java.util.Collection;
8 import java.net.InetAddress;
9
10 import musli.aorta.Benchmark;
11 import musli.aorta.Worker;
12 import musli.aorta.Tasklet;
13 import musli.util.Logger;
14
15
16 /**
17 * This is the algoritm part.
18 * Can be used to "fire" a test in the cluster, as the PingTasklet returns with
19 * all the worker clients that where visited during the Task Compute.
20 *
21 *
22 * @author Rickard.Lundin ICQ=6589530
23 */
24
25 public class PingTasklet extends Tasklet
26 {
27
28 protected long floatNo=25;
29
30
31 /**
32 * Ping task
33 *
34 */
35
36 public PingTasklet(String ID)
37 {
38 super(ID);
39
40 }
41
42
43 public boolean calc()
44 {
45 result= new ArrayList();
46
47 //
48 spendTime(needTotFloatOps());
49
50 // As result
51 ((List)result).add("CALC no="+no+" didTotFloatOps="+needTotFloatOps()+" WorkerID="+Worker.getInstance().getWorkerID()+" Host="+musli.aorta.Worker.getInstance().getHostName());
52
53
54 //
55
56
57 return true;
58 }
59
60 public boolean merge(Tasklet task)
61 {
62 ((List)result).addAll((Collection)task.getResult());
63 return true;
64 }
65
66 public Tasklet split(Benchmark rate)
67 {
68 long flops=0;
69 PingTasklet delegate=new PingTasklet(ID);
70
71
72 flops=(long) (rate.getFlops()*(1000000f));
73 Logger.log("rate.getflops="+rate.getFlops());
74 Logger.log("flops="+flops);
75 Logger.log("flops="+floatNo);
76
77 delegate.floatNo=floatNo-flops;
78
79
80 if(delegate.floatNo<=0)
81 return null; // Signalera ingen delegering!
82
83 floatNo=flops;
84
85
86 return delegate;
87
88 }
89
90
91 /**
92 * Gives amount of "multiplications/additions" in total for this task (Mega)
93 *
94 */
95
96 public float needTotFloatOps()
97 {
98 return floatNo/1000000f;
99 }
100
101 public boolean needJDBC()
102 {
103 return false;
104 }
105
106 public boolean needNET()
107 {
108 return false;
109 }
110
111 public long needRamSize()
112 {
113 return 2; // Needs 2 Mb of RAM.
114 }
115
116
117 public void setFloatNo(long floatNo)
118 {
119 this.floatNo=floatNo;
120 }
121
122 /**
123 * Silly function does the actual calculations that this client has decided to to.
124 * Hopfully it takes the amount of time that the Bencmark of this client has calculated !
125 * NOTE: As you can see this function is doing the reverse of the Constructor of Benchmark()
126 */
127 public void spendTime(float javaMegaFlops)
128 {
129 float a,b,c,d,e,f,g,h,i,j;
130 a=1.1f;
131 b=2.2f;
132 c=3.3f;
133 d=4.4f;
134 e=5.5f;
135 f=6.6f;
136 g=7.7f;
137 h=8.8f;
138 i=9.9f;
139 j=10.10f;
140
141 float alpha=2.123456789f;
142
143 // 100 miljons multiplications. =1 MegaJavaFlops
144 int no=(int)(1000000f*javaMegaFlops);
145
146 no*=Worker.getInstance().getPrefs().maxTime();
147
148 for(int n=0;n<no;n++)
149 {
150 a*=alpha;
151 b*=alpha;
152 c*=alpha;
153 d*=alpha;
154 e*=alpha;
155 f*=alpha;
156 g*=alpha;
157 h*=alpha;
158 i*=alpha;
159 j*=alpha;
160 }
161 }
162 }