[Webfunds-commits] java/webfunds/sox/server Test.java DirSSDStore.java SSD.java SimpleServer.java SmartServer.java

Ian Grigg iang@cypherpunks.ai
Sun, 8 Apr 2001 15:41:59 -0400 (AST)


iang        01/04/08 15:41:59

  Modified:    webfunds/sox/server DirSSDStore.java SSD.java
                        SimpleServer.java SmartServer.java
  Added:       webfunds/sox/server Test.java
  Log:
  fixed some bugs, wrote this Test, now works!

Revision  Changes    Path
1.2       +91 -89    java/webfunds/sox/server/DirSSDStore.java

Index: DirSSDStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/server/DirSSDStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DirSSDStore.java	2001/04/06 22:49:59	1.1
+++ DirSSDStore.java	2001/04/08 19:41:58	1.2
@@ -1,7 +1,7 @@
 /*
- * $Id: DirSSDStore.java,v 1.1 2001/04/06 22:49:59 iang Exp $
+ * $Id: DirSSDStore.java,v 1.2 2001/04/08 19:41:58 iang Exp $
  *
- * Copyright (c) Systemics Ltd 1995-1999 on behalf of
+ * Copyright (c) 1995-2001 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
  */
 package webfunds.sox.server;
@@ -11,7 +11,6 @@
 import java.io.PrintWriter;
 
 import java.util.Hashtable;
-import java.util.Stack;
 import java.util.Enumeration;
 
 import java.net.URL;
@@ -22,18 +21,12 @@
 import webfunds.utils.Debug;
 
 import webfunds.comms.CommsManager;
-import webfunds.comms.BasicCommsManager;
+import webfunds.comms.URLSupport;
 
-import webfunds.sox.Issuer;
-import webfunds.sox.SOXIssuerException;
-import webfunds.sox.SOXServerException;
 import webfunds.sox.SOXLaterException;
-import webfunds.sox.ItemId;
 
-import webfunds.ricardian.*;   // shouldn't be here!
 
 
-
 /**
  *  A Store for SSDs (SOX Server Descriptors).
  *  Provides access to SSDs, and caches the latest file on each one.
@@ -229,7 +222,7 @@
     /**
      * Refresh an SSD from the URLs off the net.
      * For some reason - bounced connections - the caller has decided
-     * that the Issuer is bad.  One reason might be that the Issuer
+     * that the server is bad.  One reason might be that the server
      * has moved.  Refresh the SSD and see if it has changed.
      *
      * Experimental!
@@ -237,44 +230,105 @@
      * @return true if it changed (caller should retry activity)
      */
     public boolean refreshSSD(SSD old)
