Better packaging this time

jjp32 [2002-05-01 21:07:54]
Better packaging this time
Filename
siena/utils/siena14/AllSubscriber.java
siena/utils/siena14/TestPublisher.java
diff --git a/siena/utils/siena14/AllSubscriber.java b/siena/utils/siena14/AllSubscriber.java
new file mode 100644
index 0000000..9e68f8a
--- /dev/null
+++ b/siena/utils/siena14/AllSubscriber.java
@@ -0,0 +1,72 @@
+
+package psl.events.siena.utils.siena14;
+
+import siena.*;
+import siena.comm.*;
+
+/**
+ * Universal subscription-and-printout service, useful for debugging.
+ * Note that even though the class is not a Runnable, it doesn't
+ * really matter since Siena will do all the thread work for us.
+ *
+ * TODO: Convert to a standardized logger
+ *
+ * @author Janak J Parekh
+ * @version 1.0
+ */
+public class AllSubscriber implements Notifiable {
+  private HierarchicalDispatcher hd = null;
+
+  public static void main(String[] args) {
+    if(args.length != 1) {
+      System.err.println("usage: java AllSubscriber <SENP URL>");
+      System.exit(-1);
+    }
+    new AllSubscriber(args[0]);
+  }
+
+  public AllSubscriber(String sienaHost) {
+    hd = new HierarchicalDispatcher();
+    try {
+      hd.setReceiver(new TCPPacketReceiver(0));
+      hd.setMaster(sienaHost);
+    } catch(Exception e) {
+      e.printStackTrace();
+    }
+
+    // Now super-subscribe
+    Filter f = new Filter();
+
+    try {
+      hd.subscribe(f, this);
+    } catch(Exception e) {
+      e.printStackTrace();
+    }
+
+    // Cleanup
+    Runtime.getRuntime().addShutdownHook(new Thread() {
+	public void run() {
+	  System.err.println("Shutting down..");
+	  hd.shutdown();
+	  return;
+	}
+      });
+
+    System.out.println("Ready.");
+  }
+
+  /**
+   * Get the hierarchicalDispatcher instance we use.
+   *
+   * @return The Hierarchical Dispatcher we're listening to.
+   */
+  public HierarchicalDispatcher getSiena() {
+    return hd;
+  }
+
+  public void notify(Notification n) {
+    System.out.println("Received event:" + n);
+  }
+
+  public void notify(Notification[] s) { ; }
+}
diff --git a/siena/utils/siena14/TestPublisher.java b/siena/utils/siena14/TestPublisher.java
new file mode 100644
index 0000000..308b886
--- /dev/null
+++ b/siena/utils/siena14/TestPublisher.java
@@ -0,0 +1,50 @@
+
+package psl.events.siena.utils.siena14;
+
+import siena.*;
+import siena.comm.*;
+
+/**
+ * Simple test publisher, useful for testing a Siena.
+ *
+ * @author Janak J Parekh
+ * @version 1.0
+ */
+public class TestPublisher {
+  private HierarchicalDispatcher hd = null;
+
+  public static void main(String[] args) {
+    new TestPublisher(args);
+  }
+
+  public TestPublisher(String[] args) {
+    if(args.length==0) {
+      System.err.println("usage: java TestPublisher <SENP URL>");
+      System.exit(-1);
+    }
+    hd = new HierarchicalDispatcher();
+    try {
+      hd.setReceiver(new TCPPacketReceiver(0));
+      hd.setMaster(args[0]);
+    } catch(Exception e) {
+      e.printStackTrace();
+    }
+
+    System.out.println("publishing...");
+
+    // Now publish
+    Notification n = new Notification();
+    n.putAttribute("foo","bar");
+
+    try {
+      hd.publish(n);
+    } catch(Exception e) { e.printStackTrace(); }
+
+    System.out.println("shutting down...");
+
+    // If we don't sleep, Siena throws an exception... blargh
+    try { Thread.sleep(2000); } catch(Exception e) { ; }
+
+    hd.shutdown();
+  }
+}