added PickManager test code. Current state of library means this example app fails...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 6 Mar 2007 12:56:31 +0000 (12:56 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 6 Mar 2007 12:56:31 +0000 (12:56 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@348 be28352e-c001-0410-b1a7-c7978e42abec

src/uk/ac/vamsas/test/ExampleApplication.java

index 684bdf3..328495b 100644 (file)
@@ -7,6 +7,9 @@
 package uk.ac.vamsas.test;
 
 import uk.ac.vamsas.client.*;
+import uk.ac.vamsas.client.picking.IMessageHandler;
+import uk.ac.vamsas.client.picking.IPickManager;
+import uk.ac.vamsas.client.picking.Message;
 import uk.ac.vamsas.objects.core.VAMSAS;
 import uk.ac.vamsas.test.objects.Core;
 
@@ -120,6 +123,26 @@ public class ExampleApplication {
     return true;
   }
   public static void main(String[] args) {
+    class ExamplePicker implements Runnable {
+      String me=null;
+      public IPickManager pm = null;
+      ExamplePicker(String me,IPickManager pm) {
+        this.me = me;
+        this.pm = pm;
+      }
+      public void run() {
+        int mcount=1;
+        while (pm!=null) {
+          try { Thread.sleep(1000+(long) Math.random()*10000); }
+          catch (Exception e){ };
+          if (pm!=null)
+          {
+            pm.sendMessage(new uk.ac.vamsas.client.picking.CustomMessage("Message "+mcount+++" from "+me));
+          }
+        }
+      }
+        
+    };
 
     if (!parseArgs(args)) {
       System.err.print(Usage);
@@ -164,7 +187,16 @@ public class ExampleApplication {
       System.exit(1);
     }
     int update=0;
-    // Main application event loop - wait around and do stuff...
+    ExamplePicker picker = new ExamplePicker(vorbaclient.getClientHandle().getClientUrn(),vorbaclient.getPickManager());
+    Thread pickthread = new Thread(picker);
+    pickthread.start();
+    picker.pm.registerMessageHandler(new IMessageHandler() {
+
+      public void handleMessage(Message message) {
+        System.out.println("Received |"+message.getRawMessage()+"|");
+      }
+      
+    });
     while (!isShuttingdown && update<5) {
       // do something with data
       // , update document, or something.
@@ -186,6 +218,14 @@ public class ExampleApplication {
       }
       try { Thread.sleep(15); } catch (Exception e) {};
     }
+    System.out.println("Shutting down picker.");
+    picker.pm=null;
+    while (pickthread.isAlive()) {
+      System.out.println("Waiting for picker to die...");
+      try { Thread.sleep(1000); 
+      } catch (Exception e) {};
+    }
+  
     System.out.println("Finalizing.");
       // call finalizeClient
     vorbaclient.finalizeClient();
@@ -194,4 +234,5 @@ public class ExampleApplication {
     
     // finish
   }
+  
 }