1 33 34 package com.icesoft.faces.async.render; 35 36 import edu.emory.mathcs.backport.java.util.concurrent.ScheduledExecutorService; 37 import edu.emory.mathcs.backport.java.util.concurrent.ScheduledFuture; 38 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 56 public class IntervalRenderer extends OnDemandRenderer implements Runnable { 57 58 private static Log log = LogFactory.getLog(IntervalRenderer.class); 59 60 private long interval = 60000; 61 private boolean isStarted = false; 62 private ScheduledFuture future; 63 64 70 public long getInterval() { 71 return interval; 72 } 73 74 81 public void setInterval(long interval) { 82 this.interval = interval; 83 } 84 85 89 public void requestRender() { 90 91 if (isStarted) { 92 return; 93 } 94 95 isStarted = true; 96 97 ScheduledExecutorService scheduleService = 98 renderManager.getScheduledService(); 99 future = scheduleService.scheduleAtFixedRate(this, interval, interval, 100 TimeUnit.MILLISECONDS); 101 102 if (log.isDebugEnabled()) { 103 log.debug( 104 "interval render started: interval is " + interval + " ms"); 105 } 106 } 107 108 public void requestStop() { 109 super.requestStop(); 110 if (future != null && !future.isDone()) { 111 future.cancel(false); 112 } 113 isStarted = false; 114 } 115 116 public void run() { 117 super.requestRender(); 118 } 119 120 public void dispose() { 121 super.dispose(); 122 future = null; 123 } 124 } 125 126 | Popular Tags |