| Home >> All >> cxtable >> [ core_comm Javadoc ] |
Source code: cxtable/core_comm/xListenerDispatch.java
1 package cxtable.core_comm; 2 import cxtable.peer.xPlugClientListen; 3 4 5 6 7 /*this is a threaded dispatcher..it receives the registry of listeners... 8 the xMessageConverter (uses it one at a time) and the line read... 9 It dispatches the line to each listener registered*/ 10 11 /*new xListenerDispatch function...including updated xListener interface... 12 This will now first ask an xListener if it reads all (readAll()).. 13 if (true){dispatch;return;} 14 if (false){request String[] of keys from xListener; 15 navigate String[]: 16 if (true){dispatch;return;} 17 if still there, fall-through 18 } 19 20 */ 21 22 23 import java.util.Vector; 24 25 public class xListenerDispatch extends Thread{ 26 27 private xListenerRegistry listen; private String rd; 28 private String[] rds; 29 private boolean single; 30 private boolean debug=false; 31 private xMessageConverter xmc; 32 private String _s; 33 private String[] _ss; 34 35 static{System.out.println("Dynamic xListenerDispatch vers 11-21-01");} 36 37 38 39 public xListenerDispatch(xListenerRegistry v, xMessageConverter xm, String s) 40 { xmc=xm; 41 listen=v; 42 single=true; 43 _s=s; 44 45 } 46 47 public void setDeb(boolean b){ 48 debug = b;} 49 public void run() 50 { 51 if (_s == null){System.out.println("xListenerDispatch:null"); 52 return;} 53 long start = System.currentTimeMillis(); 54 if (xmc == null){xmc=new xMessageConverter();} 55 56 /*'low level' pack|unpack new 7-16-01*/ 57 58 try{rd = xmc.unpack(_s);} 59 60 catch(Exception e){ 61 62 rd=_s;} 63 64 65 xListener[] xl = listen.on(); 66 67 for (int j=0; j<xl.length; j++) 68 { 69 if (xl[j] ==null) 70 { 71 continue;} 72 73 try { 74 if (debug==true){System.out.println("Dispatching to "+xl[j].who());} 75 if (xl[j].readAll()==true) 76 {xl[j].read(rd);continue;} 77 78 String[] kys = xl[j].readKeys(); 79 for (int q=0; q<kys.length;q++) 80 { 81 int p = rd.indexOf(kys[q]); 82 if (p>-1) 83 {xl[j].read(rd);continue; 84 } 85 } 86 } 87 88 catch(Exception e){ 89 System.out.println("Failed at xlistener"); 90 try{System.out.println("who?:"+xl[j].who()+e.toString());} 91 catch(Exception ee){ 92 System.out.println("who?null"+ee.toString());} 93 try{xPlugClientListen xxx = (xPlugClientListen)xl[j]; 94 System.out.println("xPCL:Failed at reading-->"+rd); 95 e.printStackTrace();} 96 catch(Exception cce){ 97 } 98 } 99 100 101 } 102 benchmark(start); 103 } 104 105 private void benchmark(long l) 106 { 107 long end = System.currentTimeMillis(); 108 long tot = end-l; 109 System.out.println("Dispatcher 11-21-01, dispatched in "+tot+" millis.."); 110 } 111 112 113 }