[Webfunds-commits] java/webfunds/sox SmartIssuer.java

Ian Grigg iang@cypherpunks.ai
Fri, 6 Apr 2001 19:46:05 -0400 (AST)


iang        01/04/06 19:46:05

  Modified:    webfunds/sox SmartIssuer.java
  Log:
  Added CommsManager stuff; and reworked init() to add another constructor.
  (Temp hack as this is now deprecated by webfunds.sox.server;)

Revision  Changes    Path
1.18      +75 -25    java/webfunds/sox/SmartIssuer.java

Index: SmartIssuer.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/SmartIssuer.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- SmartIssuer.java	2001/03/20 23:07:37	1.17
+++ SmartIssuer.java	2001/04/06 23:46:05	1.18
@@ -1,5 +1,5 @@
 /*
- * $Id: SmartIssuer.java,v 1.17 2001/03/20 23:07:37 iang Exp $
+ * $Id: SmartIssuer.java,v 1.18 2001/04/06 23:46:05 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -15,6 +15,8 @@
 
 import webfunds.utils.Debug;
 
+import webfunds.util.Panic;
+
 import webfunds.comms.*;
 
 /**
@@ -34,36 +36,76 @@
     protected int          which;
     protected int          size;
     protected Certificate  cert;
+    protected CommsManager comms = null;
 
     /**
+     *  Initialise the real data.
+     *
+     */
+    private void init(String[] serverURLs, Certificate cert)
+        throws SOXIssuerException
+    {
+        this.which  = 0;
+        this.cert   = cert;
+        this.others = null;
+
+        if (serverURLs.length == 0)
+            throw new SOXServerException("no servers listed");
+
+        this.urls = convertToURLs(serverURLs);
+        this.size = this.urls.size();
+        if (size == 0)
+            throw new SOXServerException("all server URLs are malformed!");
+
+        // XXX: we should be given a CommsManager, but old code might not
+        // do that.  Drop this when we can drop the extra constructor.
+        if (comms == null)
+            comms = new BasicCommsManager();
+
+        startSimpleServers(this.urls);
+    }
+
+    /**
      * Create a new Issuer object
      * The Issuer object will normally be cached by the caller,
      * but is not usefully stored on disk.
      * This call is passive, call getReady() to cause action.
      *
-     * @param name our name for the issuer
-     * @param signer the [operator] certificate which signs the
+     * @param serverURLs links to the server, some of which might work
+     * @param cert the [operator] certificate which signs the
      *               server's [server] certificate
-     * @param agent the comms agent that sends requests at the transport layer
      */
-    public SmartIssuer(String[] rawUrls, Certificate operCert, PrintWriter bug)
+    public SmartIssuer(String[] serverURLs, Certificate cert, PrintWriter bug)
         throws SOXIssuerException
     {
         debug(bug, "        I  ");
+
+        init(serverURLs, cert);
 
-        which = 0;
-        this.cert = operCert;
-        others = null;
+        logmsg("SmartIssuer(" + size + " urls, operCert, bug);");
+    }
 
-        if (rawUrls.length == 0)
-            throw new SOXIssuerException("no servers listed");
+    /**
+     * Create a new Issuer object
+     * The Issuer object will normally be cached by the caller,
+     * but is not usefully stored on disk.
+     * This call is passive, call getReady() to cause action.
+     *
+     * @param serverUrls links to the server, some of which might work
+     * @param cert the [operator] certificate which signs the
+     *               server's [server] certificate
+     * @param comms can provide requestor objects at the transport layer
+     */
+    public SmartIssuer(String[] serverURLs, Certificate cert,
+                       CommsManager comms,
+                       PrintWriter bug)
+        throws SOXIssuerException
+    {
+        debug(bug, "        I  ");
 
-        urls = convertToURLs(rawUrls);
-        size = urls.size();
-        if (size == 0)
-            throw new SOXIssuerException("all URLs are malformed!");
+        this.comms = comms;
 
-        startSimpleServers(urls);
+        init(serverURLs, cert);
 
         logmsg("SmartIssuer(" + size + " urls, operCert, bug);");
     }
@@ -121,8 +163,8 @@
             URL url = (URL)urls.elementAt(which % siz);
             logmsg("new Simple at " + url);
 
-            CommsAgent comms = new HttpSocketAgent(url, getDebug());
-            SimpleIssuer simp = new SimpleIssuer(""+i, cert, comms, getDebug());
+            CommsAgent agent = new HttpSocketAgent(url, comms, getDebug());
+            SimpleIssuer simp = new SimpleIssuer(""+i, cert, agent, getDebug());
 
             servers[i] = simp;
         }
@@ -202,9 +244,9 @@
                                         "tried them all, but all are down");
 
         else if (laters == 0)
-            throw new SOXIssuerException("tried them all, all dead.  Fatal?");
+            throw new SOXServerException("tried them all, all dead.  Fatal?");
         else
-            throw new SOXIssuerException("tried them all, " +
+            throw new SOXServerException("tried them all, " +
                                    laters + " later, " + failures + " failed");
     }
 
@@ -241,7 +283,7 @@
             throw new SOXLaterException(SOXLaterException.LATER_DOWN,
                                         "tried them all, but all are down");
         else if (laters == 0)
-            throw new SOXIssuerException("tried them all, all dead.  Fatal?");
+            throw new SOXServerException("tried them all, all dead.  Fatal?");
         else // mixed results
             throw new SOXLaterException(SOXLaterException.LATER_DOWN,
                                    "tried them all, " +
@@ -274,14 +316,17 @@
             url = (URL)others.elementAt(i);
             logmsg("other URL at " + url);
 
-            String domain = url.getHost();
+            String host = url.getHost();
 
-            String s = httpGet + domain + httpEnd;
-            logmsg(i + ": " + domain);
+            String getRequest = httpGet + host + httpEnd;
+            logmsg(i + ": " + host);
             byte[] page;
+            SingleRequestor sr = comms.getSingleRequestor(url);
+            sr.setMax(256);
+
             try {
-                page = RawHttp.getSocket(domain, url.getPort(),
-                                           s.getBytes(), 256);
+                page = sr.get(getRequest.getBytes());
+
             } catch (RawURLException ex) {
                 failures++;
                 logmsg(url + " : is bad?");
@@ -290,6 +335,11 @@
                 failures++;
                 logmsg(url + " : later?");
                 continue ;
+            } catch (RawException ex) {
+                String s = "Unknown RawEx: " + ex;
+                logmsg(s);
+                ex.printStackTrace();
+                throw new Panic(s);
             }
 
             if (page == null)     // why is this?