1 package org.objectweb.proactive.examples.eratosthenes; 2 3 import org.apache.log4j.Logger; 4 5 35 36 41 public class PrimeNumberImpl implements PrimeNumber, java.io.Serializable { 42 43 static Logger logger = Logger.getLogger(PrimeNumberImpl.class.getName()); 44 private long value; 45 private PrimeNumber next; 46 private ActivePrimeContainer container; 47 48 50 private long nextValue; 51 52 55 public PrimeNumberImpl(ActivePrimeContainer container, long value) { 56 this.container = container; 57 this.value = value; 58 } 59 60 67 public void tryModulo(long n) { 68 if (n % value != 0) { 69 if (next == null) { 70 nextValue = n; 71 next = container.newPrimeNumber(n); 72 } else { 73 if (n <= nextValue) { 74 logger.fatal("Requests arrived out of order. Should never occur when using FIFO serving."); 75 System.exit(2); 76 } 77 next.tryModulo(n); 78 } 79 } 80 } 81 82 85 public long getValue() { 86 return value; 87 } 88 89 } 90 | Popular Tags |