Overdue update. Numerous bugfixes

jjp32 [2002-09-23 15:48:16]
Overdue update.  Numerous bugfixes
Filename
ep/EPConfig.xml
ep/EPConfiguration.java
ep/event/EPEvent.java
ep/input/SienaInput.java
ep/input/SocketInput.java
ep/store/JDBCStore.java
ep/store/MemoryStore.java
ep/transform/StoreTransform.java
ep/util/EPTest.java
diff --git a/ep/EPConfig.xml b/ep/EPConfig.xml
index 5e8c236..e79c4e0 100644
--- a/ep/EPConfig.xml
+++ b/ep/EPConfig.xml
@@ -5,18 +5,56 @@

 <EventPackagerConfiguration>
   <Inputters>
-    <Inputter Name="ConsoleInput1" Type="psl.xues.ep.input.ConsoleInput"></Inputter>
+    <Inputter Name="ConsoleInput1" Type="psl.xues.ep.input.ConsoleInput" />
+    <Inputter Name="SienaInput1" Type="psl.xues.ep.input.SienaInput"
+	      SienaReceivePort="7890">
+      <SienaFilter />
+    </Inputter>
+    <Inputter Name="SocketInput1" Type="psl.xues.ep.input.SocketInput"
+	      Port="7891" SocketType="tcpstream" DataType="StringObject" />
   </Inputters>
+  <Transforms>
+    <Transform Name="StoreTransform1"
+	       Type="psl.xues.ep.transform.StoreTransform"
+	       StoreName="JDBCStore1" />
+  </Transforms>
   <Outputters>
-    <Outputter Name="ConsoleOutput1" Type="psl.xues.ep.output.ConsoleOutput"></Outputter>
+    <Outputter Name="ConsoleOutput1" Type="psl.xues.ep.output.ConsoleOutput" />
+    <Outputter Name="NullOutput1" Type="psl.xues.ep.output.NullOutput" />
   </Outputters>
+  <Stores>
+    <Store Name="JDBCStore1" Type="psl.xues.ep.store.JDBCStore"
+	   DBType="hsqldb" DBDriver="org.hsqldb.jdbcDriver" Username="sa" />
+  </Stores>
   <Rules>
     <Rule Name="ConsoleRule">
       <Inputs>
-	<Input Name="ConsoleInput1"></Input>
+	<Input Name="ConsoleInput1" />
       </Inputs>
       <Outputs>
-	<Output Name="ConsoleOutput1"></Output>
+	<Output Name="ConsoleOutput1" />
+      </Outputs>
+    </Rule>
+    <Rule Name="SienaRule">
+      <Inputs>
+	<Input Name="SienaInput1"/>
+      </Inputs>
+      <Transforms>
+	<Transform Name="StoreTransform1" />
+      </Transforms>
+      <Outputs>
+	<Output Name="NullOutput1" />
+      </Outputs>
+    </Rule>
+    <Rule Name="SocketRule">
+      <Inputs>
+	<Input Name="SocketInput1" />
+      </Inputs>
+      <Transforms>
+	<Transform Name="StoreTransform1" />
+      </Transforms>
+      <Outputs>
+	<Output Name="ConsoleOutput1" />
       </Outputs>
     </Rule>
   </Rules>
diff --git a/ep/EPConfiguration.java b/ep/EPConfiguration.java
index 7e3a590..8527760 100644
--- a/ep/EPConfiguration.java
+++ b/ep/EPConfiguration.java
@@ -24,6 +24,7 @@ import psl.xues.ep.transform.EPTransformInterface;
 import psl.xues.ep.store.EPStore;
 import psl.xues.ep.store.EPStoreInterface;
 import psl.xues.util.JAXPUtil;
+import psl.xues.util.XuesUtil;

 /**
  * Event packager configuration module.
@@ -208,7 +209,7 @@ public class EPConfiguration {
       Class.forName(eventFormatName);
     } catch(Exception e) {
       debug.warn("Failed in loading event format \"" + eventFormatName +
-      "\", ignoring", e);
+      "\", ignoring", XuesUtil.parseException(e));
       return null;
     }

@@ -276,7 +277,7 @@ public class EPConfiguration {
       { ep, data });
     } catch(Exception e) {
       debug.warn(pluginType + " \"" + pluginName +
-      "\" failed to load, ignoring", e);
+      "\" failed to load, ignoring", XuesUtil.parseException(e));
       return null;
     }

@@ -300,5 +301,4 @@ public class EPConfiguration {
   public boolean deletePlugin(short type, String name) {
     return false;
   }
-
 }
\ No newline at end of file
diff --git a/ep/event/EPEvent.java b/ep/event/EPEvent.java
index 2bfc00b..c80aee4 100644
--- a/ep/event/EPEvent.java
+++ b/ep/event/EPEvent.java
@@ -27,7 +27,7 @@ public abstract class EPEvent implements Comparable, Serializable {
   /** Timestamp of this event, in OUR perception */
   protected long timestamp = -1;
   /** Debugger */
