Author: orbiter
Date: 2006-03-10 14:57:30 +0100 (Fri, 10 Mar 2006)
New Revision: 1873

Modified:
   trunk/source/de/anomic/kelondro/kelondroMScoreCluster.java
   trunk/source/de/anomic/kelondro/kelondroOutOfLimitsException.java
   trunk/source/de/anomic/plasma/plasmaWordIndexCache.java
Log:
fixed some problems with new cache flush karenz

Modified: trunk/source/de/anomic/kelondro/kelondroMScoreCluster.java
===================================================================
--- trunk/source/de/anomic/kelondro/kelondroMScoreCluster.java  2006-03-09 
14:03:54 UTC (rev 1872)
+++ trunk/source/de/anomic/kelondro/kelondroMScoreCluster.java  2006-03-10 
13:57:30 UTC (rev 1873)
@@ -138,14 +138,23 @@
         addScore(objs, 1);
     }
     
+    public synchronized void decScore(Object[] objs) {
+        addScore(objs, -1);
+    }
+    
     public synchronized void incScore(Object obj) {
         addScore(obj, 1);
     }
     
+    public synchronized void decScore(Object obj) {
+        addScore(obj, -1);
+    }
+    
     public synchronized void setScore(Object obj, int newScore) {
         if (obj == null) return;
         //System.out.println("setScore " + obj.getClass().getName());
         Long usk = (Long) refkeyDB.remove(obj); // get unique score key, old 
entry is not needed any more
+        if (newScore < 0) throw new kelondroOutOfLimitsException(newScore);
         
         if (usk == null) {
             // set new value
@@ -182,6 +191,7 @@
         
         if (usk == null) {
             // set new value
+            if (incrementScore < 0) throw new 
kelondroOutOfLimitsException(incrementScore);
             usk = new Long(scoreKey(encnt++, incrementScore));
             
             // put new value into cluster
@@ -198,7 +208,9 @@
             int oldHandle = (int) (c & 0xFFFFFFFFL);
             
             // set new value
-            usk = new Long(scoreKey(oldHandle, oldScore + incrementScore)); // 
generates an unique key for a specific score
+            int newValue = oldScore + incrementScore;
+            if (newValue < 0) throw new kelondroOutOfLimitsException(newValue);
+            usk = new Long(scoreKey(oldHandle, newValue)); // generates an 
unique key for a specific score
             refkeyDB.put(obj, usk);
             keyrefDB.put(usk, obj);
             

Modified: trunk/source/de/anomic/kelondro/kelondroOutOfLimitsException.java
===================================================================
--- trunk/source/de/anomic/kelondro/kelondroOutOfLimitsException.java   
2006-03-09 14:03:54 UTC (rev 1872)
+++ trunk/source/de/anomic/kelondro/kelondroOutOfLimitsException.java   
2006-03-10 13:57:30 UTC (rev 1873)
@@ -53,4 +53,8 @@
         super("Object size is " + actualSize + "; it exceeds the size limit " 
+ expectedLimit);
     }
     
+    public kelondroOutOfLimitsException(int actualSize) {
+        super("Object size is " + actualSize + "; must not be negative");
+    }
+    
 }

Modified: trunk/source/de/anomic/plasma/plasmaWordIndexCache.java
===================================================================
--- trunk/source/de/anomic/plasma/plasmaWordIndexCache.java     2006-03-09 
14:03:54 UTC (rev 1872)
+++ trunk/source/de/anomic/plasma/plasmaWordIndexCache.java     2006-03-10 
13:57:30 UTC (rev 1873)
@@ -207,14 +207,17 @@
     // cache settings
 
     public int maxURLinWordCache() {
+        if (hashScore.size() == 0) return 0;
         return hashScore.getMaxScore();
     }
 
     public long minAgeOfWordCache() {
+        if (hashDate.size() == 0) return 0;
         return System.currentTimeMillis() - longEmit(hashDate.getMaxScore());
     }
 
     public long maxAgeOfWordCache() {
+        if (hashDate.size() == 0) return 0;
         return System.currentTimeMillis() - longEmit(hashDate.getMinScore());
     }
 
@@ -345,25 +348,28 @@
         return count;
     }
 
-    public synchronized int tryRemoveURLs(String urlHash) {
+    public int tryRemoveURLs(String urlHash) {
         // this tries to delete an index from the cache that has this
         // urlHash assigned. This can only work if the entry is really fresh
         // Such entries must be searched in the latest entries
-        Iterator i = hashDate.scores(false);
-        String wordHash;
-        long t;
-        plasmaWordIndexEntryContainer c;
         int delCount = 0;
-        while (i.hasNext()) {
-            wordHash = (String) i.next();
-            // check time
-            t = longEmit(hashDate.getScore(wordHash));
-            if (System.currentTimeMillis() - t > ramCacheMinAge) return 
delCount;
-            // get container
-            c = (plasmaWordIndexEntryContainer) cache.get(wordHash);
-            if (c.remove(urlHash) != null) {
-                cache.put(wordHash, c);
-                delCount++;
+        synchronized (cache) {
+            Iterator i = hashDate.scores(false);
+            String wordHash;
+            long t;
+            plasmaWordIndexEntryContainer c;
+            while (i.hasNext()) {
+                wordHash = (String) i.next();
+                // check time
+                t = longEmit(hashDate.getScore(wordHash));
+                if (System.currentTimeMillis() - t > ramCacheMinAge) return 
delCount;
+                // get container
+                c = (plasmaWordIndexEntryContainer) cache.get(wordHash);
+                if (c.remove(urlHash) != null) {
+                    cache.put(wordHash, c);
+                    hashScore.decScore(wordHash);
+                    delCount++;
+                }
             }
         }
         return delCount;

_______________________________________________
YaCy-svn mailing list
[email protected]
http://lists.berlios.de/mailman/listinfo/yacy-svn

Antwort per Email an