1 package org.objectweb.proactive.examples.eratosthenes; 2 3 34 35 import org.apache.log4j.Logger; 36 import org.objectweb.proactive.Body; 37 import org.objectweb.proactive.RunActive; 38 import org.objectweb.proactive.Service; 39 40 46 public class NumberSource implements java.io.Serializable , RunActive, Slowable { 47 48 static Logger logger = Logger.getLogger(NumberSource.class.getName()); 49 private PrimeOutputListener outputListener; 50 private ActivePrimeContainer first; 51 private boolean pause; 52 private boolean sleep; 53 private long currentNumber; 54 55 58 public NumberSource() { 59 pause = true; 60 currentNumber = 5; 61 } 62 63 public void setFirst(ActivePrimeContainer first) { 64 this.first = first; 65 } 66 67 68 public void sleep(boolean sleep) { 69 this.sleep = sleep; 70 } 71 72 73 74 public void runActivity(Body b) { 75 Service service = new Service(b); 76 while (b.isActive()) { 77 while (service.hasRequestToServe()) service.serveOldest(); if (pause || sleep) { 79 try { 80 Thread.sleep(100); 81 } catch (InterruptedException ex) {} 82 } else if (first != null) { 83 logger.info(" Testing numbers from "+currentNumber+" to "+(currentNumber+98)); 84 for (int i = 0; i < 100; i ++) { first.tryModulo(currentNumber); 86 currentNumber += 2; 87 } 88 } 89 } 90 } 91 92 93 public void pause(boolean p) { 94 pause = p; 95 } 96 97 } 98 | Popular Tags |