From: jprocter Date: Tue, 6 Mar 2007 12:56:31 +0000 (+0000) Subject: added PickManager test code. Current state of library means this example app fails... X-Git-Tag: Release_0.2~172 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8a09da71c5939ec3198084eccea06f6e88e69a8b;p=vamsas.git added PickManager test code. Current state of library means this example app fails to shutdown after three instances have been started. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@348 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/uk/ac/vamsas/test/ExampleApplication.java b/src/uk/ac/vamsas/test/ExampleApplication.java index 684bdf3..328495b 100644 --- a/src/uk/ac/vamsas/test/ExampleApplication.java +++ b/src/uk/ac/vamsas/test/ExampleApplication.java @@ -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 } + }