1 33 34 package com.icesoft.applications.faces.auctionMonitor.beans; 35 36 import com.icesoft.faces.async.render.IntervalRenderer; 37 import com.icesoft.faces.async.render.RenderManager; 38 import com.icesoft.faces.async.render.Renderable; 39 import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState; 40 import com.icesoft.faces.webapp.xmlhttp.RenderingException; 41 import com.icesoft.faces.context.ViewListener; 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 45 52 public class ClockBean implements Renderable, ViewListener { 53 private static Log log = LogFactory.getLog(ClockBean.class); 54 private boolean isRunning = false; 55 private IntervalRenderer clock; 56 private int pollInterval = 1000; 57 private String autoLoad = " "; 58 private PersistentFacesState state = null; 59 60 private static final String AUTO_LOAD = "ClockBean-Loaded"; 61 private static final String INTERVAL_RENDERER_GROUP = "clock"; 62 63 public ClockBean() { 64 state = PersistentFacesState.getInstance(); 65 state.addViewListener(this); 66 AuctionBean.incrementUsers(); 67 } 68 69 public String getAutoLoad() { 70 if (" ".equals(autoLoad)) { 71 autoLoad = AUTO_LOAD; 72 } 73 return autoLoad; 74 } 75 76 public void setPollInterval(int interval) { 77 pollInterval = interval; 78 } 79 80 public int getPollInterval() { 81 return pollInterval; 82 } 83 84 public boolean isRunning() { 85 return isRunning; 86 } 87 88 public void setRenderManager(RenderManager manager) { 89 if (manager != null) { 90 clock = manager.getIntervalRenderer(INTERVAL_RENDERER_GROUP + "-" + System.currentTimeMillis() + "-" + this); 91 if (clock.getInterval() != pollInterval) { 92 clock.setInterval(pollInterval); 93 } 94 clock.add(this); 95 clock.requestRender(); 96 isRunning = true; 97 } 98 } 99 100 103 public RenderManager getRenderManager() { 104 return null; 105 } 106 107 public PersistentFacesState getState() { 108 return state; 109 } 110 111 public void renderingException(RenderingException renderingException) { 112 if (log.isDebugEnabled()) { 113 log.debug("Rendering exception called because of " + 114 renderingException); 115 } 116 117 performCleanup(); 118 } 119 120 protected boolean performCleanup() { 121 try{ 122 if (clock != null) { 123 clock.requestStop(); 124 clock.remove(this); 125 clock.dispose(); 126 clock = null; 127 } 128 129 isRunning = false; 130 AuctionBean.decrementUsers(); 131 132 return true; 133 }catch (Exception failedCleanup) { 134 if (log.isErrorEnabled()) { 135 log.error("Failed to cleanup a clock bean", failedCleanup); 136 } 137 } 138 139 return false; 140 } 141 142 public void viewCreated() { 143 } 144 145 public void viewDisposed() { 146 if (log.isInfoEnabled()) { 147 log.info("ViewListener of ClockBean fired for a user - cleaning up"); 148 } 149 150 performCleanup(); 151 } 152 } 153 | Popular Tags |