various changes towards working demo

png3 [2001-03-14 08:17:13]
various changes towards working demo
Filename
Metaparser.java
ParserThread.java
SienaListenerThread.java
diff --git a/Metaparser.java b/Metaparser.java
index b3862b7..61860c1 100644
--- a/Metaparser.java
+++ b/Metaparser.java
@@ -1,112 +1,115 @@
-package psl.metaparser;
-
-import java.util.*;
-import java.io.*;
-import java.net.*;
-
-import siena.SienaException;
-
-/** Root Metaparser class.
- *  Creates a SienaListenerThread, and establishes a few
- *  thread intercommunication data structures.
- *  If SienaListener gets a query from the Event Distiller,
- *  it starts a new SEParserThread.  The SEParserThread
- *  directs the data input of a subordinate Validator.
- *  This initial Validator validates against the smartevent
- *  schema.  When it encounters an unknown tag, the schema and
- *  processor for the unknown tag are requested from the Oracle,
- *  and the thread  goes to sleep.  When the response comes in, the
- *  Validator wakes up and validates the unknown portion.  When
- *  finished, it checks to see if the worklet has arrived and
- *  installed the tag processor.  If not, it goes to sleep again,
- *  and waits for the arrival.  When it comes, it applies the tag
- *  processor based on type: XSLT templates are applied, and
- *  XMLFilters are hooked up to an XMLReader.
- *
- *  Maybe.
- *
- *  TODO: properties instead of hardcoding
- *  TODO: caching of oracle responses.
- *  TODO: reacting to unknown tag, instead of faking it based on
- *  FleXML PI.  Requires actual streaming validation.
- *
+package psl.metaparser;
+
+import java.util.*;
+import java.io.*;
+import java.net.*;
+
+import siena.SienaException;
+
+/** Root Metaparser class.
+ *  Creates a SienaListenerThread, and establishes a few
+ *  thread intercommunication data structures.
+ *  If SienaListener gets a query from the Event Distiller,
+ *  it starts a new SEParserThread.  The SEParserThread
+ *  directs the data input of a subordinate Validator.
+ *  This initial Validator validates against the smartevent
+ *  schema.  When it encounters an unknown tag, the schema and
+ *  processor for the unknown tag are requested from the Oracle,
+ *  and the thread  goes to sleep.  When the response comes in, the
+ *  Validator wakes up and validates the unknown portion.  When
+ *  finished, it checks to see if the worklet has arrived and
+ *  installed the tag processor.  If not, it goes to sleep again,
+ *  and waits for the arrival.  When it comes, it applies the tag
+ *  processor based on type: XSLT templates are applied, and
+ *  XMLFilters are hooked up to an XMLReader.
+ *
+ *  Maybe.
+ *
+ *  TODO: properties instead of hardcoding
+ *  TODO: caching of oracle responses.
+ *  TODO: reacting to unknown tag, instead of faking it based on
+ *  FleXML PI.  Requires actual streaming validation.
+ *
  *  $Log$
- *  Revision 2.4  2001-02-05 06:35:16  png3
+ *  Revision 2.5  2001-03-14 08:17:13  png3
+ *  various changes towards working demo
+ *
+ *  Revision 2.4  2001/02/05 06:35:16  png3
  *  Post California version
- *
- *  Revision 2.3  2001/01/29 04:04:48  png3
- *  Added package psl.metaparser statements.  Can you say "Oops?"
- *
- *  Revision 2.2  2001/01/28 17:52:17  png3
- *  New version of Metaparser: fully multithreaded.  PrintWriter logs.
- *
- *
- */
-
-public class Metaparser {
-
-  /** when Parsers need to wait for a response, they register
-    * themselves here (key=requestid, value=the object they're
-    * wait()ing on, and wait for a notify().
-    * Synchronized HashMap;
-    */
-  static Map waitList = null;
-  SienaListenerThread slt = null;
-  private static final String fn = "Metaparser";
-  // should allow this from command line also...
-  private static final String prop = "metaparser.properties";
-  static boolean debug = false;
-  private static String seSchema = null;
-  static PrintWriter log = null;
-  static PrintWriter dbg = null;
-
-  public static void main(String args[]) {
-    System.out.println("Metaparser starting up");
-
-    Properties p = new Properties();
-    try {
-      FileInputStream fis = new FileInputStream(prop);
-      p.load(fis);
-    } catch (IOException ioe) {
-      System.out.println(fn + ": Warning: can't open properties file " +
-      	prop + ". Using defaults.");
-      System.out.println(ioe);
-    }
-
-    String sienaURL = p.getProperty("sienaURL",
-    	"senp://canal.psl.cs.columbia.edu:4321");
-    debug = Boolean.valueOf(p.getProperty("debug","false")).booleanValue();
-    String logFile = p.getProperty("logFile", "Metaparser.log");
-    String dbgFile = null;
-    if (debug) {
-      dbgFile = p.getProperty("dbgFile", "Metaparser.dbg");
-    }
-    seSchema = p.getProperty("seSchema", "SmartEventSchema.xsd");
-
-    try {
-      log = new PrintWriter(new FileWriter(logFile), true);
-      log.println("Log started " + MPUtil.timestamp());
-      if (debug) {
-	dbg = new PrintWriter(new FileWriter(dbgFile), true);
-	dbg.println("Debug Log started " + MPUtil.timestamp());
-      }
-    } catch (IOException ioe) {
-      System.err.println(fn + ": Can't open log/debug file:");
-      System.err.println(ioe);
-      // abort
-      return;
-    }
-
-    Metaparser mp = new Metaparser();
-    waitList = Collections.synchronizedMap(new HashMap());
-    // TODO: SienaListeners don't have to be threads...
-    mp.slt = new SienaListenerThread(sienaURL, log, dbg);
-    Thread t = new Thread(mp.slt);
-    if (debug) dbg.println(fn + ": starting slt");  // debug
-    t.start();
-  }
-
-  synchronized public static String getSESchema() {
-    return seSchema;
-  }
-}
+ *
+ *  Revision 2.3  2001/01/29 04:04:48  png3
+ *  Added package psl.metaparser statements.  Can you say "Oops?"
+ *
+ *  Revision 2.2  2001/01/28 17:52:17  png3
+ *  New version of Metaparser: fully multithreaded.  PrintWriter logs.
+ *
+ *
+ */
+
+public class Metaparser {
+
+  /** when Parsers need to wait for a response, they register
+    * themselves here (key=requestid, value=the object they're
+    * wait()ing on, and wait for a notify().
+    * Synchronized HashMap;
+    */
+  static Map waitList = null;
+  SienaListenerThread slt = null;
+  private static final String fn = "Metaparser";
+  // should allow this from command line also...
+  private static final String prop = "metaparser.properties";
+  static boolean debug = false;
+  private static String seSchema = null;
+  static PrintWriter log = null;
+  static PrintWriter dbg = null;
+
+  public static void main(String args[]) {
+    System.out.println("Metaparser starting up");
+
+    Properties p = new Properties();
+    try {
+      FileInputStream fis = new FileInputStream(prop);
+      p.load(fis);
+    } catch (IOException ioe) {
+      System.out.println(fn + ": Warning: can't open properties file " +
+      	prop + ". Using defaults.");
+      System.out.println(ioe);
+    }
+
+    String sienaURL = p.getProperty("sienaURL",
+    	"senp://canal.psl.cs.columbia.edu:4321");
+    debug = Boolean.valueOf(p.getProperty("debug","false")).booleanValue();
+    String logFile = p.getProperty("logFile", "Metaparser.log");
+    String dbgFile = null;
+    if (debug) {
+      dbgFile = p.getProperty("dbgFile", "Metaparser.dbg");
+    }
+    seSchema = p.getProperty("seSchema", "SmartEventSchema.xsd");
+
+    try {
+      log = new PrintWriter(new FileWriter(logFile), true);
+      log.println("Log started " + MPUtil.timestamp());
+      if (debug) {
+	dbg = new PrintWriter(new FileWriter(dbgFile), true);
+	dbg.println("Debug Log started " + MPUtil.timestamp());
+      }
+    } catch (IOException ioe) {
+      System.err.println(fn + ": Can't open log/debug file:");
+      System.err.println(ioe);
+      // abort
+      return;
+    }
+
+    Metaparser mp = new Metaparser();
+    waitList = Collections.synchronizedMap(new HashMap());
+    // TODO: SienaListeners don't have to be threads...
+    mp.slt = new SienaListenerThread(sienaURL, log, dbg);
+    Thread t = new Thread(mp.slt);
+    if (debug) dbg.println(fn + ": starting slt");  // debug
+    t.start();
+  }
+
+  synchronized public static String getSESchema() {
+    return seSchema;
+  }
+}
diff --git a/ParserThread.java b/ParserThread.java
index 283578e..9af597f 100644
--- a/ParserThread.java
+++ b/ParserThread.java
@@ -23,7 +23,10 @@ import psl.tagprocessor.TagProcessor;
   * Spawns Validators/SubParsers to validate subcomponents.
   *
   * $Log$
