fix some compile bugs ...still some more to go
authoradash <adash>
Wed, 4 Nov 2009 00:07:05 +0000 (00:07 +0000)
committeradash <adash>
Wed, 4 Nov 2009 00:07:05 +0000 (00:07 +0000)
need a Global string to create a new hash entry for an each email and then compare it with
the global entry in the distributed hash map

Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java
Robust/src/Benchmarks/Distributed/SpamFilter/EphemeralSignature.java
Robust/src/Benchmarks/Distributed/SpamFilter/FilterResult.java
Robust/src/Benchmarks/Distributed/SpamFilter/Mail.java
Robust/src/Benchmarks/Distributed/SpamFilter/SignatureComputer.java
Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java

index 5b7857236ccef21e41819c319f32f2039daceb54..93ffe3a92524b046ca6ece252ffad46b2a6eb12f 100644 (file)
@@ -19,10 +19,6 @@ public class DistributedHashMap {
       return value;
   }
 
-  public DistributedHashMapIterator iterator(int type) {
-    return new DistributedHashMapIterator(this, type);
-  }
-
   Object remove(Object key) {
     int hashcode=key.hashCode();
     int index1=hash1(hashcode, table.length);
index b5a80a5ab9718fb5c02c209a3e75e0d1bc592425..f938aac9f07cca10c7d658125ddd291caa9586e3 100644 (file)
@@ -30,10 +30,6 @@ public class EphemeralSignature {
     return signature;
   }
 
-  private String computeHexDigest(String body) {
-    return 
-  }
-
   /*
   public long DEKHash(String str)
   {
index 2a8a2bf211546bd46cdb4c019e9e82111954fdf5..2eab89ccab223647285a82579b6c374cdd08c47c 100644 (file)
@@ -37,7 +37,7 @@ public class FilterResult {
 
   public boolean getResult(int[] confidenceVals) {
     int[] res = new int[3];
-    for(int i=0; i<confidenceVals; i++) {
+    for(int i=0; i<confidenceVals.length; i++) {
        if(confidenceVals[i] < 0)
          res[0]+=1; //unknown
        if(confidenceVals[i] >= 0 && confidenceVals[i] < 500)
@@ -60,7 +60,7 @@ public class FilterResult {
     if(max==2)
       return true;
 
-    System.out.println("Err: getResult() Shouldn't come here\n");
+    System.out.println("Err: getResult() Control shouldn't come here\n");
     return false;
   }
 
index e14633e7af63accefc9b92f807b46f82711e360a..41cb3cda2fe6ed6f4aa79e099ebca250aa3d64a5 100644 (file)
@@ -11,7 +11,7 @@ public class Mail {
        String cc;  
        String subject;
        String body;
-  String noURLBody;
+    String noURLBody;
        String sourceCode;
        boolean hasAttachement;
        String encoding; //rich text, plain, html
@@ -343,6 +343,22 @@ public class Mail {
     return isSpam;
   }
 
+  /**
+   *  Returns result to the Spam filter
+   **/
+  public Vector checkMail(int userid) {
+    //Preprocess emails
+    //Vector partsOfMailStrings = mail.createMailStringsWithURL();
+    Vector partsOfMailStrings = getCommonPart();
+    partsOfMailStrings.addElement(getBodyString());
+
+    //Compute signatures
+    SignatureComputer sigComp = new SignatureComputer();
+    Vector signatures = sigComp.computeSigs(partsOfMailStrings);//vector of strings
+
+    return signatures;
+  }
+
   /* For tests only */
   /*
   public static void main(String[] args)
index ab9caae81633440d542b0b4dd114963369586b84..1986d080f42d0b8f0a71c2928a2091e8e192ed63 100644 (file)
@@ -95,26 +95,11 @@ public class SignatureComputer {
           System.out.println("Couldn't find the signature engine\n");
         }
 
-        /*
-        switch (engineNo) {
-          case 4:
-            sig = computeSignature(engineNo,mail);
-            break;
-          case 8:
-            sig = computeSignature(engineNo,mail);
-            break;
-          default:
-            System.out.println("Couldn't find the signature engine\n");
-            //sig = computeSignature(engineNo,curPart.getCleaned());
-            break;
-        }//switch engineNo
-        */
-
-        if (sig != null && sig.length() > 0) {
+        if (sig != null) {
           String hash = engineNo + ":" + sig;
           printableSigs.addElement(hash);
         } else {
-          /* we didn't produce a signature for the mail. */
+          // we didn't produce a signature for the mail. 
         }
       }//engine
     }//each emails part
