01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.channels.error;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.jasig.portal.ChannelRuntimeData;
11: import org.jasig.portal.ChannelRuntimeProperties;
12: import org.jasig.portal.ChannelStaticData;
13: import org.jasig.portal.GeneralRenderingException;
14: import org.jasig.portal.IChannel;
15: import org.jasig.portal.PortalEvent;
16: import org.jasig.portal.PortalException;
17: import org.xml.sax.ContentHandler;
18:
19: /**
20: * A channel which exists to demonstrate timing out on render.
21: * This channel will hang for 30 seconds on rendering. This will likely be greater
22: * than the configured channel timeout and so the channel rendering framework
23: * should fall back on using CError to render an error message. This channel
24: * exists to facilitate demonstrating that fallback behavior.
25: * @author andrew.petro@yale.edu
26: * @version $Revision: 35593 $ $Date: 2005-04-17 13:54:14 -0700 (Sun, 17 Apr 2005) $
27: * @since uPortal 2.5
28: */
29: public final class CTimeout implements IChannel {
30:
31: protected final Log log = LogFactory.getLog(getClass());
32:
33: /**
34: * Do-nothing constructor
35: */
36: public CTimeout() {
37: this .log.trace("CThrower()");
38: // nothing to do
39: }
40:
41: public ChannelRuntimeProperties getRuntimeProperties() {
42: this .log.trace("getRuntimeProperties()");
43: return new ChannelRuntimeProperties();
44: }
45:
46: public void receiveEvent(PortalEvent ev) {
47: if (this .log.isTraceEnabled())
48: this .log.trace("received event [" + ev + "]");
49: // no events for this channel
50: }
51:
52: public void setStaticData(ChannelStaticData sd) {
53: if (this .log.isTraceEnabled())
54: this .log.trace("setStaticData(" + sd + ")");
55: }
56:
57: public void setRuntimeData(ChannelRuntimeData rd) {
58: if (this .log.isTraceEnabled())
59: this .log.trace("setRuntimeData(" + rd + ")");
60:
61: // TODO this channel could get timeout configuration from static or
62: // runtime data
63: }
64:
65: public void renderXML(ContentHandler out) throws PortalException {
66:
67: long startRendering = System.currentTimeMillis();
68:
69: // do something that takes a long time
70:
71: Object dummyLock = new Object();
72:
73: synchronized (dummyLock) {
74: try {
75: // wait 30 seconds
76: dummyLock.wait(30000);
77: } catch (InterruptedException e) {
78: long interrupted = System.currentTimeMillis();
79:
80: long elapsedMillis = interrupted - startRendering;
81:
82: // we're a test channel, let's let the developer know we were interrupted
83: throw new GeneralRenderingException(
84: "CTimeout interrupted after " + elapsedMillis
85: + " milliseconds.");
86: }
87: }
88:
89: long returningFromRendering = System.currentTimeMillis();
90: log.trace("CTimeout returning from rendering after "
91: + (returningFromRendering - startRendering)
92: + " milliseconds.");
93: }
94:
95: }
|