From c5ae09e2372eabd49d9d186ec1b0f150287aca86 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 31 Aug 2007 09:57:17 +0000 Subject: [PATCH] flags for reading/writing client or user appdata only. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@450 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/test/ExampleApplication.java | 136 ++++++++++++++----------- 1 file changed, 75 insertions(+), 61 deletions(-) diff --git a/src/uk/ac/vamsas/test/ExampleApplication.java b/src/uk/ac/vamsas/test/ExampleApplication.java index e7557df..df95ec8 100644 --- a/src/uk/ac/vamsas/test/ExampleApplication.java +++ b/src/uk/ac/vamsas/test/ExampleApplication.java @@ -22,21 +22,24 @@ import java.io.OutputStream; import java.util.Vector; /** - * Toy vamsas command line client application demonstrating the API. - * Currently runs with one argument: ExampleApplication.main(new String("watch")) - * Test: Start up at least two of these processes independently and they will + * Toy vamsas command line client application demonstrating the API. Currently + * runs with one argument: ExampleApplication.main(new String("watch")) Test: + * Start up at least two of these processes independently and they will * successively modify and handle update events from the document model. * - * Behaviour of each client: - * Event handlers are registered for documentUpdate. - * - every document update: - * * the vamsas document will be dumped to standard out using uk.ac.vamsas.test.simpleclient.ArchiveReports - * * if there are more than 4 vamsas roots, the first sequence in the first alignment of the first dataset of the second vamsas root will be appended with a single gap character and then written back to the session document. - * A pick thread is started, which sends random CUSTOM pick events every so often (tuning: flooding the pick channel seems to affect the behaviour of other vamsasClient threads, suggesting some object lock contention). - * A new vamsas root generated from uk.ac.vamsas.test.objects.Core.getDemoVamsas is added to the document. - * Then a while loop waits around for events until shutdown: - * - currently it will shutdown after 9 updates (totalUpdates) - * - an update will be made after every other update that is detected. + * Behaviour of each client: Event handlers are registered for documentUpdate. - + * every document update: * the vamsas document will be dumped to standard out + * using uk.ac.vamsas.test.simpleclient.ArchiveReports * if there are more than + * 4 vamsas roots, the first sequence in the first alignment of the first + * dataset of the second vamsas root will be appended with a single gap + * character and then written back to the session document. A pick thread is + * started, which sends random CUSTOM pick events every so often (tuning: + * flooding the pick channel seems to affect the behaviour of other vamsasClient + * threads, suggesting some object lock contention). A new vamsas root generated + * from uk.ac.vamsas.test.objects.Core.getDemoVamsas is added to the document. + * Then a while loop waits around for events until shutdown: - currently it will + * shutdown after 9 updates (totalUpdates) - an update will be made after every + * other update that is detected. * * Status: PickManager now shuts down correctly. Serial updates for two * instances work correctly and are detected under j1.4 (need to test in 1.5 and @@ -129,56 +132,65 @@ public class ExampleApplication { private int appdatareads = 0; + boolean clientappd = true; + + boolean userappd = false; + private void processAppData(IClientDocument doc) throws Exception { appdatareads++; boolean writtenonce = false; if (doc != null) { uk.ac.vamsas.client.IClientAppdata appd = doc.getClientAppdata(); - if (appd.hasClientAppdata() && !(appdatareads % 2 == 0)) { - // byte[] cappd = appd.getClientAppdata(); - // if (cappd!=null) - // System.out.println("Client appdata\n"+cappd.toString()+"\nEnd of - // Appdata\n"); - System.out.println("Testing read from inputstream"); - String cappds = readData(appd.getClientInputStream()); - System.out.println("Client appdata\n" + cappds + "\nEnd of Appdata\n"); - } else { - if (!writtenonce) { - String newapd = "Client Appdata:"; - if (appd.hasClientAppdata()) - { - AppDataInputStream is; - newapd = readData(is = appd.getClientInputStream()); - is.close(); + if (clientappd) { + if (appd.hasClientAppdata() && !(appdatareads % 2 == 0)) { + // byte[] cappd = appd.getClientAppdata(); + // if (cappd!=null) + // System.out.println("Client appdata\n"+cappd.toString()+"\nEnd of + // Appdata\n"); + System.out.println("Testing read from inputstream"); + String cappds = readData(appd.getClientInputStream()); + System.out + .println("Client appdata\n" + cappds + "\nEnd of Appdata\n"); + } else { + if (!writtenonce) { + String newapd = "Client Appdata:"; + if (appd.hasClientAppdata()) { + AppDataInputStream is; + newapd = readData(is = appd.getClientInputStream()); + is.close(); + } + writtenonce = true; + // appd.setClientAppdata(makeappData("Client Appdata for + // "+user.toString()+" written")); + writeData(appd.getClientOutputStream(), newapd + + " : Client Appdata for all users written on " + appdatareads + + " read by " + vorbaclient.getUserHandle()); + System.out.println("Written to ClientAppdata stream."); } - writtenonce = true; - // appd.setClientAppdata(makeappData("Client Appdata for - // "+user.toString()+" written")); - writeData(appd.getClientOutputStream(), - newapd+" : Client Appdata for all users written on " + appdatareads - + " read by " + vorbaclient.getUserHandle()); - System.out.println("Written to ClientAppdata stream."); } } - if (appd.hasUserAppdata() && !(appdatareads % 2 == 0)) { - byte[] cappd = appd.getUserAppdata(); - if (cappd != null) - System.out.println("User appdata\n" + new String(cappd) - + "\nEnd of Users' Appdata\n"); - else { - System.out.println("No user appdata."); - appd.setUserAppdata(("no default - overwritten null byte set on " - + appdatareads + " read by " + vorbaclient.getUserHandle() + "") - .getBytes()); + if (userappd) { + if (appd.hasUserAppdata() && !(appdatareads % 2 == 0)) { + byte[] cappd = appd.getUserAppdata(); + if (cappd != null) + System.out.println("User appdata\n" + new String(cappd) + + "\nEnd of Users' Appdata\n"); + else { + System.out.println("No user appdata."); + appd + .setUserAppdata(("no default - overwritten null byte set on " + + appdatareads + " read by " + vorbaclient.getUserHandle() + "") + .getBytes()); + } + } else if (!writtenonce) { + writtenonce = true; + byte[] bts = makeappData("User Appdata for " + user + " written on " + + appdatareads + " read at "); + System.out.println("Setting appData bytes to\n" + new String(bts) + + "\nEnd."); + appd.setUserAppdata(bts); + System.out.println("Written to UserAppdata stream."); } - } else if (!writtenonce) { - writtenonce = true; - byte[] bts = makeappData("User Appdata for " + user + " written on " - + appdatareads + " read at "); - System.out.println("Setting appData bytes to\n" + new String(bts) - + "\nEnd."); - appd.setUserAppdata(bts); - System.out.println("Written to UserAppdata stream."); } } } @@ -326,10 +338,9 @@ public class ExampleApplication { IClientAppdata apd = cdoc.getClientAppdata(); if (apd != null) { String userd = ""; - if (apd.getUserAppdata()!=null) - { - userd = new String(apd.getUserAppdata()); - } + if (apd.getUserAppdata() != null) { + userd = new String(apd.getUserAppdata()); + } String appdat = me.readData(apd.getClientInputStream()); me.writeData(apd.getClientOutputStream(), appdat + "\nUser Data merged\n" + userd + "\n"); @@ -540,6 +551,9 @@ public class ExampleApplication { .println("Error when updating document after an even numbered update."); e.printStackTrace(System.err); } + try { + Thread.sleep(200); + } catch (Exception e){} } } else { if (System.currentTimeMillis() > shutdown) { @@ -571,10 +585,10 @@ public class ExampleApplication { // and all registered listeners will be deregistered to avoid deadlock. // finish - vorbaclient=null; - clientfactory=null; + vorbaclient = null; + clientfactory = null; System.out.println("Byee!"); - //try { Thread.sleep(100000); } catch (Exception e) {} + // try { Thread.sleep(100000); } catch (Exception e) {} } public static void main(String[] args) { -- 1.7.10.2