@@ -128,29 +113,19 @@ public class SignatureComputer {
    */
   private String computeSignature(int engineNo, String mail) {
     if(engineNo==4) {
-      String s1 = this.sig4.computeSignature(mail);
+      //String s1 = this.sig4.computeSignature(mail);
+      return this.sig4.computeSignature(mail);
       //return new String { this.sig4.computeSignature(mail) };
     }
 
+    /*
     if(engineNo==8) {
         //String cleanedButKeepHTML = Preprocessor.preprocess(mail,Preprocessor.ConfigParams.NO_DEHTML);
         //return this.sig8.computeSignature(cleanedButKeepHTML);
       return this.sig8.computeSignature(mail);
     }
+    */
 
     return null;
-
-    /*
-    switch (engineNo) {
-      case 4:
-        return new String { this.sig4.computeSignature(mail) };
-      case 8:
-        //TODO device and equivalent for this
-        //String cleanedButKeepHTML = Preprocessor.preprocess(mail,Preprocessor.ConfigParams.NO_DEHTML);
-        return this.sig8.computeSignature(cleanedButKeepHTML);
-      default:
-        return null;
-    }
-    */
   }
 }
index 1002c811a2c3ffa4c20d71f548d8564800f8b045..60d5c50a78457643b0668694f2d5715a40b33b3e 100644 (file)
@@ -1,8 +1,18 @@
 public class SpamFilter extends Thread {
   DistributedHashMap mydhmap;
+
   int id; //thread id
+
+  /**
+   * Total number of iterations
+   **/
   int numiter;
+
+  /**
+   * Total number of emails
+   **/
   int numemail;
+
   /**
    * Total number of threads
    **/
@@ -12,10 +22,12 @@ public class SpamFilter extends Thread {
 
   }
 
-  public SpamFilter(int numiter, int numemail,int id) {
+  public SpamFilter(int numiter, int numemail,int id, DistributedHashMap mydhmap, int nthreads) {
     this.numiter=numiter;
     this.numemail=numemail;
     this.id = id;
+    this.mydhmap = mydhmap;
+    this.nthreads = nthreads;
   }
 
   public void run() {
@@ -35,17 +47,28 @@ public class SpamFilter extends Thread {
         int pickemail = rand.nextInt(100);
         Mail email = new Mail("emails/email"+pickemail);
         //Mail email = getEmail(pickemail);
-        boolean filterAnswer = checkMail(email, thid);
+        Vector signatures = email.checkMail(thid);
+        //check with global data structure
+        int[] confidenceVals=null;
+        atomic {
+          confidenceVals = check(signatures,thid);
+        }
+
+        //---- create and  return results --------
+        FilterResult filterResult = new FilterResult();
+        boolean filterAnswer = filterResult.getResult(confidenceVals);
+
         boolean userAnswer = email.getIsSpam();
         if(filterAnswer != userAnswer) {
-          sendFeedBack(email, userAnswer);
+          atomic {
+            sendFeedBack(email, userAnswer, thid);
+          }
         }
-      }
-    }
+      } //end num emails
+    }//end num iter
   }
 
   public static void main(String[] args) {
-    int nthreads;
     int[] mid = new int[8];
     mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dc-1.calit2
     mid[1] = (128<<24)|(195<<16)|(136<<8)|163; //dc-2.calit2
@@ -56,18 +79,17 @@ public class SpamFilter extends Thread {
     mid[6] = (128<<24)|(195<<16)|(136<<8)|168; //dc-7.calit2
     mid[7] = (128<<24)|(195<<16)|(136<<8)|169; //dc-8.calit2
 
-
-    
-     //Read options from command prompt
+    //Read options from command prompt
     SpamFilter sf = new SpamFilter();
     SpamFilter.parseCmdLine(args, sf);
+    int nthreads = sf.nthreads;
 
     Random rand = new Random(8);
     //Randomly set Spam vals for each email
     for(int i=0; i<sf.numemail; i++) {
       Mail email = new Mail("./emails/email"+i);
       int spamval = rand.nextInt(100);
-      if(spamval<90) { //assume 90% are not spam and rest are spam
+      if(spamval<60) { //assume 60% are spam and rest are ham
         email.setIsSpam(false);
       } else {
         email.setIsSpam(true);
@@ -75,14 +97,34 @@ public class SpamFilter extends Thread {
     }
 
     //Create Global data structure 
-    
     DistributedHashMap dhmap;
+    SpamFilter[] spf;
     atomic {
       dhmap = global new DistributedHashMap(500, 0.75f);
+      spf = global new SpamFilter[nthreads];
+      for(int i=0; i<nthreads; i++) {
+        spf[i] = global new SpamFilter(sf.numiter, sf.numemail, i, dhmap, nthreads);
+      }
+    }
+
+    /* ---- Start Threads ---- */
+    SpamFilter tmp;
+    for(int i = 0; i<nthreads; i++) {
+      atomic {
+        tmp = spf[i];
+      }
+      tmp.start(mid[i]);
+    }
+
+    /* ---- Join threads----- */
+    for(int i = 0; i<nthreads; i++) {
+      atomic {
+        tmp = spf[i];
+      }
+      tmp.join();
     }
-    //3. N times iteration of work that needs to be done
-    //     by each client
 
+    System.out.println("Finished");
   }
 
   public static void parseCmdLine(String args[], SpamFilter sf) {
@@ -125,9 +167,11 @@ public class SpamFilter extends Thread {
   /**
    *  Returns result to the Spam filter
    **/
+  /*
   public boolean checkMail(Mail mail, int userid) {
     //Preprocess emails
     //Vector partsOfMailStrings = mail.createMailStringsWithURL();
+    /*
     Vector partsOfMailStrings = mail.getCommonPart();
     partsOfMailStrings.addElement(mail.getBodyString());
 
@@ -144,6 +188,7 @@ public class SpamFilter extends Thread {
 
     return spam;
   } 
+   */
 
   public int[] check(Vector signatures, int userid) {
     int numparts = signatures.size();
@@ -151,25 +196,26 @@ public class SpamFilter extends Thread {
     for(int i=0; i<numparts; i++) {
       String part = (String)(signatures.elementAt(i));
       char tmpengine = part.charAt(0);
-      String engine =  new String(tmpengine);
-      String signature = part.substring(2); //a:b index(a)=0, index(:)=1, index(b)=2
-      HashEntry myhe = new HashEntry();
+      String engine =  global new String(tmpengine);
+      String signature = global new String(part.substring(2));
+      //String signature = part.substring(2); //a:b index(a)=0, index(:)=1, index(b)=2
+      HashEntry myhe = global new HashEntry();
       myhe.setengine(engine);
       myhe.setsig(signature);
 
       //find object in distributedhashMap: if no object then add object 
       //else read object
-
       if(!mydhmap.containsKey(myhe)) {
         //add new object
-        myhe.stats = new HashStat();
+        myhe.stats = global new HashStat();
         myhe.stats.setuser(userid, 0, 0, -1);
-        FilterStatistic fs = new FilterStatistic(0,0,-1);
+        FilterStatistic fs =  global new FilterStatistic(0,0,-1);
         mydhmap.put(myhe, fs);
       } else {
         // ----- now connect to global data structure and ask for spam -----
-        HashEntry tmphe = mydhmap.getKey(myhe);
-        confidenceVals[i] = tmphe.askForSpam();
+        HashEntry tmphe = (HashEntry)(mydhmap.getKey(myhe));
+        FilterStatistic fs = (FilterStatistic) (mydhmap.get(myhe)); //get the value from hash
+        confidenceVals[i] = fs.getChecked();
       }
     }
 
@@ -187,25 +233,31 @@ public class SpamFilter extends Thread {
     for(int i=0;i<signatures.size();i++) {
       String part = (String)(signatures.elementAt(i));
       char tmpengine = part.charAt(0);
-      String engine =  new String(tmpengine);
-      String signature = part.substring(2); //a:b index(a)=0, index(:)=1, index(b)=2
-      HashEntry myhe = new HashEntry();
+      String engine =  global new String(tmpengine);
+      String signature = global new String(part.substring(2));
+      //String signature = part.substring(2); //a:b index(a)=0, index(:)=1, index(b)=2
+      HashEntry myhe = global new HashEntry();
       myhe.setengine(engine);
       myhe.setsig(signature);
 
       // ----- now connect to global data structure and upate spam count -----
-      HashEntry tmphe = mydhmap.getKey(myhe);
+      HashEntry tmphe = (HashEntry)(mydhmap.getKey(myhe));
       if(tmphe.stats.userid[id] != 1) {
         tmphe.stats.setuserid(id);
       }
 
+      FilterStatistic fs = (FilterStatistic) (mydhmap.get(myhe)); //get the value from hash
+
       //Increment spam or ham value 
       if(isSpam) {
-
-
+        tmphe.stats.incSpamCount(id);
+        fs.increaseSpam();
       } else {
-
+        tmphe.stats.incHamCount(id);
+        fs.increaseHam();
       }
     }
   }
 }
+
+