From 43ba16c5dc20e182c8d48db1f32962bad747f999 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 23 Jan 2006 19:10:43 +0000 Subject: [PATCH] implementing minimal set : SimpleClientFactory createSession method -> SimpleClient -> SimpleDocument + events. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@166 be28352e-c001-0410-b1a7-c7978e42abec --- src/org/vamsas/client/IClient.java | 5 +- .../client/simpleclient/EventGeneratorThread.java | 127 +++++++++++++- src/org/vamsas/client/simpleclient/SessionUrn.java | 8 +- .../vamsas/client/simpleclient/SimpleClient.java | 176 ++++++++++++++++---- .../client/simpleclient/SimpleClientFactory.java | 37 +++- .../vamsas/client/simpleclient/SimpleDocument.java | 2 +- .../vamsas/client/simpleclient/VamsasSession.java | 89 ++++++++-- 7 files changed, 392 insertions(+), 52 deletions(-) diff --git a/src/org/vamsas/client/IClient.java b/src/org/vamsas/client/IClient.java index 5c538b1..a8d122e 100644 --- a/src/org/vamsas/client/IClient.java +++ b/src/org/vamsas/client/IClient.java @@ -5,6 +5,7 @@ package org.vamsas.client; import java.beans.PropertyChangeListener; +import java.io.IOException; /** * Defines the methods availabable to a vamsas @@ -71,8 +72,10 @@ public interface IClient { * get vamsas document with * user and app specific data * IClientDocuments are not thread-safe. + * TODO: New exception for failed document lock. + * @throws IOException if lock is not obtainable for the document in the session */ - public IClientDocument getClientDocument(); + public IClientDocument getClientDocument() throws IOException; /** * Queue new Vorba objects for storage and propagation * to other clients (via Event.DOCUMENT_UPDATE based diff --git a/src/org/vamsas/client/simpleclient/EventGeneratorThread.java b/src/org/vamsas/client/simpleclient/EventGeneratorThread.java index e60a674..a643ae1 100644 --- a/src/org/vamsas/client/simpleclient/EventGeneratorThread.java +++ b/src/org/vamsas/client/simpleclient/EventGeneratorThread.java @@ -16,9 +16,18 @@ public class EventGeneratorThread extends Thread implements Runnable { private SimpleClient client; private Hashtable handlers; // manager object private VamsasSession session; - + + /** + * list with all the clientHandles for the session + */ protected FileWatcher clientfile=null; + /** + * the session's vamsasDocument + */ protected FileWatcher vamsasfile=null; + /** + * written to by client when its app calls storeDocument. + */ protected FileWatcher storeFile=null; private boolean watch=false; @@ -70,17 +79,129 @@ public class EventGeneratorThread extends Thread implements Runnable { } if ((watchlock=clientfile.getChangedState())!=null) { // see what happened to the clientfile - compare our internal version with the one in the file, or just send the updated list out...? - raised++; + // + /** + * Generated when a new vamsas client is attached to a session (Handle is + * passed) Note: the newly created client does not receive the event. + * + public static final String CLIENT_CREATION = "org.vamsas.client.events.clientCreateEvent"; + */ // as the test + /** + * Generated when a vamsas client leaves a session (Handle is passed to all + * others). + public static final String CLIENT_FINALIZATION = "org.vamsas.client.events.clientFinalizationEvent"; + */ // again - as the test. + raised++; } if ((watchlock=vamsasfile.getChangedState())!=null) { - // pass IClientDocument instance to app handler ? + + /** + * Generated when a client has finished updating the document. Passes + * applicationHandle of client so the updating client can recognise its own + * updates. + public static final String DOCUMENT_UPDATE = "org.vamsas.client.events.documentUpdateEvent"; + */ + // read apphandle from 'lastUpdate' session file. + // pass apphandle name to appHandler ? + } + /** + * Generated when a new vamsas document is created (perhaps from some existing + * Vamsas data) so an application may do its own data space initialization. + * TODO: decide if this is called when an app is connected to a stored + * session... + public static final String DOCUMENT_CREATE = "org.vamsas.client.events.documentCreateEvent"; + */ + // check if this session's appInit flag is set - if not - generate event for this app. + // prolly don't need this at the moment - when an app does getDocument it can to the initing then. + + + /** + * Generated prior to session Shutdown, after the last participating vamsas + * client has finalized. + * TODO: decide on purpose of this ? is this for benefit of multi-session Apps only ? + public static final String SESSION_SHUTDOWN = "org.vamsas.client.events.SessionShutdownEvent"; + */ + + /** + * Generated for all clients when any client calls IClient.storeDocument() to + * allow them to store any updates before an offline copy of the session is + * created. Any client that handles this should call the + * IClient.getDocument(), update and then IClient.updateDocument in the same + * handler thread. + * EventName: + * NewValue: org.vamsas.client.IClient for session. + * + public static final String DOCUMENT_FINALIZEAPPDATA = "org.vamsas.client.events.DocumentFinalizeAppData"; +*/ + // watch for finalization semaphore (last finalised sessionFile). + + /** + * Generated by Vorba stub after the penultimate client makes a call to + * closeDocument(). Sequence is as follows : 1. All other vamsas clients have + * called closeDocument() 2. Final living client monitors closures, and + * realises that it is last. 3. Final client generates event to prompt + * associated application to inquire if the user wishes to save the document + * for future reference. + * * Any call to closeDocument in a thread other than the registered + * EventListener will block until the RequestToClose handler has exited. + * + */ + // public static final String DOCUMENT_REQUESTTOCLOSE = "org.vamas.client.DocumentRequestToCloseEvent"; + return raised; } private void initEvents() { } + /** + * Events raised by IClient and propagated to others in session + */ + + /** + * number of milliseconds between any file state check. + */ + long POLL_UNIT = 20; + protected void wait(int u) { + if (u<=0) + u=1; + long l = System.currentTimeMillis()+POLL_UNIT*u; + while (System.currentTimeMillis()