[Webfunds-commits] java/webfunds/store AppendFileStore.java SepFileStore.java Store.java

Ian Grigg iang@cypherpunks.ai
Thu, 12 Apr 2001 00:55:51 -0400 (AST)


iang        01/04/12 00:55:51

  Modified:    webfunds/store AppendFileStore.java SepFileStore.java
                        Store.java
  Log:
  all now working with Log, cleaned up diags

Revision  Changes    Path
1.17      +46 -11    java/webfunds/store/AppendFileStore.java

Index: AppendFileStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/store/AppendFileStore.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- AppendFileStore.java	2001/02/20 21:44:23	1.16
+++ AppendFileStore.java	2001/04/12 04:55:50	1.17
@@ -1,5 +1,5 @@
 /*
- * $Id: AppendFileStore.java,v 1.16 2001/02/20 21:44:23 gelderen Exp $
+ * $Id: AppendFileStore.java,v 1.17 2001/04/12 04:55:50 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -25,8 +25,10 @@
 
 import webfunds.sox.*;   // for examples
 
+import webfunds.util.Hex;
+import webfunds.util.Log;
+
 import webfunds.utils.Diagnostics;
-import webfunds.utils.Hex;
 
 
 /**
@@ -69,13 +71,12 @@
     protected   Hashtable stores = new Hashtable();
 
     /** implements Diagnostics */
-    protected PrintWriter bug = null;
-    protected String      fix = "";
+    protected Log bug = null;
+    protected String      fix = TAB + "afS- ";
     public void logmsg(String s)  { if (bug != null) bug.println(fix + s); }
     public PrintWriter getDebug() { return bug ; }
-    // hmm, no autoflush.
-    public PrintWriter err()
-    { return (bug == null) ? new PrintWriter(System.err, true) : bug ; }
+    public Log getLog() { return bug ; }
+    public PrintWriter err() { return (bug == null) ? new Log() : bug ; }
 
 
 
@@ -89,11 +90,19 @@
      *  But, why would you want one?
      *  Opened up due to ClassLoader inheriting problems.
      */
+    public AppendFileStore(File dir, Log bug, String logfix)
+        throws StoreException
+    {
+        super();
+        init(dir, bug, logfix);
+    }
+
+    /** XXX: deprecated */
     public AppendFileStore(File dir, PrintWriter pw, String logfix)
         throws StoreException
     {
         super();
-        init(dir, pw, logfix);
+        init(dir, new Log(pw), logfix);
     }
 
     /**
@@ -108,6 +117,23 @@
     /**
      *  Has to be a non-existant file.
      */
