[Webfunds-commits] java/webfunds/sox/value ValueManager.java WebFundsData.java

Ian Grigg iang@cypherpunks.ai
Fri, 6 Apr 2001 18:52:15 -0400 (AST)


iang        01/04/06 18:52:15

  Modified:    webfunds/sox/value ValueManager.java WebFundsData.java
  Log:
  updated for new SSD package

Revision  Changes    Path
1.4       +29 -27    java/webfunds/sox/value/ValueManager.java

Index: ValueManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/value/ValueManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ValueManager.java	2001/03/27 01:48:36	1.3
+++ ValueManager.java	2001/04/06 22:52:14	1.4
@@ -1,4 +1,4 @@
-/* $Id: ValueManager.java,v 1.3 2001/03/27 01:48:36 iang Exp $
+/* $Id: ValueManager.java,v 1.4 2001/04/06 22:52:14 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -30,7 +30,7 @@
 import webfunds.sox.AccountId;
 import webfunds.sox.ArmouredPayment;
 import webfunds.sox.Crypto;
-import webfunds.sox.IssuerFinder;
+import webfunds.sox.ServerFinder;
 import webfunds.sox.ItemId;
 import webfunds.sox.MailId;
 import webfunds.sox.MailItem;
@@ -60,7 +60,7 @@
  *
  *  (Was the SOXWallet -- attempt to separate and make simple!)
  *
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
 public class ValueManager
     extends Debug
@@ -72,10 +72,10 @@
     protected   Store                   store;
 
     protected   StoreAccountStore       accountStore;
-    protected   SOXServerStore          soxes;
+    // protected   SOXServerStore          soxes;
     protected   StateReceiptStore       receiptStore;
     protected   Properties              properties;
-    protected   IssuerFinder            finder;
+    protected   ServerFinder            finder;
 
     protected static final String name = "SOX Value Manager";
     protected String shortname         = "SOX-VM";
@@ -109,7 +109,7 @@
      * Construction is complicated by class loader, hence separate init.
      */
     public void init(SecureRandom sr, Store store,
-                     IssuerFinder finder, Properties properties)
+                     ServerFinder finder, Properties properties)
         throws StoreException
     {
         if (Crypto.sr == null)
@@ -124,16 +124,6 @@
 
 
     /**
-     * Shortname is used for the stores.  Can be set by child.
-    public void   setShortName(String name) { shortname = name; }
-    public String getShortName()            { return shortname; }
-    public String getProtocol()             { return name; }
-    public String getVersion()              { return "2.2"; }
-     */
-
-
-
-    /**
      *  Set the Store.
      *  This is the only access we have to persistant storage.
      *  Unfortunately, it's quite limiting.
@@ -188,6 +178,8 @@
         throws StoreException
     {
         Account ac = accountStore.getAccount(id);
+        // System.err.println("setting finder: " + finder);
+        // System.err.println("setting finder: " + finder.getClass());
         ac.setFinder(finder);
         return ac;
     }
@@ -247,7 +239,7 @@
     /**
      *  Get a list of accounts managed by this wallet.
      *
-     *  @return an array of all AccountIds, maybe empty but never null
+     *  @return an array of all AccountIds, may be empty but never null
      */
     public AccountId[] getAccountIds()
     {
@@ -322,7 +314,7 @@
     protected SubAccount getKnownSubAccount(AccountId accountid, ItemId item)
         throws AccountException
     {
-        logmsg("AccountId update");
+        logmsg("getKnownSubAccount");
         Account account = getKnownAccount(accountid);
 
         SubAccount sub = account.getSub(item);
@@ -952,7 +944,7 @@
      *
      */
     public void cancel(AccountId accountid, ItemId item, String pid)
-        throws CancelException, SOXLaterException, AccountException
+        throws CancelException, AccountException
     {
 
         ValueAccount val = getKnownValueAccount(accountid, item);
@@ -985,13 +977,14 @@
      *
      */
     protected void internalCancel(ValueAccount sub, String[] pids)
-        throws CancelException, SOXLaterException
+        throws CancelException
     {
         AccountId acct = getAccountId(sub);
         ItemId item = sub.getItemId();
         logmsg("internalCancel("+acct+"/"+item+", pid["+pids.length+"])");
         Vector updates = new Vector();
-        SOXLaterException soxlater = null;
+        boolean later = false;
+        int errno = CancelException.UNKNOWN;
         StoreException storex = null;
         int failures = 0;
         String errors = "";
@@ -1005,6 +998,7 @@
             } catch (StoreException ex) {
                 storex = ex ;
                 errors += "\nStoreEx: " + ex;
+                errno = CancelException.INTERNAL;
                 break ;
             }
 
@@ -1015,12 +1009,14 @@
             try {
                 mails = quietCancel(sub, pid);
             } catch (SOXLaterException ex) {
-                soxlater = ex ;
+                later = true;
                 errors += "\nLater: " + ex;
+                errno = ex.getNumber();
                 break ;
             } catch (CancelException ex) {
                 failures++;
                 errors += "\npid "+pid+" failed to cancel (skipping): "+ex;
+                errno = ex.getNumber();
                 continue ;
             }
 
@@ -1031,6 +1027,7 @@
             } catch (SOXPacketException ex) {
                 failures++;
                 errors += "\npid "+pid+"could not recover receipt: " + ex ;
+                errno = ex.getNumber();
                 continue ;
             }
 
@@ -1069,9 +1066,9 @@
         if (storex != null)
             throw new CancelException(CancelException.INTERNAL, errors);
         if (failures > 0)
-            throw new CancelException(errors) ;
-        if (soxlater != null)
-            throw soxlater ;
+            throw new CancelException(errno, errors) ;
+        if (later)
+            throw new CancelException(errno, errors) ;
 
         return ;
     }
@@ -1083,7 +1080,7 @@
      *  @return an error string if errors detected, else empty (never null)
      */
     protected void internalCancel(ValueAccount sub, String pid)
-        throws CancelException, SOXLaterException
+        throws CancelException
     {
 
         AccountId acct = getAccountId(sub);
@@ -1102,7 +1099,12 @@
         if ((sr != null) && sr.isCancelled())
             throw new CancelException(CancelException.ALREADY);
 
-        MailItem[] mails = quietCancel(sub, pid);
+        MailItem[] mails;
+        try {
+            mails = quietCancel(sub, pid);
+        } catch (SOXLaterException ex) {
+            throw new CancelException(ex.getNumber(), ex.getMessage());
+        }
         
         //
         //  Should this be here?  Perhaps the low level wallet
@@ -1528,7 +1530,7 @@
 
 
     /**
-     * Do an update - one single cycle of request with sigs.
+     *  Handle these mails.  Store them or process them as necessary.
      */
     protected MailId[] tryHandle(SubAccount sub, MailItem[] mails)
     {
@@ -1546,7 +1548,7 @@
             {
                 MailId id = mail.getMailId();  // confirm this number
                 newConfirms.addElement(id);  // confirm
-                logmsg("uccessfully saved " + id);
+                logmsg("successfully saved " + id);
             }
         }
 



1.2       +60 -17    java/webfunds/sox/value/WebFundsData.java

Index: WebFundsData.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/value/WebFundsData.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebFundsData.java	2001/03/27 01:48:36	1.1
+++ WebFundsData.java	2001/04/06 22:52:15	1.2
@@ -1,25 +1,28 @@
-/* $Id: WebFundsData.java,v 1.1 2001/03/27 01:48:36 iang Exp $
+/* $Id: WebFundsData.java,v 1.2 2001/04/06 22:52:15 iang Exp $
  *
- * Copyright (c) Systemics Inc. 1995-2000 on behalf of
+ * Copyright (c) 1995-2001 Systemics Inc. on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
  */
 package webfunds.sox.value;
 
 
-// JDK
 import java.io.File;
+import java.io.PrintWriter;
 
 import java.security.SecureRandom;
 
 import webfunds.sox.IssuerFinder;
+import webfunds.sox.ServerFinder;
 
+import webfunds.comms.CommsManager;
+
 import webfunds.ricardian.Contract;
 import webfunds.ricardian.ContractStore;
 import webfunds.ricardian.DirContractStore;
 import webfunds.ricardian.ContractDirectoryException;
 
 import webfunds.ricardian.SOXStore;
-import webfunds.ricardian.DirSOXStore;
+// import webfunds.ricardian.DirSOXStore;
 import webfunds.ricardian.SOXServerException;
 
 import webfunds.store.Store;
@@ -34,24 +37,29 @@
  *  Static data that identifies where files are, in
  *  the WebFunds v2 existance.
  *
- *  @version $Revision: 1.1 $
+ *  @version $Revision: 1.2 $
  */
 public class WebFundsData
 {
-    private final String userDirName;
-    private       File soxDir, userDir;
-    private       Store soxWalletStore;
+    private final String        userDirName;
+    private       File          soxDir, userDir;
+    private       Store         soxWalletStore;
     private       ContractStore contracts;
+    private       CommsManager  comms;
+    private       PrintWriter   bug;
 
-    public WebFundsData(String userDirName)
+    public WebFundsData(String userDirName, PrintWriter bug)
     {
         this.userDirName = userDirName;
-        this.userDir    = new File(userDirName);
-        File dataDir    = new File(userDir, "data2");
-        File walletDir  = new File(dataDir, "WalletManager");
-        this.soxDir     = new File(walletDir, "SOX");
+        this.bug         = bug;
 
+        this.userDir     = new File(userDirName);
+        File dataDir     = new File(userDir, "data2");
+        File walletDir   = new File(dataDir, "WalletManager");
+        this.soxDir      = new File(walletDir, "SOX");
 
+        contracts        = null;
+        soxWalletStore   = null;
     }
 
     /**
@@ -65,23 +73,51 @@
         if (soxWalletStore == null)
         {
             soxWalletStore  = SepFileStore.getInstance(soxDir);
+            if (soxWalletStore == null)
+                throw new RuntimeException("new returned null");
         }
         return soxWalletStore;
     }
 
+
+
+    /**
+     *  Set up the CommsManager, the only way that we can access the net.
+     *  (Access is via SSDStore, which returns Servers, which do requests.)
+     *
+     *  Call this before calling getServerFinder().
+     */
+    public void setCommsManager(CommsManager cm)    { comms = cm; }
+
+
+
+    /**
+     *  Set up an alternate ContractStore.
+     *  Call this before calling getContractStore() or getServerFinder().
+     */
+    public void setContractStore(ContractStore cs)    { contracts = cs; }
+
+    /**
+     *  @return the valid ContractStore, never null
+     */
     public ContractStore getContractStore()
         throws ContractDirectoryException
     {
         if (contracts == null)
         {
-            File contractDir        = new File(userDir, "contract");
-            ContractStore contracts = new DirContractStore(contractDir);
+            File contractDir = new File(userDir, "contract");
+            contracts = new DirContractStore(contractDir, bug);
+            if (contracts == null)
+                throw new ContractDirectoryException("new returned null");
         }
         return contracts;
     }
 
 
-    public IssuerFinder getIssuerFinder()
+    /**
+     *  @return the valid IssuerFinder, never null
+     */
+    public ServerFinder getServerFinder()
         throws StoreException, ContractDirectoryException
     {
         Store soxWallet = getSOXWalletStore();
@@ -89,9 +125,16 @@
         //  The SOX server file Store.
         //
         Store soxstore = soxWallet.getStore("SOXServers", SepFileStore.APPEND);
-        SOXServerStore soxes = new SOXServerStore(soxstore);
-        soxes.setContractStore(getContractStore());
-        return (IssuerFinder)soxes;
+        if (soxstore == null)
+            throw new StoreException("getStore() returned null");
+
+        ContractStore contracts = getContractStore();
+
+        SSDStore ssds = new SSDStore(soxstore, contracts, comms, bug);
+        if (ssds == null)
+            throw new StoreException("new SSDStore() returned null");
+        // soxes.setContractStore(getContractStore());
+        return (ServerFinder)ssds;
     }
 
 }