-  protected Logger debug = null;
+  protected transient Logger debug = null;
   /**
    * Creator ("source", not "type").  NB: This creator must be the local
    * EP creator -- rules are fired by examining the source.
diff --git a/ep/input/SienaInput.java b/ep/input/SienaInput.java
index 99f994e..67aff58 100644
--- a/ep/input/SienaInput.java
+++ b/ep/input/SienaInput.java
@@ -21,6 +21,24 @@ import psl.xues.util.SienaUtils;
  * Siena 1.4.2.  (Note that Siena 1.4.0-1 is extremely buggy and will probably
  * not work well.)
  * <p>
+ * Usage: <em>([] implies an optional parameter)</em></p>
+ * <p><tt>
+ * &lt;Inputs&gt;<br>
+ * <blockquote>&lt;Inputter Name="<em>instance name</em>"
+ * Type="psl.xues.ep.input.SienaInput" [SienaHost="<em>senp url</em>"]
+ * [SienaReceivePort="<em>port number</em>"] [Control="true"]&gt;
+ * <blockquote>&lt;SienaFilter&gt;
+ * <blockquote>[&lt;SienaConstraint AttributeName="<em>attribute name</em>"
+ * Op="<em>matching operator</em>" ValueType="<em>value type</em>"
+ * Value="<em>attribute value</em>"&gt;]
+ * <br>...</blockquote>
+ * &lt;/SienaFilter&gt;
+ * <br>...</blockquote>
+ * &lt;/Inputter&gt;
+ * </blockquote>
+ * &lt;/Inputs&gt;
+ * </tt></p>
+ * <p>
  * Attributes/parameters: <ol>
  * <li><b>SienaHost</b>: Specifies the Siena master that this node will
  * connect to (in Siena URL format {which is version-dependent}).  If this field
diff --git a/ep/input/SocketInput.java b/ep/input/SocketInput.java
index 8d23184..0189cf9 100644
--- a/ep/input/SocketInput.java
+++ b/ep/input/SocketInput.java
@@ -31,6 +31,16 @@ import siena.Notification;
  * Socket event input mechanism.  Allows EP to be a server which receives
  * socket input.  We currently allocate one thread per socket.
  * <p>
+ * Usage: <em>([] implies an optional parameter)</em></p>
+ * <p><tt>
+ * &lt;Inputs&gt;<br>
+ * <blockquote>&lt;Inputter Name="<em>instance name</em>"
+ * Type="psl.xues.ep.input.SocketInput" Port="<em>port number</em>"
+ * [SocketType="<em>socket type</em>"] DataType="<em>datatype</em>" /&gt;<br>
+ * </blockquote>
+ * &lt;/Inputs&gt;
+ * </tt></p>
+ * <p>
  * Required attributes:<ol>
  * <li><b>Port</b>: specify the port to listen on for client connections</li>
  * <li><b>SocketType</b>: specify socket type (optional)</li>
@@ -60,9 +70,9 @@ import siena.Notification;
  *  <li>org.w3c.dom.Element: a DOMEvent is automatically created.</li>
  * </ol></li>
  * <li>String input (via type <b>StringObject</b>).  Note that String input
- * is newline-delimited for TCP streams.</li>
+ * is newline-delimited for tcpstream.</li>
  * <li>XML plaintext input (via type <b>XMLObject</b>).
- * Note that for TCP, only one XML document per connection is supported!  Gets
+ * Note that for TCP, only tcpwrap and tcpconn modes are supported.  Gets
  * parsed and inserted as a DOMEvent.</li>
  * </ol>
  * <p>
diff --git a/ep/store/JDBCStore.java b/ep/store/JDBCStore.java
index 3ca757f..b9bc8bc 100644
--- a/ep/store/JDBCStore.java
+++ b/ep/store/JDBCStore.java
@@ -22,11 +22,11 @@ import psl.xues.ep.util.Base64;
  * Usage: <em>([] implies an optional parameter)</em></p>
  * <p><tt>
  * &lt;Stores&gt;<br>
- * <blockquote>&lt;Store Name="<em>instance name</em>"
+ * <blockquote>&lt;Store Name="<em>instance name</em>"
  * Type="psl.xues.ep.store.JDBCStore" DBType="<em>database type</em>"
  * DBDriver="<em>database driver</em>" [DBName="<em>database name</em>"]
- * [TableName="<em>table name</em>"] Username="<em>username</em>"
- * Password="<em>password</em>" /&gt;<br></blockquote>
+ * [TableName="<em>table name</em>"] [Username="<em>username</em>"]
+ * [Password="<em>password</em>"] /&gt;<br></blockquote>
  * &lt;/Stores&gt;
  * </tt></p>
  * <p>
@@ -34,26 +34,22 @@ import psl.xues.ep.util.Base64;
  * <li><b>DBType</b>: The database type name (for JDBC).</li>
  * <li><b>DBDriver</b>: The database driver (full classname; for JDBC).</li>
  * <li><b>DBName</b>: The name of the database to use.  If none is specified,
- * "EventPackager" will be used.  If the database does not exist, it will
+ * "EventPackagerDB" will be used.  If the database does not exist, it will
  * automatically be created.</li>
  * <li><b>DBTable</b>: The name of the table to use.  If none is specified,
  * "EPData" will be used.  If the table does not exist, it will automatically
  * be created.</li>
  * <li><b>Username</b>: The username to use when connecting to the JDBC
- * driver.  (Required for now; anonymous connections may be supported in the
- * future.)</li>
+ * driver.  (If making an anonymous connection, leave this attribute out or
+ * specify an empty string.)</li>
  * <li><b>Password</b>: The password to use when connecting to the JDBC
- * driver. (For a passwordless connection, specify an empty string.)</li>
+ * driver. (For a passwordless connection, leave this attribute out or
+ * specify an empty string.)</li>
  * </ol>
  * <p>
  * Copyright (c) 2002: The Trustees of Columbia University in the
  * City of New York.  All Rights Reserved.
  *
- * <!--
- * TODO:
- * - Support anonymous and passwordless database connections
- * -->
- *
  * @author Janak J Parekh
  * @version $Revision$
  */
