1 4 package com.openedit.archive.cumulus; 5 6 import java.util.Timer ; 7 import java.util.TimerTask ; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 public class ImageConvertQueue 13 { 14 protected Timer fieldQueue; 15 private static final Log log = LogFactory.getLog(ImageConvertQueue.class); 16 17 protected int fieldCount; 18 protected boolean fieldHasHitMax; 19 20 21 public Timer getQueue() 22 { 23 if( fieldQueue == null) 24 { 25 fieldQueue = new Timer (true); 26 } 27 return fieldQueue; 28 } 29 30 public void setQueue(Timer inQueue) 31 { 32 fieldQueue = inQueue; 33 } 34 protected void reduce() 35 { 36 fieldCount--; 37 if( fieldHasHitMax && fieldCount == 0) 38 { 39 log.info("Image Queue is now empty"); 40 fieldHasHitMax = false; 41 } 42 43 } 44 protected void increase() 45 { 46 fieldCount++; 47 } 48 49 public void add(final Runnable inTask) 50 { 51 if(( fieldCount > 300)) { 53 fieldHasHitMax = true; 54 inTask.run(); 55 return; 56 } 57 increase(); 58 log.debug("Adding " + inTask); 59 TimerTask task = new TimerTask () 60 { 61 public void run() 62 { 63 try 64 { 65 reduce(); 66 log.debug("Running " + inTask); 67 inTask.run(); 68 } 69 catch ( Throwable ex) 70 { 71 log.error("Image convert failed " + ex.getMessage() + " on " + inTask ); 72 } 73 } 74 }; 75 getQueue().schedule(task, 0); 76 } 77 } 78 | Popular Tags |