-        throws SSDException, SOXLaterException
+        throws SOXLaterException
     {
+        /*
+         *  First, check the latest in the cache to see if it is updated.
+         *  Use the more recent one available.
+         *  Also check that it is a little bit stale at least.
+         */
+        String name = old.getName();
+        SSD cached = (SSD) ssds.get(name);
+        if (cached == null)
+            throw new Panic("unknown SSD: " + old);
+
+        int oldVersion = old.getVersion();
+        int cachedVersion = cached.getVersion();
+        if (cachedVersion == 0)              // our version is broken
+        {
+            return refresh(cached);          // so try an update
+            // throw new SSDException("cannot refresh, new version is 0");
+        }
 
-        String[] urls = old.getArray("server_file_url");
-        if (urls.length == 0)
-            throw new SSDException(no_urls);
+        if (oldVersion < cachedVersion)     // we already have a newer one
+            return true ;
+
+        /*
+         *  The cached version has the same version number.
+         *  If the SSD hasn't been updated in a while, try and
+         *  refresh it.
+         */
+
+        long now = System.currentTimeMillis();
+        final long TEN_MINUTES = 600 * 1000;
+        if (now - cached.lastUpdated() < TEN_MINUTES)
+            return false;
+
+        return refresh(cached);
+    }
+
+    private boolean refresh(SSD current)
+        throws SOXLaterException
+    {
+        /*
+         */
+        String name = current.getName();
+        String[] urls = current.getArray("server_file_url");
 
         //
-        // Collect the existing cache one and try for the new one on the net.
+        //  Get the latest off the net.
         //
-        // SSD old = getSSDFromCache(urls);
-        SSD ssd = getSSDFromNet(urls);
-
-        int oldV = old.getVersion();
-        int newV = ssd.getVersion();
-        if (newV == 0)
-            throw new SSDException("cannot refresh, new version is 0");
+        SSD newest;
+        try {
+            newest = getSSDFromNet(urls);
+        } catch (SSDException ex) {
+            logmsg("cannot refresh now: " + ex);
+            return false;
+        }
 
-        if (oldV >= newV)
-            return false ;
+        long now = System.currentTimeMillis();
+        int newVersion = newest.getVersion();
+        if (newVersion == 0)
+        {
+            logmsg("new SSD does not have version number? " + newest);
+            current.resetLastUpdate(now);
+            return false;
+        }
 
-        String name = old.getName();
-        logmsg("updating " + name + " from " + oldV + " to " + newV);
+        int currentVersion = current.getVersion();
+        if (currentVersion >= newVersion)
+        {
+            current.resetLastUpdate(now);
+            return false;
+        }
 
         //
-        //  A quick name check.
+        //  A quick name check.  If it changes name on us, we are sunk.
         //
-        String newName = ssd.getName();
+        String newName = newest.getName();
         if (!name.equals(newName))
-            throw new SSDException("refreshed SSD changed name: " +
+        {
+            logmsg("refreshed SSD changed name: " +
                                          name + " ==> " + newName);
+            current.resetLastUpdate(now);
+            return false;
+        }
+
+        logmsg("updating " + name +
+               " from " + currentVersion +
+               " to " + newVersion);
 
         //
         //  We've found a new version.
         //  Need to store it over the top of the old.
         //
-
-        addAndSave(ssd);
+        try {
+            addAndSave(newest);
+        } catch (SSDException ex) {
+            logmsg("cannot save persistantly, locally cached only:\n\n" + ex);
+            addSSD(newest);
+            return true;
+        }
         return true ;
     }
 
@@ -367,7 +421,7 @@
      * Browse an SSD from some URLs.
      * @return the first SSD that we find
      */
-    protected SSD getSSDFromNet(String[] urls)
+    protected SSD getSSDFromNet(String[] locs)
         throws SSDException, SOXLaterException
     {
         // only used locally I think
@@ -376,22 +430,16 @@
 
         SSD ssd;
 
+        URL[] urls = URLSupport.convertToURLs(locs, null);
+
         //
         // Extract the urls - again - and go out on the net.
         // Might want to think about multithreading this stage.
         //
         for (int i = 0; i < urls.length; i++)
         {
-            logmsg("net <" + i + "> " + urls[i]);
-            URL url;
-            try {
-                url = new URL(urls[i]);
-            } catch (MalformedURLException ex) {
-                logmsg(ex + ": " + urls[i]);
-                continue ;
-            }
-            if (url == null)
-                continue ;
+            URL url = urls[i];
+            logmsg("net <" + i + "> " + url);
 
             ssd = SSD.getInstance(url, comms, getDebug());
             if (ssd != null)
@@ -399,7 +447,7 @@
             // might want to keep searching here, if we are refreshing
         }
 
-        throw new SSDException("no SSD file from " + urls[0]);
+        throw new SSDException("no SSD file from " + locs[0]);
     }
 
     /**
@@ -503,50 +551,4 @@
         return retval;
     }
 
-    static final String usage =
-           "Test Usage: DirSSDStore directory";
-
-    public static void main(String[] arg)
-        throws ContractException, ContractDirectoryException,
-               SSDException, SOXLaterException
-    {
-        if (arg.length == 0)
-        {
-            System.err.println(usage);
-            System.exit(1);
-        }
-
-        File d = new File(arg[0]);
-        PrintWriter bug = new PrintWriter(System.err, true);
-        DirContractStore cons = new DirContractStore(d, bug);
-        CommsManager cm = new BasicCommsManager();
-        DirSSDStore store = new DirSSDStore(cm, d, bug);
-        System.err.println("Started: " + store);
-        
-        //
-        //  For all contracts, ask for the SSD file (and the urls).
-        //
-        Contract[] contracts = cons.getAllContracts();
-        int found = 0;
-        for (int i = 0; i < contracts.length; i++)
-        {
-            System.err.println("  " + i + ": " + contracts[i]);
-
-            Contract con = contracts[i];
-            String[] locs = SSDFields.getLocation(con);
-            String name = SSDFields.getName(con);
-
-            SSD ssd = store.get(name, locs);
-            found++;
-
-            System.err.println("  " + ssd);
-            String[] urls = ssd.getArray("sox", "server_url");
-            for (int k = 0; k < urls.length; k++)
-            {
-                System.err.println("           " + urls[k]);
-            }
-        }
-        
-
-    }
 }



1.2       +53 -41    java/webfunds/sox/server/SSD.java

Index: SSD.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/server/SSD.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSD.java	2001/04/06 22:49:59	1.1
+++ SSD.java	2001/04/08 19:41:58	1.2
@@ -1,7 +1,7 @@
 /*
- * $Id: SSD.java,v 1.1 2001/04/06 22:49:59 iang Exp $
+ * $Id: SSD.java,v 1.2 2001/04/08 19:41:58 iang Exp $
  *
- * Copyright (c) Systemics Ltd 1995-1999 on behalf of
+ * Copyright (c) 1995-2001 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
  */
 package webfunds.sox.server;
@@ -23,6 +23,7 @@
 import webfunds.util.Support;
 
 import webfunds.comms.RawHttp;
+import webfunds.comms.URLSupport;
 import webfunds.comms.CommsManager;
 import webfunds.comms.BasicCommsManager;
 import webfunds.comms.SingleRequestor;
@@ -86,8 +87,13 @@
     // protected   Issuer        issuer;
     protected   String        originalName;
 
+    private long updated = 0;
 
+    public long  lastUpdated()                  { return updated; }
+    public void  resetLastUpdate(long t)        { updated = t; }
 
+
+
 ///////  Constructors  /////////////////////////////////////////////
 
     public SSD(byte[] fileData, String name, PrintWriter bug)
@@ -177,7 +183,7 @@
 //////  Initial Instances  /////////////////////////////////////
 
     /**
-     * Create a SSD given the file.
+     * Create an SSD object given the file of a cached copy.
      *
      * @param file name for SSD file
      */
@@ -205,7 +211,7 @@
     }
 
     /**
-     * Create a SSD object given an URL
+     * Create an SSD object given an URL.
      *
      * @param url URL to read the object from
      * @param comms where to get a comms requestor from
@@ -226,18 +232,22 @@
         SingleRequestor sr = comms.getSingleRequestor(url);
         byte[] getRequest = RawHttp.getGetData(url);
 
+        String gr = new String(getRequest);
+        // if (bug != null)
+        //     bug.println("try this: " + gr);
+
         byte[] buf;
         try {
             // do a Get on the URL
             buf = sr.get(getRequest);
         } catch (RawConnectException ex) {
-            throw new SOXLaterException(ex.getErrno(), "no net?\n" + ex);
+            throw new SOXLaterException(ex.getErrno(), "no net?\n" + gr + ex);
         } catch (RawURLException ex) {
             ex.printStackTrace();
-            throw new SSDException("bad url?\n" + ex);
+            throw new SSDException("bad url?\n" + gr + ex);
         } catch (RawException ex) {
             ex.printStackTrace();
-            throw new Panic("Bad RawEx: " + ex);
+            throw new Panic("RawEx: \n" + gr + ex);
         }
 
         byte[] data;
@@ -249,7 +259,9 @@
             "Check this URL (as found in the contract local file).");
         }
 
-        return new SSD(data, url+"", bug) ;
+        SSD ssd = new SSD(data, url+"", bug);
+        ssd.resetLastUpdate(System.currentTimeMillis());
+        return ssd;
     }
 
     /**
@@ -420,34 +432,6 @@
         return names ;
     }
 
-    /**
-     *  Convert a list of strings to URLs.
-     *  Ignores malformed ones.
-     *  Always returns an array.
-     */
-    public static URL[] convertToURLs(String[] stringURLs, PrintWriter bug)
-    {
-        Vector v = new Vector();
-
-        for (int i = 0; i < stringURLs.length; i++)
-        {
-            URL url;
-            try {
-                url = new URL(stringURLs[i]);
-            } catch(MalformedURLException ex) {
-                bug.println(i + ": " + ex + ":\n<<" + stringURLs[i] + ">>");
-                continue ;
-            }
-            v.addElement(url);
-            bug.println("ok " + stringURLs[i]);
-        }
-
-        URL[] urls = new URL[v.size()];
-        v.copyInto(urls);
-
-        return urls;
-    }
-
     public URL[] getServerLocation()
     {
         //
@@ -456,7 +440,7 @@
         //     server_url += http://mises.econ:8888/
         //
         String[] strings = getArray("server_url" );
-        return convertToURLs(strings, bug);
+        return URLSupport.convertToURLs(strings, bug);
     }
 
     public URL[] getNearbyURLs()
