001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.async.render;
035:
036: import edu.emory.mathcs.backport.java.util.concurrent.ScheduledExecutorService;
037: import edu.emory.mathcs.backport.java.util.concurrent.ScheduledFuture;
038: import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041:
042: /**
043: * The DelayRenderer is type of {@link GroupAsyncRenderer} that is used to
044: * request a single render pass on a group of Renderables. The render pass is
045: * executed after a specified time delay. DelayRenderers can be created and
046: * used directly but it is recommended to use the RenderManager to create and
047: * managed named render groups.
048: *
049: * @author ICEsoft Technologies, Inc.
050: * @see RenderManager, GroupAsyncRenderer
051: */
052: public class DelayRenderer extends OnDemandRenderer implements Runnable {
053:
054: private static Log log = LogFactory.getLog(IntervalRenderer.class);
055: private ScheduledFuture future;
056:
057: /**
058: * The delay value to use before request a render pass on the group.
059: */
060: private long delay = 60000;
061:
062: public long getDelay() {
063: return delay;
064: }
065:
066: public void setDelay(long delay) {
067: this .delay = delay;
068: }
069:
070: /**
071: * Schedules a render pass on the group of Renderables using the delay value
072: * specified using {@link #setDelay}. If a delay value was not
073: * explicitly set, then the default delay value (60000 ms) is used.
074: */
075: public void requestRender() {
076:
077: ScheduledExecutorService scheduleService = renderManager
078: .getScheduledService();
079: future = scheduleService.schedule(this , delay,
080: TimeUnit.MILLISECONDS);
081:
082: if (log.isDebugEnabled()) {
083: log
084: .debug("delay render started: delay is " + delay
085: + " ms");
086: }
087: }
088:
089: public void requestStop() {
090: super .requestStop();
091: if (future != null && !future.isDone()) {
092: future.cancel(false);
093: }
094: }
095:
096: public void run() {
097: super .requestRender();
098: }
099:
100: public void dispose() {
101: super.dispose();
102: future = null;
103: }
104: }
|