1 //header of class--------------------------------------------------------------- 2 import java.*; 3 import java.io.*; 4 import java.util.*; 5 6 public class zServer{ 7 public static String INIFILE= "zServer.ini"; 8 public static Hashtable constants; 9 public static Hashtable threads; 10 public static Hashtable services; 11 public final static int BUILD=80; 12 //main.zdys--------------------------------------------------------------------- 13 public static void main(String[] args){ 14 constants= new Hashtable(); 15 threads= new Hashtable(); 16 services= new Hashtable(); 17 try{ 18 BufferedReader br= new BufferedReader(new FileReader(INIFILE)); 19 String[] arg; 20 while((arg= getNextLine(br))!= null){ 21 if(arg[0].equals("constants{")){ 22 while(!(arg= getNextLine(br))[0].equals("}")){ 23 if(arg[0].endsWith("{")){ 24 String newhash= arg[0].substring(0, arg[0].length()- 1); 25 Hashtable hash= new Hashtable(); 26 while(!(arg= getNextLine(br))[0].equals("}")){ 27 hash.put(arg[0], arg[1]); 28 } 29 constants.put(newhash, hash); 30 } 31 } 32 }else if(arg[0].equals("threads{")){ 33 while(!(arg= getNextLine(br))[0].equals("}")){ 34 threads.put(arg[1], startCommandLineThread(arg)); 35 } 36 }else if(arg[0].equals("services{")){ 37 while(!(arg= getNextLine(br))[0].equals("}")){ 38 services.put(arg[2]+ ":"+ arg[1], startCommandLineThread(arg)); 39 } 40 }else if(arg[0].startsWith("#")){ 41 ; // ignore comment 42 }else{ 43 Utils.pr("ERROR unrecognized line:"+ arg.toString()); 44 } 45 } 46 }catch(Throwable tw){ 47 Utils.pr("ERROR in zServer.main:"+ tw); 48 } 49 } 50 //getNextLine.zdys-------------------------------------------------------------- 51 private static String[] getNextLine(BufferedReader br)throws IOException{ 52 String line; 53 do{ 54 line= br.readLine(); 55 if(line== null){ 56 return(null); 57 } 58 }while(line.startsWith("#")); 59 return(toStringArray(line, ";")); 60 } 61 //startCommandLineThread.zdys--------------------------------------------------- 62 private static CommandLineThread startCommandLineThread(String[] arg){ 63 try{ 64 CommandLineThread clt= (CommandLineThread)(Class.forName(arg[0])).newInstance(); 65 clt.arg= arg; 66 clt.start(); 67 return(clt); 68 }catch(Exception ex){ 69 Utils.pr("ERROR in startCommandLineThread("+ arg+ "):"+ ex); 70 return(null); 71 } 72 } 73 //toStringArray.zdys------------------------------------------------------------ 74 public static String[] toStringArray(String line, String delimiter){ 75 if(line== null){ 76 return(new String[]{}); 77 } 78 StringTokenizer st= new StringTokenizer(line, delimiter); 79 String[] ret= new String[st.countTokens()]; 80 int pos= 0; 81 while(st.hasMoreTokens()){ 82 ret[pos]= st.nextToken().trim(); 83 pos++; 84 } 85 return(ret); 86 } 87 //killServer.zdys--------------------------------------------------------------- 88 public static void killServer(){ 89 Utils.pr("killServer called, terminating"); 90 System.exit(1); 91 } 92 //end of class------------------------------------------------------------------ 93 }