@@ -65,7 +61,7 @@ public class JDBCStore extends EPStore {
   /** Database driver for this type */
   private String dbDriver = null;
   /** Name of database */
-  private String dbName = "EventPackager";
+  private String dbName = "EventPackagerDB";
   /** Name of table */
   private String tableName = "EPData";
   /** Username */
@@ -92,33 +88,42 @@ public class JDBCStore extends EPStore {
     // Now attempt to determine necessary JDBC parameters
     dbType = el.getAttribute("DBType");
     dbDriver = el.getAttribute("DBDriver");
-    dbName = el.getAttribute("DBName");
-    tableName = el.getAttribute("DBTable");
+    // Optional parameters
     username = el.getAttribute("Username");
     password = el.getAttribute("Password");
-
-    if(dbType == null || dbDriver == null || dbName == null ||
-    tableName == null || username == null || password == null ||
-    dbType.length() == 0 || dbDriver.length() == 0 ||
-    dbName.length() == 0 || tableName.length() == 0 ||
-    username.length() == 0) {
-      debug.error("Can't initialize store: missing parameters");
-      throw new InstantiationException();
+    // Optional parametes with defaults
+    String tempdbName = el.getAttribute("DBName");
+    String temptableName = el.getAttribute("DBTable");
+    if(tempdbName.length() > 0)
+      dbName = tempdbName;
+    if(temptableName.length() > 0)
+      tableName = temptableName;
+
+    if(dbType.length() == 0 || dbDriver.length() == 0) {
+      throw new InstantiationException("Can't initialize store: missing or "+
+      "invalid parameters");
     }

     // Try to load the driver
     try {
       Class.forName(dbDriver);
     } catch(Exception e) {
-      debug.error("Can't initialize store", e);
-      throw new InstantiationException();
+      InstantiationException ie =
+      new InstantiationException("Can't initialize store");
+      ie.initCause(e); // Chain the underlying cause
+      throw ie;
     }

     // Attempt connection
     debug.debug("Connecting to jdbc:" + dbType + ":" + dbName + "...");
     try {
-      conn = DriverManager.getConnection("jdbc:" + dbType + ":" +
-      dbName, username, password);
+      if(username.length() > 0) {
+        conn = DriverManager.getConnection("jdbc:" + dbType + ":" +
+        dbName, username, password);
+      } else {
+        conn = DriverManager.getConnection("jdbc:" + dbType + ":" +
+        dbName);
+      }
     } catch(Exception e) {
       debug.error("Can't connect to database", e);
     }
@@ -135,7 +140,7 @@ public class JDBCStore extends EPStore {
         debug.debug("Table \"" + tableName + "\" doesn't exist, creating");
         Statement s = conn.createStatement();
         s.executeUpdate("CREATE TABLE " + tableName +
-        " (ID BIGINT PRIMARY KEY, SOURCE VARCHAR(100), TIMESTAMP TIMESTAMP, " +
+        " (ID BIGINT PRIMARY KEY, SOURCE VARCHAR(100), TIMESTAMP BIGINT, " +
         "FORMAT VARCHAR(100), EVENT VARCHAR(" + eventSize + "))");
         s.executeUpdate("CREATE INDEX source_index ON " + tableName +
         " (SOURCE)");
@@ -228,6 +233,7 @@ public class JDBCStore extends EPStore {
   public Object storeEvent(EPEvent e) {
     // First grab the event and try to base64 it.
     String encoding = Base64.encodeObject(e);
+    debug.debug("Base64 encoding complete, length is " + encoding.length());
     if(encoding == null) {
       debug.warn("Could not serialize event, skipping");
       return null;
@@ -250,6 +256,7 @@ public class JDBCStore extends EPStore {
     }

     // Done
+    debug.debug("Event stored, ID is " + lastID);
     return new Long(lastID);
   }

diff --git a/ep/store/MemoryStore.java b/ep/store/MemoryStore.java
index 5e31e39..bfce27b 100644
--- a/ep/store/MemoryStore.java
+++ b/ep/store/MemoryStore.java
@@ -9,6 +9,16 @@ import psl.xues.ep.event.EPEvent;
  * Simple implementation of an EP store to store events in memory.
  * Fast, and useful for testing.
  * <p>
+ * Usage: <em>([] implies an optional parameter)</em></p>
+ * <p><tt>
+ * &lt;Stores&gt;<br>
+ * <blockquote>&lt;Store Name="<em>instance name</em>"
+ * Type="psl.xues.ep.store.MemoryStore"/&gt;<br></blockquote>
+ * &lt;/Stores&gt;
+ * </tt></p>
+ * <p>
+ * Note that there are no configurable parameters for this store.
+ * <p>
  * Copyright (c) 2002: The Trustees of Columbia University in the
  * City of New York.  All Rights Reserved.
  *
diff --git a/ep/transform/StoreTransform.java b/ep/transform/StoreTransform.java
index b080c74..ade7e87 100644
--- a/ep/transform/StoreTransform.java
+++ b/ep/transform/StoreTransform.java
@@ -9,6 +9,15 @@ import org.w3c.dom.Element;
  * Transform that snapshots the current event and writes it to the
  * configured store.
  * <p>
+ * Usage: <em>([] implies an optional parameter)</em></p>
+ * <p><tt>
+ * &lt;Transforms&gt;<br>
+ * <blockquote>&lt;Transform Name="<em>instance name</em>"
+ * Type="psl.xues.ep.transform.StoreTransform"
+ * StoreName="<em>store instance name</em> /&gt;</blockquote>
+ * &lt;/Transforms&gt;
+ * </tt></p>
+ * <p>
  * Attributes/parameters: <ol>
  * <li><b>StoreName</b>: Specifies the store instance to capture events to.
  * </ol>
diff --git a/ep/util/EPTest.java b/ep/util/EPTest.java
index 6a20a2f..d729a38 100644
--- a/ep/util/EPTest.java
+++ b/ep/util/EPTest.java
@@ -1,6 +1,11 @@
 package psl.xues.ep.util;

+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import psl.xues.ep.EventPackager;
+import psl.xues.ep.util.Base64;
 import siena.HierarchicalDispatcher;
 import siena.Filter;
 import siena.Notifiable;
@@ -55,6 +60,24 @@ public class EPTest {
   }

   public static void main(String[] args) {
-    new EPTest(args[0], args[1]);
+    Notification n = new Notification();
+    byte[] ba = null;
+    n.putAttribute("foo", "bar");
+    try {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      ObjectOutputStream oos = new ObjectOutputStream(baos);
+      oos.writeObject(n);
+      oos.close();
+      ba = baos.toByteArray();
+      baos.close();
+      System.out.println("Length is " + ba.length + ", now reading back in");
+      ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+      ObjectInputStream ois = new ObjectInputStream(bais);
+      Notification n2 = (Notification)ois.readObject();
+      System.out.println("Notification read, it's \"" + n2 + "\"");
+    } catch(Exception e) { e.printStackTrace(); }
+      //    System.out.println(Base64.encodeObject(n));
+      //    System.out.println(Base64.encodeObject(n).length());
+      //new EPTest(args[0], args[1]);
   }
 }
\ No newline at end of file