Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: cxtable/core_comm/xAutoProcessor.java


1   package cxtable.core_comm;
2   import cxtable.gui.xPanel;
3   
4   import cxtable.*;
5   
6   /*This class is new as of 10-26-01..intended to be used for
7   roundtrip benchmarks...but also for auto command processing
8   and custom command "negotiating"..more later*/
9   
10  
11   public class xAutoProcessor extends Thread implements xListener{
12  
13  private xLineSplit xline =new xLineSplit();
14  private xClientConn xcc;
15  private xPanel report=null;
16  
17  
18  
19  public xAutoProcessor(xClientConn x)
20  {
21  xcc=x;
22  }
23  
24  public xAutoProcessor(xClientConn x, xPanel xpan)
25  {
26  report=xpan; 
27  xcc=x;
28  }
29  
30  public void run()
31  {
32  xcc.setListen(this);
33  }
34  
35  public String who()
36  {
37  try{
38  return "((xAutoProcessor{10-26-01}:xcc:"+xcc.who()+"))";
39  }
40  catch(Exception e){}
41  return "xAutoProcessor::10-26-01";
42  }
43  
44  public boolean readAll()
45  {return false;}
46  
47  public String[] readKeys()
48  {
49  return new String[]{"<BENCHF>","<BENCHS>"};
50  }
51  
52  
53  
54  public void read(String s)
55  {
56  /*for benchmarking*/
57  long bench = System.currentTimeMillis();
58  
59  /*replace with dynamic commands*/
60  String[] comms = xline.split("BENCHF",s);
61  relay_proc(comms);
62  String[] comm2= xline.split("BENCHS",s);
63  return_proc(comm2, bench);
64  }
65  
66  private  void relay_proc(String[] s)
67  {
68  if (s.length < 1){return;}
69  
70  try{
71     for (int i=0; i<s.length;i++)
72    {
73    xcc.send("<BENCHS>"+s[i]+"</BENCHS>");
74    }
75      }
76    catch(Exception e){System.out.println("Error sending bench-relay");}
77  
78  
79  return;
80  }
81  
82  public void return_proc(String[] s, long b)
83  {
84  if(s.length < 1){return;}
85  
86  try{
87      for (int i=0; i<s.length;i++)
88    {
89    String dat = xline.ssplit("START",s[i]);
90    try{
91        long start = Long.parseLong(dat);
92        double st = (double)start;
93        double ed=(double)b;
94        double dif =( ed-st)/1000;
95        String mssg="Benchmark for "+xcc.getRegID()+"\n";
96        mssg =mssg+"Round trip(in sec):"+dif+"\n";
97        double rate = s[i].length()/dif;
98        mssg=mssg+"Roundtripped at "+rate+" chars-per-sec";
99        if (report !=null) {report.post(mssg);}
100      System.out.println(who()+"::"+mssg);
101       }
102      catch(Exception e)
103     {System.out.println("Failed at processing bench");
104      if (report !=null) {report.post("Failed processing bench request");}
105     }
106   }
107 
108     }catch(Exception e){}
109 return;
110 }
111 
112 }