001: package demo.poa_monitor.client;
002:
003: import demo.poa_monitor.foox.*;
004: import org.omg.CosNaming.*;
005: import java.io.*;
006:
007: public class Client {
008: public static int speed = 0;
009: public static int cost = 0;
010: public static String serverDescription = "description not available";
011:
012: private static TestFrame frame;
013: private static FooFactory factory;
014: private static Foo[] foos;
015: private static RequestGenerator[][] generators;
016:
017: private static int allConsumed;
018: private static int allEffort;
019: private static int firstPOAConsumed;
020: private static int firstPOAEffort;
021: private static int firstObjectConsumed;
022: private static int firstObjectEffort;
023: private static int allICount;
024: private static int firstPOAICount;
025: private static int firstObjectICount;
026: private static boolean firstPOAContact = true;
027:
028: public static void actionCancel() {
029: actionStop();
030: try {
031: for (int i = 0; i < generators.length; i++) {
032: for (int k = 0; k < generators[i].length; k++) {
033: generators[i][k].join();
034: }
035: }
036: } catch (Throwable e) {
037: }
038: System.exit(0);
039: }
040:
041: public static void actionStart(int objects, int threads) {
042: foos = new Foo[objects];
043: generators = new RequestGenerator[objects][threads];
044: try {
045: for (int i = 0; i < foos.length; i++) {
046:
047: if (firstPOAContact) {
048: long startTime = System.currentTimeMillis();
049: foos[i] = factory.createFoo("" + (1000 + i));
050: long stopTime = System.currentTimeMillis();
051: Client.addTime((int) (stopTime - startTime), 0,
052: false);
053: firstPOAContact = false;
054:
055: } else {
056: foos[i] = factory.createFoo("" + (1000 + i));
057: }
058: if (foos[i] == null)
059: throw new Error("error: createFoo returns null");
060:
061: for (int k = 0; k < threads; k++) {
062: generators[i][k] = new RequestGenerator(foos[i],
063: k == 0);
064: if (k == 0)
065: generators[i][k].start();
066: }
067: }
068: Thread.currentThread().sleep(1000);
069: for (int i = 0; i < generators.length; i++) {
070: for (int k = 1; k < generators[i].length; k++) {
071: generators[i][k].start();
072: }
073: }
074: System.out.println("[ " + (objects * threads)
075: + " RequestGenerators started ]");
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079: }
080:
081: public static void actionStop() {
082: for (int i = 0; i < generators.length; i++) {
083: for (int k = 0; k < generators[i].length; k++) {
084: generators[i][k].active = false;
085: }
086: }
087:
088: System.out.println("[ RequestGenerators stopped ]");
089:
090: for (int i = 0; i < foos.length; i++) {
091: try {
092: foos[i].deactivate();
093: } catch (Throwable e) {
094: System.out
095: .println("[ exception occured during object deactivation ]");
096: System.out.println(e.toString());
097: }
098: }
099: System.out
100: .println("[ Remote objects deactivated (don't worry about wrong policy exception messages s\n in server 3 (Servant Locator) ]");
101: printTime();
102: }
103:
104: synchronized public static void addTime(int consumed, int effort,
105: boolean firstObjectContact) {
106: if (firstPOAContact) {
107: firstPOAConsumed += consumed;
108: firstPOAEffort += effort;
109: firstPOAICount++;
110: return;
111: }
112: if (firstObjectContact) {
113: firstObjectConsumed += consumed;
114: firstObjectEffort += effort;
115: firstObjectICount++;
116: }
117: allConsumed += consumed;
118: allEffort += effort;
119: allICount++;
120: }
121:
122: public static void main(String args[]) {
123: try {
124: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
125: // get hold of the naming service and create a fooFactory object
126: NamingContextExt nc = NamingContextExtHelper.narrow(orb
127: .resolve_initial_references("NameService"));
128: factory = FooFactoryHelper.narrow(nc.resolve(nc
129: .to_name("FooFactory.service")));
130: System.out.println("[ FooFactory created ]");
131:
132: // get the server description
133: serverDescription = factory.getServerDescription();
134:
135: // set up the gui
136: frame = new TestFrame();
137: frame.setVisible(true);
138: } catch (Exception e) {
139: e.printStackTrace();
140: }
141: }
142:
143: public static void printTime() {
144:
145: /*
146: long startTime = System.currentTimeMillis();
147: while (nb-- > 0)
148: ret_vals = server.intTransfer(myInt);
149:
150: // for(int i = 0; i < size; System.out.print(" " + ret_vals[i++]));
151:
152: long stopTime = System.currentTimeMillis();
153: System.out.println(">>> Elapsed time = "
154: + (stopTime - startTime)/1000
155: + " secs Average time = "
156: + ((stopTime - startTime) / (float)loop)
157: + " msecs");
158:
159: if (firstPOAContact) {
160: firstPOAConsumed += consumed;
161: firstPOAEffort += effort;
162: } else if (firstObjectContact) {
163: firstObjectConsumed += consumed;
164: firstObjectEffort += effort;
165: }
166: allConsumed += consumed;
167: allEffort += effort;
168: invocationCount++;
169: */
170: String v;
171: int w = 12;
172: int its_p = firstPOAConsumed - firstPOAEffort;
173: int its_o = firstObjectConsumed - firstObjectEffort;
174: int its_a = allConsumed - allEffort;
175: float ita_p = its_p / (float) firstPOAICount;
176: float ita_o = its_o / (float) firstObjectICount;
177: float ita_a = its_a / (float) allICount;
178:
179: System.out
180: .println(" IS CTS(s) CTA(ms) ETS(s) ETA(ms) ITS(s) ITA(ms)");
181: System.out
182: .println(" ---------------------------------------------------------------------------------------");
183: System.out.print("FPCL: ");
184: v = firstPOAICount + "";
185: System.out.print(v);
186: for (int i = v.length(); i <= w; i++)
187: System.out.print(" ");
188: v = firstPOAConsumed / (float) 1000 + "";
189: System.out.print(v);
190: for (int i = v.length(); i <= w; i++)
191: System.out.print(" ");
192: v = firstPOAConsumed / (float) firstPOAICount + "";
193: System.out.print(v);
194: for (int i = v.length(); i <= w; i++)
195: System.out.print(" ");
196: v = firstPOAEffort / (float) 1000 + "";
197: System.out.print(v);
198: for (int i = v.length(); i <= w; i++)
199: System.out.print(" ");
200: v = firstPOAEffort / (float) firstPOAICount + "";
201: System.out.print(v);
202: for (int i = v.length(); i <= w; i++)
203: System.out.print(" ");
204: v = its_p / (float) 1000 + "";
205: System.out.print(v);
206: for (int i = v.length(); i <= w; i++)
207: System.out.print(" ");
208: v = ita_p + "";
209: System.out.print(v);
210: for (int i = v.length(); i <= w; i++)
211: System.out.print(" ");
212:
213: System.out.println("\n");
214: System.out.print("FOCL: ");
215: v = firstObjectICount + "";
216: System.out.print(v);
217: for (int i = v.length(); i <= w; i++)
218: System.out.print(" ");
219: v = firstObjectConsumed / (float) 1000 + "";
220: System.out.print(v);
221: for (int i = v.length(); i <= w; i++)
222: System.out.print(" ");
223: v = firstObjectConsumed / (float) firstObjectICount + "";
224: System.out.print(v);
225: for (int i = v.length(); i <= w; i++)
226: System.out.print(" ");
227: v = firstObjectEffort / (float) 1000 + "";
228: System.out.print(v);
229: for (int i = v.length(); i <= w; i++)
230: System.out.print(" ");
231: v = firstObjectEffort / (float) firstObjectICount + "";
232: System.out.print(v);
233: for (int i = v.length(); i <= w; i++)
234: System.out.print(" ");
235: v = its_o / (float) 1000 + "";
236: System.out.print(v);
237: for (int i = v.length(); i <= w; i++)
238: System.out.print(" ");
239: v = ita_o + "";
240: System.out.print(v);
241: for (int i = v.length(); i <= w; i++)
242: System.out.print(" ");
243:
244: System.out.println("\n");
245: System.out.print("All : ");
246: v = allICount + "";
247: System.out.print(v);
248: for (int i = v.length(); i <= w; i++)
249: System.out.print(" ");
250: v = allConsumed / (float) 1000 + "";
251: System.out.print(v);
252: for (int i = v.length(); i <= w; i++)
253: System.out.print(" ");
254: v = allConsumed / (float) allICount + "";
255: System.out.print(v);
256: for (int i = v.length(); i <= w; i++)
257: System.out.print(" ");
258: v = allEffort / (float) 1000 + "";
259: System.out.print(v);
260: for (int i = v.length(); i <= w; i++)
261: System.out.print(" ");
262: v = allEffort / (float) allICount + "";
263: System.out.print(v);
264: for (int i = v.length(); i <= w; i++)
265: System.out.print(" ");
266: v = its_a / (float) 1000 + "";
267: System.out.print(v);
268: for (int i = v.length(); i <= w; i++)
269: System.out.print(" ");
270: v = ita_a + "";
271: System.out.print(v);
272: for (int i = v.length(); i <= w; i++)
273: System.out.print(" ");
274:
275: System.out.println("");
276: System.out
277: .println(" ---------------------------------------------------------------------------------------");
278: System.out.println("");
279: System.out
280: .println(" I...invocation C...consumed T...time S...sum A...average");
281: System.out
282: .println(" F...first P...poa - O...object C...contact L...latency");
283: System.out.println("");
284: }
285: }
|