1 package org.objectweb.proactive.examples.eratosthenes; 2 3 import org.apache.log4j.Logger; 4 5 35 36 40 public class ConsolePrimeOutputListener implements PrimeOutputListener, java.io.Serializable { 41 42 static Logger logger = Logger.getLogger(ConsolePrimeOutputListener.class.getName()); 43 private long startTime; 44 private int numberCounter; 45 46 49 public ConsolePrimeOutputListener() { 50 super(); 51 } 52 53 public void newPrimeNumberFound(long n) { 54 numberCounter ++; 55 if (startTime == 0) startTime = System.currentTimeMillis(); 56 String time = Long.toString((System.currentTimeMillis() - startTime) / 1000); 57 String counter = Integer.toString(numberCounter); 58 StringBuffer line = new StringBuffer (50); 59 line.append(" "); 60 line.append("Prime number "); 61 for (int i = counter.length(); i < 6; i ++) line.append(' '); 62 line.append('#'); 63 line.append(counter); 64 line.append(" found with value "); 65 line.append(n); 66 line.append("\t ("); 67 for (int i = time.length(); i < 6; i ++) line.append('0'); 68 line.append(time); 69 line.append("s)\n"); 70 logger.info(line); 71 } 72 73 } 74 | Popular Tags |