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

DataVideoGather.java

00001 /* 00002 * Created on May 12, 2004 00003 * ****************************************************************************** 00004 * CVS Header $Header: /disks/cvs/neesgrid/turbine/src/org/nees/rbnb/DataVideoGather.java,v 1.10 2004/08/02 17:02:09 weymouth Exp $ 00005 * ****************************************************************************** 00006 */ 00007 package org.nees.rbnb; 00008 00009 import java.io.IOException; 00010 import java.io.PrintWriter; 00011 import java.io.FileWriter; 00012 import java.io.File; 00013 import java.util.StringTokenizer; 00014 import java.util.Vector; 00015 import java.util.Iterator; 00016 import java.util.Stack; 00017 import java.util.Date; 00018 import java.util.TimeZone; 00019 import java.text.SimpleDateFormat; 00020 00021 import java.util.regex.*; 00022 00023 import com.rbnb.sapi.*; 00024 import com.rbnb.utility.ArgHandler; //for argument parsing 00025 //import COM.Creare.Utility.ArgHandler; //for argument parsing 00026 00045 public class DataVideoGather extends RBNBBase { 00046 00047 private final String SINK_NAME_NAME = "SinkName"; 00048 private final String CHANNEL_PATTERN_NAME = "ChannelPattern"; 00049 private final String CHANNEL_LIST_NAME = "ChannelList"; 00050 private final String INCLUDE_HIDDEN_NAME = "IncludeHidden"; 00051 private final String ZERO_FOR_MISSING_NAME = "ZeroForMissingData"; 00052 private final String VIDEO_SOURCE_PATH_NAME = "VideoSourcePath"; 00053 private final String ARCHIVE_DIRECTORY_NAME = "ArchiveDirectory"; 00054 private final String MOVIE_FILE_NAME_NAME = "MovieFileName"; 00055 private final String DATA_FILE_NAME_NAME = "DataFileName"; 00056 private final String USER_GIVEN_FRAME_RATE_NAME = "UserGivenFrameRate"; 00057 private final String ITEMS_TO_SKIP_NAME = "ItemsToSkip"; 00058 private final String WAIT_TIME_NAME = "WaitTime"; 00059 private final String COLLECTION_TIME_NAME = "CollectionTime"; 00060 00061 private static final String SINK_NAME = "DataVideoGather"; 00062 private static final String ARCHIVE_DIRECTORY = "."; 00063 private static final String DATA_FILE_NAME = "Data.txt"; 00064 private static final String MOVIE_FILE_NAME = "Movie.mov"; 00065 00066 private static final String CHANNEL_PATTERN = ""; 00067 private static final String CHANNEL_LIST = ""; 00068 private static final boolean INCLUDE_HIDDEN = false; 00069 private static final boolean ZERO_FOR_MISSING = false; 00070 private static final String VIDEO_SOURCE_PATH = ""; 00071 00072 private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MMM d, yyyy h:mm aa"); 00073 private static final TimeZone TZ = TimeZone.getTimeZone("GMT"); 00074 00075 private static float USER_GIVEN_FRAME_RATE = 1.0F; 00076 private static int ITEMS_TO_SKIP = 0; 00077 00078 private static long WAIT_TIME = 30*60; // in seconds 00079 private static long COLLECTION_TIME = WAIT_TIME; 00080 00081 private static final SimpleDateFormat OUTPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss.SSS"); 00082 00083 static 00084 { 00085 DATE_FORMAT.setTimeZone(TZ); 00086 OUTPUT_FORMAT.setTimeZone(TZ); 00087 } 00088 00089 private String sinkName = SINK_NAME; 00090 private String channelPathPattern = null; 00091 private String channelPathListString = null; 00092 private Vector channelPathList = new Vector(); 00093 private String videoChannelPath = null; 00094 private String[] channelPathArray; 00095 private boolean includeHidden = false; 00096 private String archiveDirectory = ARCHIVE_DIRECTORY; 00097 private String dataFileName = DATA_FILE_NAME; 00098 private String movieFileName = MOVIE_FILE_NAME; 00099 private float userGivenFrameRate = USER_GIVEN_FRAME_RATE; 00100 private int itemsToSkip = ITEMS_TO_SKIP; 00101 private boolean repeatMissingValue = true; 00102 00103 private boolean connected = false; 00104 private boolean runit = true; 00105 private Thread fetchDataThread; 00106 private long waitTime = WAIT_TIME; // in seconds 00107 // private long waitTime = 60; // one minute 00108 private long collectionTime = waitTime; 00109 00110 // This should be fixed now 00111 // private double uglyOffset = 5.0; 00112 00113 private String[] parameterNameArray; 00114 private String[] parameterTypeArray; 00115 private Object[] parameterDefaultArray; 00116 00117 public static void main(String[] args) { 00118 DataVideoGather d = new DataVideoGather(); 00119 d.setArgs(args); 00120 d.testConnect(); 00121 d.startThread(); 00122 } // main 00123 00124 public void printUsage() { 00125 System.out.println("DataVideoGather: usage is..."); 00126 System.out.println("DataVideoGather "); 00127 super.printUsage(); 00128 System.out.println("[-k Sink Name *" + SINK_NAME + " ]"); 00129 System.out.println("[-c Data Channels Path Pattern - pearl-like pattern to match] "); 00130 System.out.println("[-C Data Channels list - comma seperated lsit of Paths]"); 00131 System.out.println("[-x Include Hidden channels (true|false) *false]"); 00132 System.out.println("[-Z zero for missing data; otherzise last value repeats]"); 00133 System.out.println("[-v Video Source path - no path for no movie]"); 00134 System.out.println("[-d Archive directory root *" + ARCHIVE_DIRECTORY + "]"); 00135 System.out.println("[-M Movie output file name *" + MOVIE_FILE_NAME + "]"); 00136 System.out.println("[-D Data output file name *" + DATA_FILE_NAME + "]"); 00137 System.out.println("[-f Frame Rate of final movie *" + USER_GIVEN_FRAME_RATE + "]"); 00138 System.out.println("[-i Items to skip in data for each movie frame *" + 00139 ITEMS_TO_SKIP +"]"); 00140 System.out.println("[-w Wait Time in seconds; the time between cycles *" 00141 + WAIT_TIME + "]"); 00142 System.out.println("[-W Collection time in seconds; defaults to Wait Time]"); 00143 // System.out.println("[-u magic offset *"+ uglyOffset + "]"); 00144 } // printUsage 00145 00146 public DataVideoGather() { 00147 setParamterArrays(); 00148 initialize(); 00149 } 00150 00151 public boolean setInstanceArgs (String[] args) { 00152 //parse args 00153 try { 00154 ArgHandler ah=new ArgHandler(args); 00155 if (ah.checkFlag('k')) { 00156 String a=ah.getOption('k'); 00157 if (a!=null) sinkName=a; 00158 } 00159 if (ah.checkFlag('c')) { 00160 String a=ah.getOption('c'); 00161 if (a!=null) channelPathPattern=a; 00162 } 00163 if (ah.checkFlag('C')) { 00164 String a=ah.getOption('C'); 00165 if (a!=null) channelPathListString=a; 00166 } 00167 if (ah.checkFlag('w')) { 00168 String a=ah.getOption('w'); 00169 if (a!=null) 00170 { 00171 try 00172 { 00173 long value = Long.parseLong(a); 00174 waitTime = value; 00175 } 00176 catch (Exception ex) 00177 { 00178 System.out.println("Failed to parse Wait Time (" + a + "): " + ex); 00179 } 00180 } 00181 } 00182 if (ah.checkFlag('W')) { 00183 String a=ah.getOption('W'); 00184 if (a!=null) 00185 { 00186 try 00187 { 00188 long value = Long.parseLong(a); 00189 collectionTime = value; 00190 } 00191 catch (Exception ex) 00192 { 00193 System.out.println("Failed to parse Collection Time (" + a + "): " + ex); 00194 } 00195 } 00196 } 00197 if (ah.checkFlag('x')) { 00198 String a=ah.getOption('x'); 00199 if (a!=null) 00200 { 00201 if (a.equals("true")) includeHidden = true; 00202 if (a.equals("false")) includeHidden = false; 00203 } 00204 } 00205 if (ah.checkFlag('v')) { 00206 String a=ah.getOption('v'); 00207 if (a!=null) videoChannelPath=a; 00208 } 00209 if (ah.checkFlag('d')) { 00210 String a=ah.getOption('d'); 00211 if (a!=null) archiveDirectory=a; 00212 } 00213 if (ah.checkFlag('M')) { 00214 String a=ah.getOption('M'); 00215 if (a!=null) movieFileName=a; 00216 } 00217 if (ah.checkFlag('D')) { 00218 String a=ah.getOption('D'); 00219 if (a!=null) dataFileName=a; 00220 } 00221 if (ah.checkFlag('f')) { 00222 String a=ah.getOption('f'); 00223 if (a!=null) 00224 { 00225 try 00226 { 00227 float value = Float.parseFloat(a); 00228 userGivenFrameRate = value; 00229 } 00230 catch (Exception ex) 00231 { 00232 System.out.println("Failed to parse Frame Rate (" + a + "): " + ex); 00233 } 00234 } 00235 } 00236 if (ah.checkFlag('i')) { 00237 String a=ah.getOption('i'); 00238 if (a!=null) 00239 { 00240 try 00241 { 00242 int value = Integer.parseInt(a); 00243 itemsToSkip = value; 00244 } 00245 catch (Exception ex) 00246 { 00247 System.out.println("Failed to parse Frame Rate (" + a + "): " + ex); 00248 } 00249 } 00250 } 00251 if (ah.checkFlag('Z')) { 00252 repeatMissingValue = false; 00253 } 00254 // if (ah.checkFlag('u')) { 00255 // String a=ah.getOption('u'); 00256 // if (a!=null) 00257 // { 00258 // try 00259 // { 00260 // double value = Double.parseDouble(a); 00261 // uglyOffset = value; 00262 // } 00263 // catch (Exception ex) 00264 // { 00265 // System.out.println("Failed to parse magic offset (" + a + "): " + ex); 00266 // } 00267 // } 00268 // } 00269 } catch (Exception e) { 00270 System.err.println("DataVideoGather argument exception "+e.getMessage()); 00271 e.printStackTrace(); 00272 System.exit(0); 00273 } 00274 00275 setupChannelList(); 00276 00277 System.out.println("Starting DataVideoGather on " + getServer() + " as " + sinkName); 00278 System.out.println("Gatering data from: "); 00279 for (int i = 0; i < channelPathArray.length; i++) 00280 { 00281 System.out.println(" " + channelPathArray[i]); 00282 } 00283 if ((videoChannelPath != null) && (!videoChannelPath.equals(""))) 00284 { 00285 System.out.println("Gatering video from: " + videoChannelPath); 00286 System.out.println("Frame rate = " + userGivenFrameRate + " frames per second."); 00287 System.out.println("Data frames to skip between video frame = " + itemsToSkip); 00288 } 00289 00290 System.out.println(" Use DataVideoGather -h to see optional parameters"); 00291 00292 return true; 00293 } // sestArgs 00294 00295 private void setupChannelList() 00296 { 00297 channelPathList = new Vector(); 00298 00299 if ((channelPathPattern != null) && !channelPathPattern.equals("")) 00300 appendChannelListFromPattern(); 00301 if ((channelPathListString != null) && !channelPathListString.equals("")) 00302 appendChannelListFromString(); 00303 00304 Iterator channels = channelPathList.iterator(); 00305 if (!channels.hasNext()) 00306 { 00307 System.out.println("DataVideoGather: No data channels to monitor."); 00308 this.printUsage(); 00309 System.exit(0); 00310 } 00311 00312 channelPathArray = new String[channelPathList.size()]; 00313 for (int i = 0; i < channelPathArray.length; i++) 00314 { 00315 ChannelTree.Node candidate = (ChannelTree.Node)channels.next(); 00316 channelPathArray[i] = candidate.getFullName(); 00317 } 00318 } 00319 00320 00321 public void appendChannelListFromPattern() 00322 { 00323 try { 00324 // Create a sink and connect: 00325 Sink sink=new Sink(); 00326 sink.OpenRBNBConnection(getServer(),sinkName); 00327 00328 // get all the channel paths that match the pattern 00329 ChannelMap sMap = new ChannelMap(); 00330 sink.RequestRegistration(); 00331 sMap = sink.Fetch(-1,sMap); 00332 ChannelTree tree = ChannelTree.createFromChannelMap(sMap); 00333 00334 Pattern p = Pattern.compile(channelPathPattern); 00335 // for each channel path, check match, collect matches... 00336 00337 Iterator nodes = tree.iterator(); 00338 while (nodes.hasNext()) 00339 { 00340 ChannelTree.Node n = (ChannelTree.Node)nodes.next(); 00341 // System.out.println("Checking " + n.getFullName() + ";" + n.getName()); 00342 if (!includeHidden && n.getFullName().startsWith("_")) continue; 00343 if (n.getType() != ChannelTree.CHANNEL) continue; 00344 String name = n.getFullName(); 00345 Matcher m = p.matcher(name); 00346 if (m.matches()) 00347 { 00348 // System.out.println("Matches"); 00349 boolean isSource = false; 00350 ChannelTree.Node upNode = n.getParent(); 00351 while ((!isSource) || (upNode != null)) 00352 { 00353 if (upNode.getType() == ChannelTree.SOURCE) isSource = true; 00354 upNode = upNode.getParent(); 00355 } 00356 if (isSource) 00357 { 00358 // System.out.println("... and is a source."); 00359 channelPathList.add(n); 00360 } 00361 else 00362 { 00363 // System.out.println("... and is NOT a source."); 00364 } 00365 } 00366 } 00367 00368 } catch (SAPIException se) { se.printStackTrace(); } 00369 } // appendChannelListFromPattern 00370 00371 public void appendChannelListFromString() 00372 { 00373 try 00374 { 00375 StringTokenizer st = new StringTokenizer(channelPathListString,","); 00376 00377 // Create a sink and connect: 00378 Sink sink=new Sink(); 00379 sink.OpenRBNBConnection(getServer(),sinkName); 00380 00381 // get all the channel paths that match the pattern 00382 ChannelMap sMap = new ChannelMap(); 00383 sink.RequestRegistration(); 00384 sMap = sink.Fetch(-1,sMap); 00385 ChannelTree tree = ChannelTree.createFromChannelMap(sMap); 00386 00387 Pattern p = Pattern.compile(channelPathPattern); 00388 // for each channel path, check match, collect matches... 00389 00390 while (st.hasMoreTokens()) { 00391 String path = st.nextToken(); 00392 // System.out.println("Checking " + path); 00393 00394 ChannelTree.Node n = tree.findNode(path); 00395 if (n == null) continue; 00396 if (n.getType() != ChannelTree.CHANNEL) continue; 00397 String name = n.getFullName(); 00398 // System.out.println("Found it..."); 00399 boolean isSource = false; 00400 ChannelTree.Node upNode = n.getParent(); 00401 while ((!isSource) || (upNode != null)) 00402 { 00403 if (upNode.getType() == ChannelTree.SOURCE) isSource = true; 00404 upNode = upNode.getParent(); 00405 } 00406 if (isSource) 00407 { 00408 // System.out.println("... and is a source."); 00409 channelPathList.add(n); 00410 } 00411 else 00412 { 00413 // System.out.println("... and is NOT a source."); 00414 } 00415 } // while next token 00416 } catch (SAPIException se) { se.printStackTrace(); } 00417 } // appendChannelListFromString 00418 00419 private void testConnect() 00420 { 00421 try { 00422 // test the connection to the server 00423 Sink sink = new Sink(); 00424 sink.OpenRBNBConnection(getServer(),sinkName); 00425 connected = true; 00426 System.out.println("DataVideoGather: Test connection made to server = " 00427 + getServer() + " as " + sinkName +"."); 00428 sink.CloseRBNBConnection(); 00429 } catch (SAPIException se) { se.printStackTrace(); } 00430 } 00431 00432 private void disconnect() 00433 { 00434 // nothing, really, to do as the connections are closed each cycle??? 00435 connected = false; 00436 } 00437 00438 public void startThread() 00439 { 00440 00441 if (!connected) return; 00442 00443 // Use this inner class to hide the public run method 00444 Runnable r = new Runnable() { 00445 public void run() { 00446 runWork(); 00447 } 00448 }; 00449 runit = true; 00450 fetchDataThread = new Thread(r, "DataVideoGather"); 00451 fetchDataThread.start(); 00452 System.out.println("DataVideoGather: Started thread."); 00453 } 00454 00455 public void stopThread() 00456 { 00457 runit = false; 00458 fetchDataThread.interrupt(); 00459 System.out.println("DataVideoGather: Stopped thread."); 00460 } 00461 00462 private void runWork () 00463 { 00464 long lastTime = System.currentTimeMillis(); 00465 try { 00466 // while(isRunning()) 00467 // { 00468 // doOneCycle(); 00469 // long actualWait = (waitTime * 1000) - (System.currentTimeMillis() - lastTime); 00470 // lastTime = System.currentTimeMillis(); 00471 // System.out.println("Actual Wait Time = " + actualWait); 00472 // if (actualWait < 0) actualWait = 0; 00473 // Thread.sleep(actualWait); 00474 // } 00475 00476 // modified to do one cycle only so that it can be 00477 // scripted; tew Aug 02, 2004 00478 if (isRunning()) 00479 doOneCycle(); 00480 00481 } catch (Exception se) { 00482 se.printStackTrace(); 00483 } 00484 fetchDataThread = null; 00485 } 00486 00487 public boolean isRunning() 00488 { 00489 return (connected && runit); 00490 } 00491 00492 private void doOneCycle() 00493 { 00494 System.out.println("One Cycle:"); 00495 System.out.println("Wait time = " + waitTime); 00496 System.out.println("Collection time = " + collectionTime); 00497 00498 long startTime = System.currentTimeMillis(); 00499 00500 DataVideoSink.DEBUG = true; 00501 // DataVideoSink.setUglyOffest(uglyOffset); 00502 DataVideoSink dataVideoSink = new DataVideoSink(); 00503 dataVideoSink.connect(getServer(),sinkName + "_data"); 00504 00505 double[][] data = new double[channelPathArray.length][0]; 00506 double[][] time = new double[channelPathArray.length][0]; 00507 00508 // collectionTime (long) in secods 00509 double duration = (double)collectionTime; // in seconds 00510 00511 if (dataVideoSink.connect(getServer(),sinkName)) 00512 { 00513 for (int i = 0; i < channelPathArray.length; i ++) 00514 { 00515 String dataSourcePath = channelPathArray[i]; 00516 // with "newest" time is figured backward from the present... 00517 dataVideoSink.fetchData(dataSourcePath, 0.0, duration,"newest"); 00518 data[i] = dataVideoSink.getDataArray(); 00519 time[i] = dataVideoSink.getTimeArray(); 00520 } 00521 00522 // for (int i = 0; i < channelPathArray.length; i ++) 00523 // { 00524 // System.out.println("Array lengths (" + i + ") are: " 00525 // + data[i].length + "," + time[i].length); 00526 // } 00527 00528 double[] referenceTime = time[0]; 00529 double[][] filledData = new double[channelPathArray.length][referenceTime.length]; 00530 int[] indexFront = new int[channelPathArray.length]; // initally zero 00531 int[] lastUsed = new int[channelPathArray.length]; 00532 00533 // force initial condition; no index last used 00534 for (int i = 0; i < lastUsed.length; i++) lastUsed[i] = -1; 00535 00536 // for each possible data slot determine the data with the correct time 00537 // filled in slots are eather duplications or zero 00538 for (int timeIndex = 0; timeIndex < referenceTime.length; timeIndex++) 00539 { 00540 // channel 0 is the referance channel, it's data value are always there 00541 filledData[0][timeIndex] = data[0][timeIndex]; 00542 for (int channelIndex = 1; channelIndex < channelPathArray.length; channelIndex++) 00543 { 00544 //System.out.println(" " + timeIndex + "," + channelIndex 00545 // + "," + lastUsed[channelIndex] + "," + indexFront[channelIndex]); 00546 00547 if (lastUsed[channelIndex] == indexFront[channelIndex]) 00548 { 00549 // filling data with and index that was already used 00550 if (repeatMissingValue) 00551 filledData[channelIndex][timeIndex] 00552 = data[channelIndex][indexFront[channelIndex]]; 00553 else 00554 filledData[channelIndex][timeIndex] = 0.0; 00555 } 00556 else 00557 { 00558 filledData[channelIndex][timeIndex] 00559 = data[channelIndex][indexFront[channelIndex]]; 00560 lastUsed[channelIndex] = indexFront[channelIndex]; 00561 } 00562 //System.out.print(" " + timeIndex + "," + channelIndex 00563 // + "," + referenceTime[timeIndex] + "," + time[channelIndex][indexFront[channelIndex]]); 00564 //if (referenceTime[timeIndex] >= time[channelIndex][indexFront[channelIndex]]) 00565 //System.out.println(" yes"); 00566 //else 00567 //System.out.println(" no"); 00568 if (referenceTime[timeIndex] >= time[channelIndex][indexFront[channelIndex]]) 00569 { 00570 if (indexFront[channelIndex] < (data[channelIndex].length - 1)) 00571 ++indexFront[channelIndex]; 00572 } 00573 } 00574 00575 // System.out.println("Time Index = " + timeIndex); 00576 // System.out.println("Filled data: "); 00577 // for (int i = 0; i < channelPathArray.length; i++) 00578 // { 00579 // System.out.print(" " + filledData[i][timeIndex]); 00580 // } 00581 // System.out.println(); 00582 // System.out.println("Last Used and Front are: "); 00583 // for (int i = 0; i < channelPathArray.length; i++) 00584 // { 00585 // System.out.println(" " + i + ": " + lastUsed[i] + "," + indexFront[i]); 00586 // } 00587 00588 } 00589 00590 try { 00591 writeDataToFile(channelPathArray,referenceTime,filledData); 00592 } catch (IOException e) { 00593 e.printStackTrace(); 00594 } 00595 00596 if ((videoChannelPath != null) && (!videoChannelPath.equals(""))) 00597 { 00598 if (!probeVideo()) 00599 System.out.println("No matching video available "); 00600 else 00601 { 00602 String outputURL = "file:" + archiveDirectory 00603 + "/" + movieFileName; 00604 try { 00605 dataVideoSink.makeMovie(userGivenFrameRate, 00606 outputURL, videoChannelPath, itemsToSkip); 00607 } catch (Exception e1) { 00608 e1.printStackTrace(); 00609 } 00610 } 00611 } 00612 00613 } 00614 dataVideoSink.disconnect(); 00615 long endTime = System.currentTimeMillis(); 00616 long elaspedTime = endTime - startTime; 00617 System.out.println("Cycle took " + elaspedTime + " milliseconds."); 00618 } 00619 00620 private boolean probeVideo() 00621 { 00622 // TODO: fix test for vidoe data 00623 return true; 00624 } 00625 00626 private void writeDataToFile(String[] names, double[] times, double[][] data) throws IOException 00627 { 00628 String path = archiveDirectory + "/" + dataFileName; 00629 PrintWriter out = new PrintWriter(new FileWriter(path)); 00630 00631 // write header 00632 /* 00633 * Active channels: ATL1,ATT1,ATL3,ATT3 00634 * Sample rate: 10.000000 00635 * Channel units: g,g,in,kip (unknown at this time!) 00636 * Time ATL1 ATT1 ATL3 ATT3 00637 */ 00638 out.print("Active channels: "); 00639 out.print(names[0]); 00640 for (int i = 1; i < names.length; i++) 00641 { 00642 out.print("," + names[i]); 00643 } 00644 out.println(); 00645 00646 double rate = 0.0; 00647 for (int i = 1; i < times.length; i++) 00648 { 00649 rate += times[i]-times[i-1]; // in seconds 00650 } 00651 rate = rate/(double)(times.length - 1); 00652 out.println("Sample rate: " + rate); 00653 00654 // Channel units are unknown at this time! 00655 00656 out.print("Time"); 00657 for (int i = 0; i < names.length; i++) 00658 { 00659 out.print(" " + names[i]); 00660 } 00661 out.println(); 00662 00663 // write data 00664 00665 for (int i = 0; i < times.length; i++) 00666 { 00667 long unixTime = (long)(times[i] * 1000.0); // convert sec to millisec 00668 // SimpleDateFormat("yyyy-MM-dd:hh:mm:ss.SSS"); 00669 String time = OUTPUT_FORMAT.format(new Date(unixTime)); 00670 time = time.substring(0,10) + "T" + time.substring(11); 00671 out.print(time); 00672 for (int j = 0; j < data.length; j++) 00673 { 00674 out.print(" " + data[j][i]); 00675 } 00676 out.println(); 00677 out.flush(); 00678 } 00679 out.close(); 00680 } 00681 00682 /* (non-Javadoc) 00683 * @see org.nees.rbnb.RBNBBase#setParamterArrays() 00684 */ 00685 protected void setParamterArrays() { 00686 String [] pNameArray = super.getBaseParameterNameArray(); 00687 String [] pTypeArray = super.getBaseParameterTypeArray(); 00688 Object [] pDefaultArray = super.getBaseParameterDefaultArray(); 00689 00690 int base = pNameArray.length; 00691 int numberOfparameters = 13; 00692 parameterNameArray = new String[base + numberOfparameters]; 00693 parameterTypeArray = new String[base + numberOfparameters]; 00694 parameterDefaultArray = new Object[base + numberOfparameters]; 00695 00696 for (int i = 0; i < base; i++) 00697 { 00698 parameterNameArray[i] = pNameArray[i]; 00699 parameterTypeArray[i] = pTypeArray[i]; 00700 parameterDefaultArray[i] = pDefaultArray[i]; 00701 } 00702 00703 parameterNameArray[base + 0] = SINK_NAME_NAME; 00704 parameterTypeArray[base + 0] = RBNBBaseParameterHolder.STRING_TYPE; 00705 parameterDefaultArray[base + 0] = new String(SINK_NAME); 00706 00707 parameterNameArray[base + 1] = CHANNEL_PATTERN_NAME; 00708 parameterTypeArray[base + 1] = RBNBBaseParameterHolder.STRING_TYPE; 00709 parameterDefaultArray[base + 1] = new String(CHANNEL_PATTERN); 00710 00711 parameterNameArray[base + 2] = CHANNEL_LIST_NAME; 00712 parameterTypeArray[base + 2] = RBNBBaseParameterHolder.STRING_TYPE; 00713 parameterDefaultArray[base + 2] = new String(CHANNEL_LIST); 00714 00715 parameterNameArray[base + 3] = INCLUDE_HIDDEN_NAME; 00716 parameterTypeArray[base + 3] = RBNBBaseParameterHolder.BOOLEAN_TYPE; 00717 parameterDefaultArray[base + 3] = new Boolean(INCLUDE_HIDDEN); 00718 00719 parameterNameArray[base + 4] = ZERO_FOR_MISSING_NAME; 00720 parameterTypeArray[base + 4] = RBNBBaseParameterHolder.BOOLEAN_TYPE; 00721 parameterDefaultArray[base + 4] = new Boolean(ZERO_FOR_MISSING); 00722 00723 parameterNameArray[base + 5] = VIDEO_SOURCE_PATH_NAME; 00724 parameterTypeArray[base + 5] = RBNBBaseParameterHolder.STRING_TYPE; 00725 parameterDefaultArray[base + 5] = new String(VIDEO_SOURCE_PATH); 00726 00727 parameterNameArray[base + 6] = ARCHIVE_DIRECTORY_NAME; 00728 parameterTypeArray[base + 6] = RBNBBaseParameterHolder.STRING_TYPE; 00729 parameterDefaultArray[base + 6] = new String(ARCHIVE_DIRECTORY); 00730 00731 parameterNameArray[base + 7] = MOVIE_FILE_NAME_NAME; 00732 parameterTypeArray[base + 7] = RBNBBaseParameterHolder.STRING_TYPE; 00733 parameterDefaultArray[base + 7] = new String(MOVIE_FILE_NAME); 00734 00735 parameterNameArray[base + 8] = DATA_FILE_NAME_NAME; 00736 parameterTypeArray[base + 8] = RBNBBaseParameterHolder.STRING_TYPE; 00737 parameterDefaultArray[base + 8] = new String(DATA_FILE_NAME); 00738 00739 parameterNameArray[base + 9] = USER_GIVEN_FRAME_RATE_NAME; 00740 parameterTypeArray[base + 9] = RBNBBaseParameterHolder.FLOAT_TYPE; 00741 parameterDefaultArray[base + 9] = new Float(USER_GIVEN_FRAME_RATE); 00742 00743 parameterNameArray[base + 10] = ITEMS_TO_SKIP_NAME; 00744 parameterTypeArray[base + 10] = RBNBBaseParameterHolder.INTEGER_TYPE; 00745 parameterDefaultArray[base + 10] = new Integer(ITEMS_TO_SKIP); 00746 00747 parameterNameArray[base + 11] = WAIT_TIME_NAME; 00748 parameterTypeArray[base + 11] = RBNBBaseParameterHolder.LONG_TYPE; 00749 parameterDefaultArray[base + 11] = new Long(WAIT_TIME); 00750 00751 parameterNameArray[base + 12] = COLLECTION_TIME_NAME; 00752 parameterTypeArray[base + 12] = RBNBBaseParameterHolder.LONG_TYPE; 00753 parameterDefaultArray[base + 12] = new Long(COLLECTION_TIME); 00754 } 00755 00756 /* (non-Javadoc) 00757 * @see org.nees.rbnb.RBNBBase#setVariablesFromParameters() 00758 */ 00759 public void setVariablesFromParameters() { 00760 super.setBaseVarialbesFromParametes(); 00761 00762 sinkName = SINK_NAME; 00763 try{ 00764 Object obj = getValueWithDefault(SINK_NAME_NAME, SINK_NAME); 00765 sinkName = (String)obj; 00766 } catch (Throwable ignore){} 00767 00768 channelPathPattern = CHANNEL_PATTERN; 00769 try{ 00770 Object obj = getValueWithDefault(CHANNEL_PATTERN_NAME, CHANNEL_PATTERN); 00771 channelPathPattern = (String)obj; 00772 } catch (Throwable ignore){} 00773 00774 channelPathListString = CHANNEL_LIST; 00775 try{ 00776 Object obj = getValueWithDefault(CHANNEL_LIST_NAME, CHANNEL_LIST); 00777 channelPathListString = (String)obj; 00778 } catch (Throwable ignore){} 00779 00780 includeHidden = INCLUDE_HIDDEN; 00781 try{ 00782 Boolean b = new Boolean(INCLUDE_HIDDEN); 00783 Object obj = getValueWithDefault(INCLUDE_HIDDEN_NAME, b); 00784 includeHidden = ((Boolean)obj).booleanValue(); 00785 } catch (Throwable ignore){} 00786 00787 repeatMissingValue = !ZERO_FOR_MISSING; // negate! 00788 try{ 00789 Boolean b = new Boolean(ZERO_FOR_MISSING); 00790 Object obj = getValueWithDefault(ZERO_FOR_MISSING_NAME, b); 00791 repeatMissingValue = !((Boolean)obj).booleanValue(); 00792 } catch (Throwable ignore){} 00793 00794 videoChannelPath = VIDEO_SOURCE_PATH; 00795 try{ 00796 Object obj = getValueWithDefault(VIDEO_SOURCE_PATH_NAME, VIDEO_SOURCE_PATH); 00797 videoChannelPath = (String)obj; 00798 } catch (Throwable ignore){} 00799 00800 archiveDirectory = ARCHIVE_DIRECTORY; 00801 try{ 00802 Object obj = getValueWithDefault(ARCHIVE_DIRECTORY_NAME, ARCHIVE_DIRECTORY); 00803 archiveDirectory = (String)obj; 00804 } catch (Throwable ignore){} 00805 00806 movieFileName = MOVIE_FILE_NAME; 00807 try{ 00808 Object obj = getValueWithDefault(MOVIE_FILE_NAME_NAME, MOVIE_FILE_NAME); 00809 movieFileName = (String)obj; 00810 } catch (Throwable ignore){} 00811 00812 dataFileName = DATA_FILE_NAME; 00813 try{ 00814 Object obj = getValueWithDefault(DATA_FILE_NAME_NAME, DATA_FILE_NAME); 00815 dataFileName = (String)obj; 00816 } catch (Throwable ignore){} 00817 00818 userGivenFrameRate = USER_GIVEN_FRAME_RATE; 00819 try{ 00820 Float f = new Float(USER_GIVEN_FRAME_RATE); 00821 Object obj = getValueWithDefault(USER_GIVEN_FRAME_RATE_NAME, f); 00822 userGivenFrameRate = ((Float)obj).floatValue(); 00823 } catch (Throwable ignore){} 00824 00825 itemsToSkip = ITEMS_TO_SKIP; 00826 try{ 00827 Integer i = new Integer(ITEMS_TO_SKIP); 00828 Object obj = getValueWithDefault(ITEMS_TO_SKIP_NAME, i); 00829 itemsToSkip = ((Integer)obj).intValue(); 00830 } catch (Throwable ignore){} 00831 00832 waitTime = WAIT_TIME; // in seconds 00833 try{ 00834 Long l = new Long(WAIT_TIME); 00835 Object obj = getValueWithDefault(WAIT_TIME_NAME, l); 00836 waitTime = ((Long)obj).longValue(); 00837 } catch (Throwable ignore){} 00838 00839 collectionTime = COLLECTION_TIME; 00840 try{ 00841 Long l = new Long(COLLECTION_TIME); 00842 Object obj = getValueWithDefault(COLLECTION_TIME_NAME, l); 00843 collectionTime = ((Long)obj).longValue(); 00844 } catch (Throwable ignore){} 00845 00846 } 00847 00848 /* (non-Javadoc) 00849 * @see org.nees.rbnb.RBNBBase#getParameterNameArray() 00850 */ 00851 public String[] getParameterNameArray() { 00852 return parameterNameArray; 00853 } 00854 00855 /* (non-Javadoc) 00856 * @see org.nees.rbnb.RBNBBase#getParameterTypeArray() 00857 */ 00858 public String[] getParameterTypeArray() { 00859 return parameterTypeArray; 00860 } 00861 00862 /* (non-Javadoc) 00863 * @see org.nees.rbnb.RBNBBase#getParameterDefaultArray() 00864 */ 00865 public Object[] getParameterDefaultArray() { 00866 return parameterDefaultArray; 00867 } 00868 00869 /* (non-Javadoc) 00870 * @see org.nees.rbnb.RBNBBase#start() 00871 */ 00872 public boolean start() { 00873 if (isRunning()) return false; 00874 if (connected) disconnect(); 00875 setVariablesFromParameters(); 00876 setupChannelList(); 00877 testConnect(); 00878 if (!connected) return false; 00879 startThread(); 00880 return true; 00881 } 00882 00883 /* (non-Javadoc) 00884 * @see org.nees.rbnb.RBNBBase#stop() 00885 */ 00886 public boolean stop() { 00887 if (!isRunning()) return false; 00888 stopThread(); 00889 disconnect(); 00890 return true; 00891 } 00892 00893 }

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