Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

DataThread.java

Go to the documentation of this file.
00001 00008 package org.nees.daq; 00009 00010 import java.net.*; 00011 import java.io.*; 00012 import java.util.*; 00013 import com.rbnb.sapi.*; 00014 00026 public class DataThread implements Runnable{ 00027 00028 private Socket socket; 00029 private BufferedReader rd; 00030 private Thread theThread; 00031 private boolean running = false; 00032 00033 private Hashtable channelTable = new Hashtable(); 00034 00040 public DataThread(Socket socket) 00041 throws IOException 00042 { 00043 rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); 00044 } 00045 00049 public void start() 00050 { 00051 if (theThread != null) return; 00052 theThread = new Thread(this); 00053 running = true; 00054 theThread.start(); 00055 } 00056 00058 public void stop() 00059 { 00060 running = false; 00061 } 00062 00075 public void run () { 00076 00077 String fromDAQ; 00078 StringTokenizer st; 00079 ISOtoRbnbTime timestamp; 00080 double time; 00081 String channelName; 00082 double data; 00083 DaqListener channel; 00084 00085 // System.out.println("Running thread for DAQ data"); 00086 00087 try { 00088 while(((fromDAQ = rd.readLine()) != null) && running) { 00089 //System.out.println("Line from DAQ: " + fromDAQ); 00090 00092 if(fromDAQ.startsWith("driverid")) { 00093 System.out.println("Skipping driverid: " + fromDAQ); 00094 }else { 00095 // Want to split out the timestamp, all up to tab char 00096 st = new StringTokenizer(fromDAQ, "\t\n"); 00097 00098 String tsString = st.nextToken(); 00099 timestamp = new ISOtoRbnbTime(tsString); 00100 if (!timestamp.is_valid) 00101 { 00102 System.out.println("Warning: timestamp not valid: " + tsString); 00103 } 00104 time = timestamp.getValue(); 00105 00107 while (st.hasMoreTokens()) 00108 { 00109 channelName = st.nextToken(); 00110 data = Double.parseDouble(st.nextToken()); 00111 channel = (DaqListener)channelTable.get(channelName); 00112 if (channel != null) 00113 { 00114 channel.postData(channelName,time,data); 00115 } 00116 } 00117 } 00118 } 00119 } 00120 catch (Exception e) { 00121 System.out.println("Socket IO Error: " + e); 00122 } 00123 finally 00124 { 00125 theThread = null; 00126 running = false; 00127 } 00128 } 00129 00145 public void addListener(String name, DaqListener l) 00146 { 00147 channelTable.put(name,l); 00148 } 00149 00160 public void removeListener(String name) 00161 { 00162 channelTable.remove(name); 00163 } 00164 00165 public boolean isRunning() 00166 { 00167 return running; 00168 } 00169 }

Generated on Tue Aug 24 11:12:25 2004 for Data turbine for NEESGrid by doxygen 1.3.7