@@ -467,7 +451,7 @@
         //     nearby_urls += http://www.help.econ/
         //
         String[] strings = getArray("nearby_urls" );
-        return convertToURLs(strings, bug);
+        return URLSupport.convertToURLs(strings, bug);
     }
 
     /**
@@ -479,11 +463,15 @@
     public int getVersion()
     {
         /*
-         * There should be a name in the file.
+         *  Get the version tag.
          */
         String s = getField("server_version");
-        if (s == null || "".equals(s))
+        if (s == null || s.length() == 0)
+        {
+            String empty = (s==null ? "<null>" : "<empty>");
+            logmsg("no version in " + getName() + ": " + empty);
             return 0 ;
+        }
 
         Integer i;
         try {
@@ -501,6 +489,30 @@
         return i2;
     }
 
+    /**
+     *  @return the more recent version of this and another
+     */
+    public SSD moreRecent(SSD other)
+    {
+        int myV = getVersion();
+        int his = other.getVersion();
+
+        if (myV > his)
+            return this;
+        else if (myV < his)
+            return other;
+
+        /*
+         *  If the versions are the same, then return the one
+         *  with the best update time.
+         */
+        long hisUpdateTime = other.lastUpdated();
+        if (updated > hisUpdateTime)
+            return this;
+        else
+            return other;
+    }
+
 
 
 ///////  Access to Fields  /////////////////////////////////////////////