-  * Revision 2.6  2001-03-12 08:07:39  png3
+  * Revision 2.7  2001-03-14 08:17:13  png3
+  * various changes towards working demo
+  *
+  * Revision 2.6  2001/03/12 08:07:39  png3
   * now links with worklets.*
   *
   * Revision 2.5  2001/02/05 06:35:16  png3
@@ -275,12 +278,13 @@ class ParserThread extends DefaultHandler
       wvm = new WVM(this, slt.hostname, requestID);

       Notification n = new Notification();
-      n.putAttribute("hostname", slt.hostname);
-      n.putAttribute("source", source);
-      n.putAttribute("SrcID", slt.SRC_ID);
+      n.putAttribute("Hostname", slt.hostname);
+      n.putAttribute("Source", source);
+      n.putAttribute("SourceID", slt.SRC_ID);
       n.putAttribute("RequestID", requestID);
-      n.putAttribute("type", "query");
-      n.putAttribute("query", MPUtil.makeQuery(qName));
+      // changed to MPQuery for Oracle compatibility
+      n.putAttribute("Type", "MPQuery");
+      n.putAttribute("MPQuery", MPUtil.makeQuery(qName));
       prDbg(fn+"sending request to Oracle:" + n);
       try {
       /*
diff --git a/SienaListenerThread.java b/SienaListenerThread.java
index 395a9be..2ddc919 100644
--- a/SienaListenerThread.java
+++ b/SienaListenerThread.java
@@ -1,198 +1,201 @@
-package psl.metaparser;
-
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import siena.*;
-
-/** Listener for incoming Siena events.
-  * Spawns ParserThreads.
-  *
+package psl.metaparser;
+
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import siena.*;
+
+/** Listener for incoming Siena events.
+  * Spawns ParserThreads.
+  *
   * $Log$
-  * Revision 2.4  2001-02-05 06:35:16  png3
+  * Revision 2.5  2001-03-14 08:17:13  png3
+  * various changes towards working demo
+  *
+  * Revision 2.4  2001/02/05 06:35:16  png3
   * Post California version
-  *
-  * Revision 2.3  2001/01/30 10:16:55  png3
-  * Almost working...
-  *
-  * Revision 2.2  2001/01/29 04:04:48  png3
-  * Added package psl.metaparser statements.  Can you say "Oops?"
-  *
-  * Revision 2.1  2001/01/28 17:52:17  png3
-  * New version of Metaparser: fully multithreaded.  PrintWriter logs.
-  *
-  */
-class SienaListenerThread implements Runnable {
-
-  private Siena s = null;
-  private String sienaURL = null;
-  private PrintWriter log = null;
-  private PrintWriter dbg = null;
-  boolean debug = false;
-
-  String hostname = null;
-  private final String source = "psl.metaparser.SienaListenerThread";
-
-
-
-  private static final int RECV_PORT = 31337;
-  //TODO: get from sequencer somewhere
-  static final int SRC_ID = 1;
-
-  static int instance_counter = 0;
-
-  SienaListenerThread (String sienaURL, PrintWriter log, PrintWriter dbg) {
-    this.sienaURL = sienaURL;
-    this.log = log;
-    this.dbg = dbg;
-    debug = (dbg == null);
-
-    try {
-      hostname = InetAddress.getLocalHost().getHostName();
-    } catch (UnknownHostException uhe) {
-      log.println("slt_ctor: can't get local host name:" + uhe);
-      return;
-    }
-  }
-
-  // TODO: not thread safe, but we're going to un-Thread this anyway...
-  void prLog(String m) {log.println(m);}
-  void prDbg(String m) {if (debug) dbg.println(m);}
-
-  synchronized static int get_inst_nr() {
-    return instance_counter++;
-  }
-
-  public void run() {
-
-    final String fn = "slt_run";
-
-    final HierarchicalDispatcher hd = new HierarchicalDispatcher();
-    try {
-      // debug
-      if (dbg != null) dbg.println(fn + " setting recv port to " +
-      	RECV_PORT + ", and sienaURL to " + sienaURL);
-      hd.setReceiver(new TCPPacketReceiver(RECV_PORT));
-      hd.setMaster(sienaURL);
-    } catch (InvalidSenderException ise) {
-      log.println(fn + ": Invalid Sender:" + ise);
-      return;
-    } catch (IOException ioe) {
-      log.println(fn + ": Unable to set hd receiver:" + ioe);
-      return;
-    }
-
-    // we have our Siena
-    synchronized (this) {
-      s = hd;
-    }
-
-    System.out.println("Subscribed to siena " + sienaURL);
-
-    Runtime.getRuntime().addShutdownHook(new Thread() {
-      public void run() {
-	System.err.println("SLT shutting down");
-	hd.shutdown();
-      } });
-
-    // create filters
-    // #1, stuff coming from ED
-    Filter f1 = new Filter();
-    f1.addConstraint("Source", "EventDistiller");
-    f1.addConstraint("Type", "DataToMetaparser");
-    // debug
-    if (dbg != null) dbg.println("adding ED filter " + f1);
-    try {
-      synchronized (this) {
-	s.subscribe(f1,
-	  new Notifiable() {
-	    public void notify(Notification n) {handleEDNotification(n);}
-	    public void notify(Notification[] s) {}
-	  }
-	);
-      }
-    } catch (SienaException se) {
-      log.println(fn + ": SienaException adding filter 1:");
-      log.println(se);
-      return;
-    }
-
-    // #2: from Oracle
-    Filter f2 = new Filter();
-    f2.addConstraint("source", "psl.oracle.impl.OracleSienaInterface");
-    f2.addConstraint("type", "queryResult");
-    // TODO: when Oracle sends it, subscribe to it...
-    f2.addConstraint("MPHostname", hostname);
-    f2.addConstraint("MPSrcID", SRC_ID);
-    // debug
-    if (dbg != null) dbg.println(fn + " adding Oracle filter " + f2);
-    try {
-      synchronized (this) {
-	s.subscribe(f2,
-	  new Notifiable() {
-	    public void notify(Notification n) {handleOracleNotification(n);}
-	    public void notify(Notification[] s) {}
-	  }
-	);
-      }
-    } catch (SienaException se) {
-      log.println(fn + ": SienaException adding filter 2:");
-      log.println(se);
-      return;
-    }
-  }
-
-  public void handleEDNotification(Notification n) {
-    final String fn="handleEDNotification: ";
-    if (dbg != null) {  // debug
-      dbg.println("hEN(): got ED notification:" + n);
-    }
-    AttributeValue se = n.getAttribute("SmartEvent");
-    prLog(fn+"Received event from EventDistiller.  Starting ParserThread " +
-    	MPUtil.timestamp());
-    ParserThread pt = new ParserThread(se.stringValue(),
-    	get_inst_nr(), this, (dbg != null));
-    Thread t = new Thread(pt);
-    t.start();
-  }
-
-  public void handleOracleNotification(Notification n) {
-    String reqID = null;
-    String oracleResp = null;
-    final String fn="hON: ";
-
-    prDbg(fn+"got Oracle notification" + n);
-
-
-    // TODO: check for not found
-    AttributeValue se = n.getAttribute("MPRequestID");
-    reqID = se.stringValue();
-    se = n.getAttribute("value");
-    oracleResp = se.stringValue();
-
-    Object o = Metaparser.waitList.get(reqID);
-    // replace hash entry with oracle xml
-    prDbg(fn+"Hash replace: key="+reqID+"; val="+oracleResp);
-    Metaparser.waitList.put(reqID, oracleResp);
-    prDbg(fn+"notifying...");
-    synchronized(o) {
-      // wakey, wakey
-      o.notify();
-    }
-  }
-
-  // synchronized wrapper
-  synchronized public void publish(Notification n) {
-    final String fn = "SLT_publish: ";
-    if (dbg != null) { dbg.println("publishing " + n); } // debug
-    try {
-      s.publish(n);
-    } catch (SienaException se) {
-      log.println(fn+"SienaException while publishing " + n);
-      log.println(se);
-      return;
-    }
-  }
-
-}
+  *
+  * Revision 2.3  2001/01/30 10:16:55  png3
+  * Almost working...
+  *
+  * Revision 2.2  2001/01/29 04:04:48  png3
+  * Added package psl.metaparser statements.  Can you say "Oops?"
+  *
+  * Revision 2.1  2001/01/28 17:52:17  png3
+  * New version of Metaparser: fully multithreaded.  PrintWriter logs.
+  *
+  */
+class SienaListenerThread implements Runnable {
+
+  private Siena s = null;
+  private String sienaURL = null;
+  private PrintWriter log = null;
+  private PrintWriter dbg = null;
+  boolean debug = false;
+
+  String hostname = null;
+  private final String source = "psl.metaparser.SienaListenerThread";
+
+
+
+  private static final int RECV_PORT = 31337;
+  //TODO: get from sequencer somewhere
+  static final int SRC_ID = 1;
+
+  static int instance_counter = 0;
+
+  SienaListenerThread (String sienaURL, PrintWriter log, PrintWriter dbg) {
+    this.sienaURL = sienaURL;
+    this.log = log;
+    this.dbg = dbg;
+    debug = (dbg == null);
+
+    try {
+      hostname = InetAddress.getLocalHost().getHostName();
+    } catch (UnknownHostException uhe) {
+      log.println("slt_ctor: can't get local host name:" + uhe);
+      return;
+    }
+  }
+
+  // TODO: not thread safe, but we're going to un-Thread this anyway...
+  void prLog(String m) {log.println(m);}
+  void prDbg(String m) {if (debug) dbg.println(m);}
+
+  synchronized static int get_inst_nr() {
+    return instance_counter++;
+  }
+
+  public void run() {
+
+    final String fn = "slt_run";
+
+    final HierarchicalDispatcher hd = new HierarchicalDispatcher();
+    try {
+      // debug
+      if (dbg != null) dbg.println(fn + " setting recv port to " +
+      	RECV_PORT + ", and sienaURL to " + sienaURL);
+      hd.setReceiver(new TCPPacketReceiver(RECV_PORT));
+      hd.setMaster(sienaURL);
+    } catch (InvalidSenderException ise) {
+      log.println(fn + ": Invalid Sender:" + ise);
+      return;
+    } catch (IOException ioe) {
+      log.println(fn + ": Unable to set hd receiver:" + ioe);
+      return;
+    }
+
+    // we have our Siena
+    synchronized (this) {
+      s = hd;
+    }
+
+    System.out.println("Subscribed to siena " + sienaURL);
+
+    Runtime.getRuntime().addShutdownHook(new Thread() {
+      public void run() {
+	System.err.println("SLT shutting down");
+	hd.shutdown();
+      } });
+
+    // create filters
+    // #1, stuff coming from ED
+    Filter f1 = new Filter();
+    f1.addConstraint("Source", "EventDistiller");
+    f1.addConstraint("Type", "DataToMetaparser");
+    // debug
+    if (dbg != null) dbg.println("adding ED filter " + f1);
+    try {
+      synchronized (this) {
+	s.subscribe(f1,
+	  new Notifiable() {
+	    public void notify(Notification n) {handleEDNotification(n);}
+	    public void notify(Notification[] s) {}
+	  }
+	);
+      }
+    } catch (SienaException se) {
+      log.println(fn + ": SienaException adding filter 1:");
+      log.println(se);
+      return;
+    }
+
+    // #2: from Oracle
+    Filter f2 = new Filter();
+    f2.addConstraint("Source", "psl.oracle.OracleSienaInterface");
+    f2.addConstraint("Type", "OracleQueryResult");
+    // TODO: when Oracle sends it, subscribe to it...
+    f2.addConstraint("MPHostname", hostname);
+    f2.addConstraint("MPSourceID", SRC_ID);
+    // debug
+    if (dbg != null) dbg.println(fn + " adding Oracle filter " + f2);
+    try {
+      synchronized (this) {
+	s.subscribe(f2,
+	  new Notifiable() {
+	    public void notify(Notification n) {handleOracleNotification(n);}
+	    public void notify(Notification[] s) {}
+	  }
+	);
+      }
+    } catch (SienaException se) {
+      log.println(fn + ": SienaException adding filter 2:");
+      log.println(se);
+      return;
+    }
+  }
+
+  public void handleEDNotification(Notification n) {
+    final String fn="handleEDNotification: ";
+    if (dbg != null) {  // debug
+      dbg.println("hEN(): got ED notification:" + n);
+    }
+    AttributeValue se = n.getAttribute("SmartEvent");
+    prLog(fn+"Received event from EventDistiller.  Starting ParserThread " +
+    	MPUtil.timestamp());
+    ParserThread pt = new ParserThread(se.stringValue(),
+    	get_inst_nr(), this, (dbg != null));
+    Thread t = new Thread(pt);
+    t.start();
+  }
+
+  public void handleOracleNotification(Notification n) {
+    String reqID = null;
+    String oracleResp = null;
+    final String fn="hON: ";
+
+    prDbg(fn+"got Oracle notification" + n);
+
+
+    // TODO: check for not found
+    AttributeValue se = n.getAttribute("MPRequestID");
+    reqID = se.stringValue();
+    se = n.getAttribute("Value");
+    oracleResp = se.stringValue();
+
+    Object o = Metaparser.waitList.get(reqID);
+    // replace hash entry with oracle xml
+    prDbg(fn+"Hash replace: key="+reqID+"; val="+oracleResp);
+    Metaparser.waitList.put(reqID, oracleResp);
+    prDbg(fn+"notifying...");
+    synchronized(o) {
+      // wakey, wakey
+      o.notify();
+    }
+  }
+
+  // synchronized wrapper
+  synchronized public void publish(Notification n) {
+    final String fn = "SLT_publish: ";
+    if (dbg != null) { dbg.println("publishing " + n); } // debug
+    try {
+      s.publish(n);
+    } catch (SienaException se) {
+      log.println(fn+"SienaException while publishing " + n);
+      log.println(se);
+      return;
+    }
+  }
+
+}