-/**
- * Created on 14-Sep-2005
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
package uk.ac.vamsas.test;
import uk.ac.vamsas.client.*;
import java.util.Vector;
/**
- * Toy vamsas command line client application demonstrating the API. TODO: test
- * appData get/set methods TODO: verify and test pickManager and interaction
- * between it and other session events TODO: add more session interaction events
- * (currently: modifies document on start up, then modifies every 2 updates
- * before finalizing after 5 updates.
+ * 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.
+ *
+ * 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 1.6).
+ *
+ * TODO: test
+ * appData get/set methods
+ *
+ * TODO: verify and test pickManager and interaction
+ * between it and other session events
+ *
+ * TODO: add more session interaction events
+ *
+ * TODO: test client add/leave events - currently library generates exceptions for sessionlist and clientlist modifications.
*
* @author jimp
*/
public class ExampleApplication
{
- private static ClientHandle app;
+ private ClientHandle app;
- private static UserHandle user; // TODO: make this something defined by the
+ private UserHandle user; // TODO: make this something defined by the
// api
- private static IClientFactory clientfactory;
-
- private static IClient vorbaclient;
+ private IClientFactory clientfactory;
- private static byte[] mydata;
+ private IClient vorbaclient;
- private static Vector vamsasObjects;
+ private byte[] mydata;
- private static boolean isUpdated = false;
+ private Vector vamsasObjects;
- private static boolean isShuttingdown = false;
+ private boolean isUpdated = false;
- private static boolean isFinalizing = false;
+ private boolean isShuttingdown = false;
- private static void processVamsasDocument(IClientDocument doc)
+ private boolean isFinalizing = false;
+ private int totalUpdates = 9;
+ private void processVamsasDocument(IClientDocument doc)
{
+ if (doc.getVamsasRoots().length<4) {
doc.addVamsasRoot(Core.getDemoVamsas());
+ } else {
+ try {
+ uk.ac.vamsas.objects.core.DataSet ds = doc.getVamsasRoots()[1].getDataSet(0);
+ uk.ac.vamsas.objects.core.AlignmentSequence alsq = ds.getAlignment(0).getAlignmentSequence(0);
+ System.out.println("Modifying Sequence:\n"+alsq.hashCode());
+ alsq.setSequence(alsq.getSequence()+ds.getAlignment(0).getGapChar());
+ System.out.println("Modifying Sequence:\n"+alsq.hashCode());
+ System.out.println("Modified Sequence:\n"+alsq.getSequence());
+ doc.setVamsasRoots(doc.getVamsasRoots());
+ } catch (Exception ee) {
+
+ }
+ }
vorbaclient.updateDocument(doc);
// merge vamsasObjects with vamsas objects in document
// get this apps 'mydata' if it hasn't got it already.
// .. access this application's 'public' mydata' if there is any.
}
- private static void addHandlers(IClient avorbaclient)
+ private void addHandlers(IClient avorbaclient)
{
// make a non-volatile reference to the client instance.
final IClient vorbaclient = avorbaclient;
IClientDocument cdoc = vorbaclient.getClientDocument();
uk.ac.vamsas.test.simpleclient.ArchiveReports.rootReport(
cdoc.getVamsasRoots(), true, System.out);
+ // Simple update
+ try {
+ if (cdoc.getVamsasRoots().length>2) {
+ uk.ac.vamsas.objects.core.DataSet ds = cdoc.getVamsasRoots()[1].getDataSet(0);
+ uk.ac.vamsas.objects.core.AlignmentSequence alsq = ds.getAlignment(0).getAlignmentSequence(0);
+ if (alsq.isUpdated())
+ System.out.println("Seqeuence was updated since last time.");
+ alsq.setSequence(alsq.getSequence()+ds.getAlignment(0).getGapChar());
+ System.out.println("Newly Modified Sequence:\n"+alsq.getSequence());
+ cdoc.setVamsasRoots(cdoc.getVamsasRoots());
+ }
+ } catch (Exception ee) {
+ System.err.println("Exception whilst updating :");
+ ee.printStackTrace(System.err);
+ }
vorbaclient.updateDocument(cdoc);
}
catch (Exception e)
}
- public static String Usage = "ExampleApplication [session urn] watch/n( future usage is :/n <vamsasFileDirectory> <vamsasSessionURN> <action> [+<arguments>]\n"
+ public String Usage = "ExampleApplication [session urn] watch/n( future usage is :/n <vamsasFileDirectory> <vamsasSessionURN> <action> [+<arguments>]\n"
+ "<action> is one of :\n\tsave,update,close,watch";
- static String sess = null;
+ String sess = null;
- private static boolean parseArgs(String args[])
+ private boolean parseArgs(String args[])
{
if (args.length == 0)
{
return true;
}
- public static void main(String[] args)
+ class ExamplePicker extends Thread
{
- class ExamplePicker extends Thread
- {
- String me = null;
+ String me = null;
- public IPickManager pm = null;
+ public IPickManager pm = null;
- ExamplePicker(String me, IPickManager pm)
- {
- this.me = me;
- this.pm = pm;
- }
+ ExamplePicker(String me, IPickManager pm)
+ {
+ this.me = me;
+ this.pm = pm;
+ }
- public void run()
+ public void run()
+ {
+ int mcount = 1;
+ while (pm != null)
{
- int mcount = 1;
- while (pm != null)
- {
- try { Thread.sleep(1000 + (long) Math.random() * 10000); }
- catch (Exception e) {}
+ 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 (pm != null)
+ {
+ pm.sendMessage(new uk.ac.vamsas.client.picking.CustomMessage("Message " + mcount++ + " from " + me));
}
}
-
}
+ }
+
+ public void runMe(String[] args)
+ {
if (!parseArgs(args))
{
System.err.print(Usage);
});
}
- while (!isShuttingdown && update < 5)
+ while (!isShuttingdown && update < totalUpdates)
{
// do something with data
// , update document, or something.
// finish
System.out.println("Byee!");
}
-
+ public static void main(String[] args)
+ {
+ ExampleApplication example = new ExampleApplication();
+ example.runMe(args);
+ }
}