@@ -665,7 +677,7 @@
 
     public String toString()
     {
-        return getName();
+        return getName() + " version==" + getVersion();
     }
 
     public static void main(String[] arg)
@@ -680,7 +692,7 @@
         String name = arg[0];
         SSD ssd = null;
         PrintWriter bug = new PrintWriter(System.err);
-        CommsManager comms = new BasicCommsManager();
+        CommsManager comms = new BasicCommsManager(bug);
 
         try
         {



1.2       +31 -25    java/webfunds/sox/server/SimpleServer.java

Index: SimpleServer.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/server/SimpleServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleServer.java	2001/04/06 22:49:59	1.1
+++ SimpleServer.java	2001/04/08 19:41:58	1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: SimpleServer.java,v 1.1 2001/04/06 22:49:59 iang Exp $
+ * $Id: SimpleServer.java,v 1.2 2001/04/08 19:41:58 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -123,11 +123,11 @@
     public void getReady()
         throws SOXIssuerException, SOXLaterException
     {
-        try {
+//        try {
             getReadyToRequest();
-        } catch (SOXServerException ex) {
-            throw new SOXIssuerException("" + ex);
-        }
+//        } catch (SOXServerException ex) {
+//            throw new SOXIssuerException("" + ex);
+//        }
     }
 
     /**
@@ -189,7 +189,7 @@
         } catch (SOXPacketException ex) {  // what was this for?
             setDead(ex.getMessage());
             throw new SOXServerException(ex.getNumber(),
-                                         "SOXPE 1: " + ex.getMessage());
+                      "SOXPE 1 {" + bullets + "}: " + ex.getMessage());
         } catch (SOXServerException ex) {
             setDead(ex.getMessage());      // BA thinks info is wrong
             throw ex ;
@@ -229,7 +229,8 @@
                 // fetchServerCert();    // do a retry on the ServerCert?
                 setDead(e);              // no, do a high level retry
 
-                throw new SOXServerException(SOXException.COMMS_CERT, e);
+                throw new SOXServerException(SOXException.COMMS_CERT,
+                                             "{" + bullets + "} " + e);
             }
             
             logmsg("Using comms key (valid signature by the server)");
@@ -274,7 +275,7 @@
         } catch (SOXPacketException ex) {  // what was this for?
             setDead(ex.getMessage());
             throw new SOXServerException(ex.getNumber(),
-                                         "SOXPE 2: " + ex.getMessage());
+                      "SOXPE 2 {" + bullets + "}: " + ex.getMessage());
         } catch (SOXServerException ex) {
             setDead(ex.getMessage());      // BA thinks info is wrong
             throw ex ;
@@ -295,7 +296,8 @@
                    sk + "\n\n\n" + ok + "\n\n");
 
             setDead(e);
-            throw new SOXServerException(SOXException.SERVER_CERT, e);
+            throw new SOXServerException(SOXException.SERVER_CERT,
+                                         "{" + bullets + "} " + e);
         }
 
         // Careful not to set this before validating the signature
@@ -313,11 +315,11 @@
     public byte[] request(Request req)
         throws SOXLaterException, SOXIssuerException
     {
-        try {
+//        try {
             return sendRequest(req);
-        } catch (SOXServerException ex) {
-            throw new SOXIssuerException("" + ex);
-        }
+//        } catch (SOXServerException ex) {
+//            throw new SOXIssuerException("" + ex);
+//        }
     }
 
     /**
@@ -351,8 +353,9 @@
 
             } catch(SOXKeyException ex) {
                 /*
-                 * We are here because the key is stale. Try and get a new
-                 * CommsKey *once* and retry the request.
+                 *  We are here because the key is stale.
+                 *  Try and get a new CommsKey *once* and
+                 *  retry the request.
                  */
                 logmsg("*** first request failed, refetching comms...");
                 refetchCommsKey();
@@ -367,21 +370,21 @@
             //
             setDead(ex.getMessage());
             throw new SOXServerException(ex.getNumber(),
-                                         "request: " + ex.getMessage());
+                      "request {" + bullets + "}: " + ex.getMessage());
 
         } catch (SOXPacketException ex) {
             setDead(ex.getMessage());
             throw new SOXServerException(ex.getNumber(),
-                                         "SOXPE 3: " + ex.getMessage());
+                      "SOXPE 3 {" + bullets + "}: " + ex.getMessage());
 
         } catch (SOXServerException ex) {   // Even if I don't deal with it...
-            logmsg("catching (and dying on)" + ex);
             setDead(ex.getMessage());       // ...I should still bail out.
+            logmsg("catching (and dying on) {" + bullets + "} " + ex);
             throw ex ;
 
         } catch (SOXLaterException ex) {    // Even if I don't deal with it...
-            logmsg("catching (and dying on)" + ex);
             setDead(ex.getMessage());       // ...I should still bail out.
+            logmsg("catching (and dying on) {" + bullets + "} " + ex);
             throw ex ;
         }
     }
