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
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.");
}
}
}
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");
.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) {
// 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) {