1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.jetspeed.aggregator.impl; |
19 |
|
|
20 |
|
import java.util.Iterator; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import javax.portlet.UnavailableException; |
24 |
|
import javax.servlet.http.HttpServletRequest; |
25 |
|
import javax.servlet.http.HttpServletResponse; |
26 |
|
|
27 |
|
import org.apache.commons.logging.Log; |
28 |
|
import org.apache.commons.logging.LogFactory; |
29 |
|
import org.apache.jetspeed.PortalReservedParameters; |
30 |
|
import org.apache.jetspeed.aggregator.ContentDispatcherCtrl; |
31 |
|
import org.apache.jetspeed.aggregator.CurrentWorkerContext; |
32 |
|
import org.apache.jetspeed.aggregator.PortletContent; |
33 |
|
import org.apache.jetspeed.aggregator.PortletRenderer; |
34 |
|
import org.apache.jetspeed.aggregator.PortletTrackingManager; |
35 |
|
import org.apache.jetspeed.aggregator.RenderingJob; |
36 |
|
import org.apache.jetspeed.aggregator.Worker; |
37 |
|
import org.apache.jetspeed.components.portletentity.PortletEntityImpl; |
38 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletEntity; |
39 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
40 |
|
import org.apache.jetspeed.request.RequestContext; |
41 |
|
import org.apache.jetspeed.statistics.PortalStatistics; |
42 |
|
import org.apache.pluto.PortletContainer; |
43 |
|
import org.apache.pluto.om.portlet.PortletDefinition; |
44 |
|
import org.apache.pluto.om.window.PortletWindow; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
public class RenderingJobImpl implements RenderingJob |
57 |
|
{ |
58 |
|
|
59 |
0 |
protected final static Log log = LogFactory.getLog(RenderingJobImpl.class); |
60 |
|
|
61 |
|
|
62 |
0 |
protected PortletWindow window = null; |
63 |
0 |
protected HttpServletRequest request = null; |
64 |
0 |
protected HttpServletResponse response = null; |
65 |
|
|
66 |
0 |
protected PortletContainer container = null; |
67 |
0 |
protected PortletRenderer renderer = null; |
68 |
0 |
protected ContentFragment fragment = null; |
69 |
0 |
protected RequestContext requestContext = null; |
70 |
0 |
protected PortletTrackingManager portletTracking = null; |
71 |
|
|
72 |
|
protected PortletDefinition portletDefinition; |
73 |
|
protected PortletContent portletContent; |
74 |
|
protected PortalStatistics statistics; |
75 |
|
protected ContentDispatcherCtrl dispatcher; |
76 |
|
protected boolean contentIsCached; |
77 |
|
|
78 |
0 |
protected int expirationCache = 0; |
79 |
|
|
80 |
|
protected Map workerAttributes; |
81 |
|
|
82 |
0 |
protected long startTimeMillis = 0; |
83 |
|
protected long timeout; |
84 |
|
|
85 |
|
public RenderingJobImpl(PortletContainer container, |
86 |
|
PortletRenderer renderer, |
87 |
|
PortletDefinition portletDefinition, |
88 |
|
PortletContent portletContent, |
89 |
|
ContentFragment fragment, |
90 |
|
ContentDispatcherCtrl dispatcher, |
91 |
|
HttpServletRequest request, |
92 |
|
HttpServletResponse response, |
93 |
|
RequestContext requestContext, |
94 |
|
PortletWindow window, |
95 |
|
PortalStatistics statistics, |
96 |
|
int expirationCache, |
97 |
|
boolean contentIsCached) |
98 |
0 |
{ |
99 |
0 |
this.container = container; |
100 |
0 |
this.renderer = renderer; |
101 |
0 |
this.portletTracking = renderer.getPortletTrackingManager(); |
102 |
0 |
this.statistics = statistics; |
103 |
0 |
this.portletDefinition = portletDefinition; |
104 |
0 |
this.fragment = fragment; |
105 |
0 |
this.dispatcher = dispatcher; |
106 |
0 |
this.request = request; |
107 |
0 |
this.response = response; |
108 |
0 |
this.requestContext = requestContext; |
109 |
0 |
this.window = window; |
110 |
0 |
this.portletContent = portletContent; |
111 |
0 |
((MutablePortletEntity)window.getPortletEntity()).setFragment(fragment); |
112 |
0 |
this.expirationCache = expirationCache; |
113 |
0 |
this.contentIsCached = contentIsCached; |
114 |
0 |
} |
115 |
|
|
116 |
|
public RenderingJobImpl(PortletContainer container, |
117 |
|
PortletRenderer renderer, |
118 |
|
PortletDefinition portletDefinition, |
119 |
|
PortletContent portletContent, |
120 |
|
ContentFragment fragment, |
121 |
|
ContentDispatcherCtrl dispatcher, |
122 |
|
HttpServletRequest request, |
123 |
|
HttpServletResponse response, |
124 |
|
RequestContext requestContext, |
125 |
|
PortletWindow window, |
126 |
|
PortalStatistics statistics, |
127 |
|
int expirationCache, |
128 |
|
boolean contentIsCached, |
129 |
|
Map workerAttributes) |
130 |
|
{ |
131 |
0 |
this(container, renderer, portletDefinition, portletContent, fragment, dispatcher, |
132 |
|
request, response, requestContext, window, statistics, expirationCache, contentIsCached); |
133 |
0 |
this.workerAttributes = workerAttributes; |
134 |
0 |
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
public void setTimeout(long timeout) { |
140 |
0 |
this.timeout = timeout; |
141 |
0 |
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
public long getTimeout() { |
147 |
0 |
return this.timeout; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
public boolean isTimeout() { |
154 |
0 |
if ((this.timeout > 0) && (class="keyword">this.startTimeMillis > 0)) { |
155 |
0 |
return (System.currentTimeMillis() - this.startTimeMillis > class="keyword">this.timeout); |
156 |
|
} |
157 |
|
|
158 |
0 |
return false; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
public void run() |
166 |
|
{ |
167 |
|
try |
168 |
|
{ |
169 |
0 |
if (this.timeout > 0) { |
170 |
0 |
this.startTimeMillis = System.currentTimeMillis(); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
0 |
fragment.setPortletContent(portletContent); |
175 |
0 |
execute(); |
176 |
|
} |
177 |
|
finally |
178 |
|
{ |
179 |
|
|
180 |
0 |
synchronized (portletContent) |
181 |
|
{ |
182 |
0 |
log.debug("Notifying completion of rendering job for fragment " + fragment.getId()); |
183 |
0 |
portletContent.notifyAll(); |
184 |
0 |
} |
185 |
0 |
} |
186 |
0 |
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
public void execute() |
196 |
|
{ |
197 |
0 |
long start = System.currentTimeMillis(); |
198 |
0 |
boolean isParallelMode = false; |
199 |
0 |
PortletWindow curWindow = this.window; |
200 |
|
try |
201 |
|
{ |
202 |
0 |
log.debug("Rendering OID "+this.window.getId()+" "+ this.request +" "+this.response); |
203 |
|
|
204 |
|
|
205 |
0 |
if (this.workerAttributes != null) |
206 |
|
{ |
207 |
0 |
isParallelMode = (Thread.currentThread() instanceof Worker || CurrentWorkerContext.getCurrentWorkerContextUsed()); |
208 |
0 |
if (isParallelMode) |
209 |
|
{ |
210 |
0 |
Iterator itAttrNames = this.workerAttributes.keySet().iterator(); |
211 |
0 |
while (itAttrNames.hasNext()) |
212 |
|
{ |
213 |
0 |
String name = (String) itAttrNames.next(); |
214 |
0 |
CurrentWorkerContext.setAttribute(name, this.workerAttributes.get(name)); |
215 |
0 |
} |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
0 |
curWindow = (PortletWindow) |
225 |
|
CurrentWorkerContext.getAttribute(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE); |
226 |
0 |
PortletEntityImpl curEntity = (PortletEntityImpl) curWindow.getPortletEntity(); |
227 |
0 |
PortletDefinition oldPortletDefinition = curEntity.getPortletDefinition(); |
228 |
0 |
PortletDefinition curPortletDefinition = (PortletDefinition) |
229 |
|
CurrentWorkerContext.getAttribute(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE); |
230 |
|
|
231 |
0 |
if (!oldPortletDefinition.getId().equals(curPortletDefinition.getId())) { |
232 |
0 |
curEntity.setPortletDefinition(curPortletDefinition); |
233 |
|
} |
234 |
|
} |
235 |
|
} |
236 |
|
|
237 |
0 |
this.request.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment); |
238 |
0 |
this.request.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE, requestContext.getPage()); |
239 |
0 |
this.request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, requestContext); |
240 |
0 |
this.request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, requestContext.getObjects()); |
241 |
|
|
242 |
0 |
container.renderPortlet(this.window, class="keyword">this.request, class="keyword">this.response); |
243 |
0 |
this.response.flushBuffer(); |
244 |
0 |
} |
245 |
0 |
catch (Throwable t) |
246 |
|
{ |
247 |
0 |
if (t instanceof UnavailableException) |
248 |
|
{ |
249 |
|
|
250 |
0 |
log.error("Error rendering portlet OID " + curWindow.getId() + ": " + t.toString()); |
251 |
|
} |
252 |
|
else |
253 |
|
{ |
254 |
0 |
log.error("Error rendering portlet OID " + curWindow.getId(), t); |
255 |
|
} |
256 |
0 |
fragment.overrideRenderedContent(t.getMessage()); |
257 |
0 |
} |
258 |
|
finally |
259 |
|
{ |
260 |
0 |
long end = System.currentTimeMillis(); |
261 |
0 |
boolean exceededTimeout = portletTracking.exceededTimeout(end - start, window); |
262 |
0 |
if (fragment.getOverriddenContent() != null) |
263 |
0 |
portletContent.completeWithError(); |
264 |
|
else |
265 |
0 |
portletContent.complete(); |
266 |
|
|
267 |
0 |
if (isParallelMode) |
268 |
|
{ |
269 |
0 |
this.renderer.addTitleToHeader(curWindow, fragment, |
270 |
|
this.request, class="keyword">this.response, |
271 |
|
this.dispatcher, class="keyword">this.contentIsCached); |
272 |
|
|
273 |
0 |
CurrentWorkerContext.removeAllAttributes(); |
274 |
|
} |
275 |
|
|
276 |
0 |
if (fragment.getType().equals(ContentFragment.PORTLET)) |
277 |
|
{ |
278 |
0 |
if (statistics != null) |
279 |
|
{ |
280 |
0 |
statistics.logPortletAccess(requestContext, fragment.getName(), PortalStatistics.HTTP_OK, end - start); |
281 |
|
} |
282 |
0 |
if (exceededTimeout) |
283 |
|
{ |
284 |
|
|
285 |
0 |
log.info("Portlet Exceeded timeout: " + curWindow.getPortletEntity().getPortletDefinition().getName() + " for window " + curWindow.getId()); |
286 |
0 |
portletTracking.incrementRenderTimeoutCount(curWindow); |
287 |
|
} |
288 |
|
else |
289 |
|
{ |
290 |
0 |
portletTracking.success(curWindow); |
291 |
|
} |
292 |
|
} |
293 |
0 |
} |
294 |
0 |
} |
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
public PortletWindow getWindow() |
305 |
|
{ |
306 |
0 |
return window; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
public PortletContent getPortletContent() |
318 |
|
{ |
319 |
0 |
return portletContent; |
320 |
|
} |
321 |
|
|
322 |
|
public PortletDefinition getPortletDefinition() |
323 |
|
{ |
324 |
0 |
return this.portletDefinition; |
325 |
|
} |
326 |
|
|
327 |
|
public HttpServletRequest getRequest() |
328 |
|
{ |
329 |
0 |
return this.request; |
330 |
|
} |
331 |
|
|
332 |
|
public HttpServletResponse getResponse() |
333 |
|
{ |
334 |
0 |
return this.response; |
335 |
|
} |
336 |
|
|
337 |
|
public ContentFragment getFragment() |
338 |
|
{ |
339 |
0 |
return this.fragment; |
340 |
|
} |
341 |
|
|
342 |
|
public RequestContext getRequestContext() |
343 |
|
{ |
344 |
0 |
return this.requestContext; |
345 |
|
} |
346 |
|
|
347 |
|
public int getExpirationCache() |
348 |
|
{ |
349 |
0 |
return this.expirationCache; |
350 |
|
} |
351 |
|
|
352 |
|
public ContentDispatcherCtrl getDispatcher() |
353 |
|
{ |
354 |
0 |
return this.dispatcher; |
355 |
|
} |
356 |
|
|
357 |
|
public boolean isContentCached() { |
358 |
0 |
return this.contentIsCached; |
359 |
|
} |
360 |
|
} |