@@ -424,13 +427,16 @@
 /////////  Time Syncronisation  //////////////////////////////////////////
     
     // if a fatal exception is found, set me as Dead, force user to re-invoke
-    protected boolean      isDead       = false;
+    protected int          bullets      = 0;
     protected String       reason       = "";
-    public boolean         isDead()             { return isDead ; }
-    public void            setDead()            { isDead = true ; }
-    public void            setDead(String s)    { isDead = true; reason = s; }
-    public void            setAlive()           { isDead = false ; }
+    public boolean         isDead()             { return bullets == 0 ; }
+    public void            setDead()            { bullets++; }
+    public void            setDead(String s)    { bullets++; reason = s; }
+    public void            setAlive()           { bullets = 0; }
     public String          getDead()            { return reason; }
+    public boolean         tooDead()            { return (bullets % 10) == 9; }
+
+
 
     /**
      *  Just to make it obvious what the numbers are used for...
@@ -487,7 +493,7 @@
         } catch (SOXPacketException ex) {
             setDead(ex.getMessage());
             throw new SOXServerException(ex.getNumber(),
-                                        "SOXPE TSR: " + ex.getMessage());
+                      "SOXPE TSR {" + bullets + "}: " + ex.getMessage());
         }
 
         timediff = reply.getTimeDifference();   // as seen by SOX Server



1.2       +71 -24    java/webfunds/sox/server/SmartServer.java

Index: SmartServer.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/server/SmartServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SmartServer.java	2001/04/06 22:49:59	1.1
+++ SmartServer.java	2001/04/08 19:41:58	1.2
@@ -1,7 +1,7 @@
 /*
- * $Id: SmartServer.java,v 1.1 2001/04/06 22:49:59 iang Exp $
+ * $Id: SmartServer.java,v 1.2 2001/04/08 19:41:58 iang Exp $
  *
- * Copyright (c) 2001 Systemics Inc on behalf of
+ * Copyright (c) 1995-2001 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
  */
 package webfunds.sox.server;