+    public /* temp */ void init(File dir, Log bug, String logfix)
+        throws StoreException
+    {
+        this.dir  = dir;
+        if (!dir.exists())
+            dir.mkdirs();
+        if (!dir.isDirectory() || !dir.canRead())
+            throw new StoreException("Cannot read as directory: " + dir);
+
+        this.name = dir.getPath();
+        this.bug  = bug;
+        this.fix  = logfix;
+
+        initFiles();
+    }
+
+    /** XXX: deprecated */
     public /* temp */ void init(File dir, PrintWriter pw, String logfix)
         throws StoreException
     {
@@ -118,7 +144,7 @@
             throw new StoreException("Cannot read as directory: " + dir);
 
         this.name = dir.getPath();
-        this.bug  = pw;
+        this.bug  = new Log(pw);
         this.fix  = logfix;
 
         initFiles();
@@ -155,7 +181,7 @@
     public static Store getInstance(File dir)
     throws StoreException
     {
-        return getInstance(dir, null, "");
+        return getInstance(dir, null, TAB + "afS: ");
     }
         
 
@@ -164,12 +190,21 @@
      * read in as objects in the hashtable.
      * (Directories are ignored, see getStores()).
      */
+    public static AppendFileStore getInstance(File dir, Log bug, String logfix)
+        throws StoreException
+    {
+
+        AppendFileStore store = new AppendFileStore(dir, bug, logfix);
+        return store;
+    }
+
+    /** XXX: deprecated */
     public static AppendFileStore getInstance(File dir,
                                               PrintWriter pw, String logfix)
         throws StoreException
     {
 
-        AppendFileStore store = new AppendFileStore(dir, pw, logfix);
+        AppendFileStore store = new AppendFileStore(dir, new Log(pw), logfix);
         return store;
     }
 



1.45      +59 -23    java/webfunds/store/SepFileStore.java

Index: SepFileStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/store/SepFileStore.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- SepFileStore.java	2001/03/27 01:46:33	1.44
+++ SepFileStore.java	2001/04/12 04:55:50	1.45
@@ -1,5 +1,5 @@
 /*
- * $Id: SepFileStore.java,v 1.44 2001/03/27 01:46:33 iang Exp $
+ * $Id: SepFileStore.java,v 1.45 2001/04/12 04:55:50 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -10,8 +10,11 @@
 import java.util.*;
 import java.lang.reflect.InvocationTargetException;
 
+import webfunds.util.Log;
+import webfunds.util.Panic;
+import webfunds.util.Support;
+
 import webfunds.utils.Diagnostics;
-import webfunds.utils.Panic;
 import webfunds.sox.Encodable;
 import webfunds.sox.SOXPacketException;
 
@@ -38,12 +41,12 @@
     protected   Hashtable stores = new Hashtable();
 
     // implements Diagnostics
-    protected PrintWriter bug = null;
-    protected String      fix = "";
+    protected Log bug = null;
+    protected String      fix = TAB + "sfS- ";
     public void logmsg(String s)  { if (bug != null) bug.println(fix + s); }
     public PrintWriter getDebug() { return bug ; }
-    // hmm, no autoflush.
-    public PrintWriter err()      { return (bug == null) ? new PrintWriter(System.err, true) : bug ; }
+    public Log         getLog()   { return bug ; }
+    public PrintWriter err()      { return (bug == null) ? new Log() : bug ; }
 
     
 
@@ -76,8 +79,19 @@
     {
         super();
 
+        init(dir);
+        initDiags(new Log(pw), logfix);
+    }
+    
+    /**
+     * Open an empty, new SepFileStore with diags
+     */
+    public SepFileStore(File dir, Log bug, String logfix)
+    {
+        super();
+
         init(dir);
-        initDiags(pw, logfix);
+        initDiags(bug, logfix);
     }
     
 
@@ -87,7 +101,7 @@
     /**
      * Set up the directory
      */
-    public void init(File dir)
+    protected void init(File dir)
     {
         if (!dir.exists())
             dir.mkdirs();
@@ -101,9 +115,9 @@
     /**
      * Set up the diags
      */
-    public void initDiags(PrintWriter pw, String logfix)
+    protected void initDiags(Log bug, String logfix)
     {
-        this.bug  = new PrintWriter(pw, true);
+        this.bug  = bug;
         this.fix  = logfix;
     }
     
@@ -111,20 +125,37 @@
     // XXX: should use Store.getInstance(type, loc) or just (loc)
     public static Store getInstance(File dir)
     {
-        return getInstance(dir, new PrintWriter(System.err), "ignore: ");
+        return getInstance(dir, new Log(), TAB + "sfS: ");
     }
 
     /**
      * Returns an existing SepFileStore, with files in dir
      * read in as objects in the hashtable.
      * (Directories are ignored, see getStores()).
+     * XXX: Deprecated by below.
      */
     public static SepFileStore getInstance(File dir,
                                PrintWriter pw, String logfix)
     {
         SepFileStore store = new SepFileStore();
+        store.init(dir);
+        store.initDiags(new Log(pw), logfix);
+
+        store.initFiles();
+        return store ;
+    }
+    
+    /**
+     * Returns an existing SepFileStore, with files in dir
+     * read in as objects in the hashtable.
+     * (Directories are ignored, see getStores()).
+     */
+    public static SepFileStore getInstance(File dir,
+                               Log bug, String logfix)
+    {
+        SepFileStore store = new SepFileStore();
         store.init(dir);
-        store.initDiags(pw, logfix);
+        store.initDiags(bug, logfix);
 
         store.initFiles();
         return store ;
@@ -316,7 +347,7 @@
     {
         SepFileStore st; //  = getInstance(d, bug, fix);
         st = new SepFileStore();
-logmsg(name + ": setting (OLD) class loader " + getClassLoader());
+logmsg(name + ": Old.CL == " + getClassLoader());
         st.setClassLoader(getClassLoader());
 
         // this needs cleaning up...
@@ -347,11 +378,11 @@
             return st;
         }
 
-logmsg("asked to open " + name + " flags == " + flags);
+logmsg("open " + name + " flags == " + flags);
         if (flags == 0)
                 return getOldStore(name) ;
 
-logmsg("testing if flags == APPEND: " + flags);
+logmsg("test flags == APPEND: " + flags);
         if (flags != APPEND)
             throw new StoreException("flag unknown: " + flags + " ("+name+")");
             
@@ -365,7 +396,7 @@
         AppendFileStore st;
         // st = AppendFileStore.getInstance(new File(dir, name), bug, fix);
         st = new AppendFileStore();
-logmsg("(APPEND) has class loader " + st.getClassLoader());
+logmsg("(APPEND) has CL " + st.getClassLoader());
         st.setClassLoader(getClassLoader());
 
         // this needs cleaning up...
@@ -386,14 +417,14 @@
         if (cl == null)
             throw new IllegalArgumentException("cl==null");
 
-logmsg("asked to open " + name + " CL == " + cl);
+logmsg("open " + name + " CL == " + cl);
         Object obj = stores.get(name);
         SepFileStore st;
         if (obj != null)
         {
             st = (SepFileStore)obj;
             ClassLoader cl2 = st.getClassLoader();
-logmsg("store already open: " + st.getClass() + " with " + st.getClassLoader());
+logmsg("already open: " + st.getClass() + " with " + st.getClassLoader());
             if (!cl.equals(cl2))
                 throw new StoreException(name + " already open without " +
                                          cl + " but with " + cl2);
@@ -502,7 +533,7 @@
     /**
      * Return a (file) object located in the hashtable.
      */
-    public synchronized Object get(Object key)
+public synchronized Object get(Object key)
     {
         Object value = super.get(key);
         String name = key.toString();
@@ -528,10 +559,10 @@
         Object value2 = get(key);
         if (value2 instanceof byte[] && value instanceof byte[])
         {
-            if (new String((byte[])value).equals(new String((byte[])value2)))
-            {
+            if (Support.equals((byte[])value2, (byte[])value))
                 return value;
-            }
+
+            //if (new String((byte[])value).equals(new String((byte[])value2)))
         }
         if (value.equals(value2))      // get(key)))
         {
@@ -551,12 +582,17 @@
     public synchronized Object remove(Object key)
     {
         String name = key.toString();
+//logmsg("XXX- removing " + name);
         Object obj = super.remove(name);
+//if (get(key) != null)
+//throw new Panic("key " + key + " still in Store! " + get(key));
+
         File file = new File(dir, name);
         if (!file.exists() && obj == null)  // already done
             return null ;
         setChanged(true);
         file.delete();
+//logmsg("XXX- deleted " + file);
         return obj;
     }
     
@@ -638,7 +674,7 @@
         args = null;
         SepFileStore fhs;
         File dir = new File(".", ".sfstest");
-        PrintWriter bug = new PrintWriter(System.err, true);
+        Log bug = new Log();
         fhs = SepFileStore.getInstance(dir, bug, "XX ");
 
         Store test1 = fhs.getStore("Test1");



1.25      +3 -1      java/webfunds/store/Store.java

Index: Store.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/store/Store.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Store.java	2001/03/27 01:43:37	1.24
+++ Store.java	2001/04/12 04:55:50	1.25
@@ -1,4 +1,4 @@
-/* $Id: Store.java,v 1.24 2001/03/27 01:43:37 iang Exp $
+/* $Id: Store.java,v 1.25 2001/04/12 04:55:50 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -29,6 +29,8 @@
     protected boolean changed;
 
     protected String  name;
+
+    public final static String  TAB = "          "; // for diags
 
     protected Hashtable hash;