[Webfunds-commits] java/webfunds/sox/value SSDStore.java

Ian Grigg iang@cypherpunks.ai
Fri, 13 Apr 2001 00:14:59 -0400 (AST)


iang        01/04/13 00:14:58

  Modified:    webfunds/sox/value SSDStore.java
  Log:
  added caching of SSDs and smart servers

Revision  Changes    Path
1.5       +30 -3     java/webfunds/sox/value/SSDStore.java

Index: SSDStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/value/SSDStore.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SSDStore.java	2001/04/13 01:46:08	1.4
+++ SSDStore.java	2001/04/13 04:14:58	1.5
@@ -1,5 +1,5 @@
 /*
- * $Id: SSDStore.java,v 1.4 2001/04/13 01:46:08 iang Exp $
+ * $Id: SSDStore.java,v 1.5 2001/04/13 04:14:58 iang Exp $
  *
  * Copyright (c) 1995-2000 Systemics Inc. on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,6 +8,7 @@
 
 
 import java.util.Enumeration;
+import java.util.Hashtable;
 import java.security.cert.Certificate;
 
 import webfunds.util.Log;
@@ -40,6 +41,9 @@
     protected Store         store;
     protected ContractStore contracts;
 
+    private Hashtable serversByItem;
+    private Hashtable serversBySSD;
+
     public SSDStore(Store store,
                     ContractStore contracts,
                     CommsManager comms,
@@ -58,6 +62,9 @@
         this.store = store;
         readInStore();
         logmsg("SSDStore Open!");
+
+        serversByItem = new Hashtable();
+        serversBySSD = new Hashtable();
     }
 
     protected void readInStore()
@@ -111,7 +118,6 @@
 
 
 
-
     /**
      *  This is the IssuerFinder call, which returns the
      *  needed Server object from an ItemId.
@@ -125,6 +131,15 @@
     public Server getServer(ItemId id)
         throws SOXServerException, SOXLaterException
     {
+        Server server = (Server)serversByItem.get(id);
+        
+        if (server != null)
+        {
+            logmsg("HIT on item: " + id);
+            logmsg(" ==> " + server);
+            return server;
+        }
+
         Contract con = contracts.getContract(id);
 
         if (con == null)
@@ -152,6 +167,14 @@
                    " is not correct for SSD " + realname +
                    "\nWho knows whether this is the right thing to do?!?");
 
+        server = (Server)serversBySSD.get(ssd);
+        if (server != null)
+        {
+            logmsg("HIT on ssd: " + ssd);
+            logmsg(" ==> " + server);
+            return server;
+        }
+
         Certificate cert;
         try {
             cert = con.getServerCert();
@@ -161,8 +184,12 @@
                                          con + "\n" + ex);
         }
 
-        Server server = new SmartServer(realname, (DirSSDStore)this,
+        server = new SmartServer(realname, (DirSSDStore)this,
                                         cert, comms, getLog());
+
+        serversByItem.put(id, server);
+        serversBySSD.put(ssd, server);
+
         return server;
     }