@@ -138,18 +138,34 @@
         }
     }
 
+
+    protected int timeouts = 0;
+    protected static final int TIMEOUT = 3;
+
     /**
-     * Do the things necessary for being ready for a request.
-     * On return, current is set to a hopefully valid Issuer.
+     *  Check the condition of retry.
+     *  @return true if a retry is worth attempting
      */
-    public void getReady()
-        throws SOXLaterException, SOXIssuerException
+    public boolean retryNow()
+        throws SOXLaterException
     {
-        try {
-            getReadyToRequest();
-        } catch (SOXServerException ex) {
-            throw new SOXIssuerException("" + ex);
+        boolean retry = false;
+        if (timeouts++ > TIMEOUT)
+        {
+            timeouts = 0;
+            return ssds.refreshSSD(ssd);
+        }
+
+        int len = servers.length;
+        for (int i = 0; i < len; i++)
+        {
+            if (servers[i].tooDead())
+            {
+                return ssds.refreshSSD(ssd);
+            }
         }
+
+        return false;
     }
 
     /**
@@ -159,7 +175,30 @@
     public void getReadyToRequest()
         throws SOXLaterException, SOXServerException
     {
+        try {
+            getready();
+        } catch (SOXLaterException ex) {
+
+            /*
+             * if (No Net) throw later ;
+             */
+            if (ex.isLaterNet())
+            {
+                logmsg(ex + " (No Net Connection)");
+                throw ex ;
+            }
+
+            if (retryNow())
+                getready();
+            else
+                throw ex;
+        }
+    }
 
