more locked IO performance tests.
[vamsas.git] / src / org / vamsas / client / simpleclient / VamsasFile.java
index 506fea6..dbff158 100644 (file)
@@ -23,52 +23,7 @@ import org.vamsas.objects.core.LockFileDescriptor;
  * @author jimp
  *
  */
-public class VamsasFile {
-  /**
-   * Vamsas client is intialised with a path to create live session directories. 
-   * This path may contain a vamsas.properties file 
-   * that sets additional parameters (otherwise client 
-   * just uses the one on the classpath).
-   * 
-   * A vamsas session consists of :
-   *  SessionDir - translates to urn of a live session.
-   *  Contains: Vamsas Document (as a jar), Session client list file, 
-   *  both of which may be locked, and additional 
-   *  temporary versions of these files when write 
-   *  operations are taking place.
-   * 
-   * Zip file entries
-   *  - vamsasdocument.xml : core info
-   *  one or more:
-   *  - <applicationname>.version.sessionnumber.raw (string given in vamsasdocument.xml applicationData entry)
-   *  
-   * Lockfile
-   *  - filename given in the vamsasdocument.xml. Should be checked for validity by any client and rewritten if necessary. 
-   *    The lockfile can point to the jar itself.
-   * Mode of operation.
-   * Initially - documentHandler either:
-   *  - creates a zip for a new session for the client
-   *  - connect to an existing session zip 
-   *   1. reads session urn file
-   *   2. waits for lock
-   *   3. examines session - decide whether to create new application data slice or connect to one stored in session.
-   *   4. writes info into session file
-   *   5. releases lock and generates local client events.
-   *   6. Creates Watcher thread to generate events.
-   * 
-   * During the session
-   *  - Update watcher checks for file change - 
-   * 
-   */
-  private File vamsasJar;
-  private Lock newVamsasJarLock;
-  private File newVamsasJar; // file which client application is writing to.
-  private File lockfile;
-  private Lock lock;
-  private File newSessionDir; // where new sessions (or copies of existing sessions) can be safely created
-  private long timeout=1000; // time in milliseconds before we give up getting a lock
-  private long interval=100; // time between attempts to lock
-  private PrintWriter vamsasWriterStream; // non null if there is a write to a new Document in progress. 
+public class VamsasFile extends SessionFile {
   /**
    * 
    * Connect to an existing Vamsas document in a given sessionDir
@@ -77,34 +32,51 @@ public class VamsasFile {
    * @param sessionDir
    * @throws java.io.IOException
    */
-  public VamsasFile(File sessionDir) throws java.io.IOException {
-      // check if directory exists. if not, create it.
-    // check if vamsas jar exists, if not, create it.
-    
+  public VamsasFile(File sessionFile) throws java.io.IOException {
+    super(sessionFile);
   }
   /**
    * Expand a previously stored session into the sessionDir
    * @param sessionDir
    * @param storedSession
-   */
-  public VamsasFile(File sessionDir, JarFile storedSession) throws IOException {
+   
+   public VamsasFile(File sessionDir, JarFile storedSession) throws IOException {
     // check if sessionDir is live or not
+    if (!sessionDir.exists()) {
+      sessionDir.mkdir();
+    }
+    
+    {
+      // check its actually a writable directory
+    }
     
+    File sfile = new File(sessionDir, "vamsas.jar");
+    VamsasFile(sfile);
     // if live - try to merge storedSession with sessionDir
     //  - will probably fail through duplicate object references needing to be dereferenced.
     // TODO: think of a way of specifying vorba_id scope for an application's references to allow merging of one vamsasDocument with another.
     
   }
+  */
+  
   /**
    * gets a locked Reader for the vamsas document.
    * @return reader for vamsasdocument.xml enrty
    */
+  public Lock getLock() {
+    while (!lockFile())
+      ;
+    return fileLock;
+  }
+  public void unLock() {
+    this.unlockFile();
+  }
   public java.io.Reader getDocumentReader() {
     
     try {
-      JarFile session = new JarFile(vamsasJar);
-      JarEntry vamsasDocument = session.getJarEntry("vamsasDocument.xml");
-      return new InputStreamReader(session.getInputStream(vamsasDocument));
+      JarFile session = new JarFile("vamsasJar");
+      //JarEntry vamsasDocument = session.getJarEntry("vamsasDocument.xml");
+      //return new InputStreamReader(session.getInputStream(vamsasDocument));
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();