+    private void getready()
+        throws SOXLaterException, SOXServerException
+    {
+
         logmsg("getReady()");
         if (current != null)
         {
@@ -185,7 +224,8 @@
 
         while (which++ < guard)
         {
-            simp = servers[which % servers.length];
+            int index = which % servers.length;
+            simp = servers[index];
 
             logmsg(which + ": " + simp);
             try {
@@ -206,14 +246,14 @@
                 current = simp;
                 // checkTimes();
                 logmsg("times " + timediff + " / " + deviation);
-                return ;
+                return ;                      // <<=== normal return here
             }
             failures++;  // does this ever happen?
         }
 
         //
         //  All issuers gave grief.
-        //  What we are left with is all issuers down or
+        //  What we are left with is all simples down or
         //  unavailable.  However, there may be no net.
         //
         checkNet();
@@ -233,19 +273,8 @@
     }
 
     /**
-     * Do the things necessary for being ready for a request.
-     * On return, current is set to a hopefully valid Issuer.
+     *  Send the request.
      */
-    public byte[] request(Request req)
-        throws SOXLaterException, SOXIssuerException
-    {
-//        try {
-            return sendRequest(req);
-//        } catch (SOXServerException ex) {
-//            throw new SOXIssuerException("" + ex);
-//        }
-    }
-
     public byte[] sendRequest(Request req)
         throws SOXLaterException, SOXServerException
     {
@@ -284,6 +313,24 @@
             throw new SOXLaterException(SOXLaterException.LATER_DOWN,
                                    "tried them all, " +
                                    laters + " later, " + failures + " failed");
+    }
+
+    /**
+     *  Compatibility call for old Isser style.
+     */
+    public byte[] request(Request req)
+        throws SOXLaterException, SOXIssuerException
+    {
+        return sendRequest(req);
+    }
+
+    /**
+     *  Compatibility call for old Isser style.
+     */
+    public void getReady()
+        throws SOXLaterException, SOXIssuerException
+    {
+        getReadyToRequest();
     }
 
     static final String httpGet = "GET / HTTP/1.1\r\nHost: ";



1.1                  java/webfunds/sox/server/Test.java

Index: Test.java
===================================================================
/*
 * $Id: Test.java,v 1.1 2001/04/08 19:41:58 iang Exp $
 *
 * Copyright (c) 2001 Systemics Inc on behalf of
 * the WebFunds Development Team.  All Rights Reserved.
 */
package webfunds.sox.server;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import webfunds.comms.CommsManager;
import webfunds.comms.BasicCommsManager;

import webfunds.ricardian.DirContractStore;
import webfunds.ricardian.Contract;
import webfunds.ricardian.SSDFields;



/**
 *  A test for the SSD and Store.
 *  Because this bridges across to Contracts,
 *  which shouldn't be a dependancy, it is stuck
 *  here in a separate class.
 */
public class Test
{


    static final String usage =
           "Test Usage: DirSSDStore contractsDir testDir";

    public static void main(String[] arg)
        throws Exception
    {
        if (arg.length != 2)
        {
            System.err.println(usage);
            System.exit(1);
        }

        File contractsDir = new File(arg[0]);
        File testDir      = new File(arg[1]);
        testDir.mkdir();

        PrintWriter bug = new PrintWriter(System.err, true);
        DirContractStore cons = new DirContractStore(contractsDir, bug);
        CommsManager cm = new BasicCommsManager(bug);
        DirSSDStore store = new DirSSDStore(cm, testDir, bug);
        System.err.println("Started: " + store);
        
        //
        //  For all contracts, ask for the SSD file (and the urls).
        //
        Contract[] contracts = cons.getAllContracts();
        int found = 0;
        for (int i = 0; i < contracts.length; i++)
        {
            System.err.println("  " + i + ": " + contracts[i]);

            Contract con = contracts[i];
            String[] locs = SSDFields.getLocation(con);
            String name = SSDFields.getName(con);

            SSD ssd = store.get(name, locs);
            found++;

            System.err.println("  " + ssd);
            String[] urls = ssd.getArray("sox", "server_url");
            for (int k = 0; k < urls.length; k++)
            {
                System.err.println("           " + urls[k]);
            }
        }

        System.err.println("Stored:");
        SSD[] ssdAll = store.getAllSSDs();
        for (int i = 0; i < ssdAll.length; i++)
        {
            System.err.println("  " + i + ": " + ssdAll[i]);
        }

    }
}