1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.aggregator.impl; |
18 |
|
|
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.Collections; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import org.apache.jetspeed.aggregator.PortletTrackingManager; |
27 |
|
import org.apache.jetspeed.aggregator.RenderTrackable; |
28 |
|
import org.apache.jetspeed.container.window.PortletWindowAccessor; |
29 |
|
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; |
30 |
|
import org.apache.pluto.om.window.PortletWindow; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
public class PortletTrackingManagerImpl implements PortletTrackingManager |
39 |
|
{ |
40 |
0 |
protected Map outOfService = Collections.synchronizedMap(new HashMap()); |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
protected long defaultPortletTimeout; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
protected int outOfServiceLimit; |
54 |
|
|
55 |
|
protected PortletWindowAccessor windowAccessor; |
56 |
|
|
57 |
|
public PortletTrackingManagerImpl(PortletWindowAccessor windowAccessor, long defaultPortletTimeout, int outOfServiceLimit) |
58 |
0 |
{ |
59 |
0 |
this.windowAccessor = windowAccessor; |
60 |
0 |
this.defaultPortletTimeout = defaultPortletTimeout; |
61 |
0 |
this.outOfServiceLimit = outOfServiceLimit; |
62 |
0 |
} |
63 |
|
|
64 |
|
public long getDefaultPortletTimeout() |
65 |
|
{ |
66 |
0 |
return this.defaultPortletTimeout; |
67 |
|
} |
68 |
|
|
69 |
|
public boolean exceededTimeout(long renderTime, PortletWindow window) |
70 |
|
{ |
71 |
0 |
RenderTrackable trackInfo = (RenderTrackable)window.getPortletEntity(); |
72 |
0 |
long defaultTimeout = this.getDefaultPortletTimeout(); |
73 |
0 |
if (trackInfo.getExpiration() > 0) |
74 |
|
{ |
75 |
0 |
return (renderTime > trackInfo.getExpiration()); |
76 |
|
} |
77 |
0 |
else if (defaultTimeout > 0) |
78 |
|
{ |
79 |
0 |
return (renderTime > defaultTimeout); |
80 |
|
} |
81 |
0 |
return false; |
82 |
|
} |
83 |
|
|
84 |
|
public boolean isOutOfService(PortletWindow window) |
85 |
|
{ |
86 |
0 |
RenderTrackable trackable = (RenderTrackable)window.getPortletEntity(); |
87 |
0 |
if (trackable.getRenderTimeoutCount() > this.outOfServiceLimit) |
88 |
|
{ |
89 |
0 |
return true; |
90 |
|
} |
91 |
0 |
return false; |
92 |
|
} |
93 |
|
|
94 |
|
public int getOutOfServiceLimit() |
95 |
|
{ |
96 |
0 |
return this.outOfServiceLimit; |
97 |
|
} |
98 |
|
|
99 |
|
public void incrementRenderTimeoutCount(PortletWindow window) |
100 |
|
{ |
101 |
0 |
RenderTrackable trackable = (RenderTrackable)window.getPortletEntity(); |
102 |
0 |
trackable.incrementRenderTimeoutCount(); |
103 |
0 |
} |
104 |
|
|
105 |
|
public void success(PortletWindow window) |
106 |
|
{ |
107 |
0 |
RenderTrackable trackable = (RenderTrackable)window.getPortletEntity(); |
108 |
0 |
trackable.success(); |
109 |
0 |
} |
110 |
|
|
111 |
|
public void setExpiration(PortletWindow window, long expiration) |
112 |
|
{ |
113 |
0 |
RenderTrackable trackable = (RenderTrackable)window.getPortletEntity(); |
114 |
0 |
trackable.setExpiration(expiration); |
115 |
0 |
} |
116 |
|
|
117 |
|
public void takeOutOfService(PortletWindow window) |
118 |
|
{ |
119 |
0 |
RenderTrackable trackable = (RenderTrackable)window.getPortletEntity(); |
120 |
0 |
trackable.setRenderTimeoutCount((int)this.defaultPortletTimeout + 1); |
121 |
0 |
} |
122 |
|
|
123 |
|
public void putIntoService(PortletWindow window) |
124 |
|
{ |
125 |
0 |
RenderTrackable trackable = (RenderTrackable)window.getPortletEntity(); |
126 |
0 |
trackable.setRenderTimeoutCount(0); |
127 |
0 |
} |
128 |
|
|
129 |
|
public void putIntoService(List fullPortletNames) |
130 |
|
{ |
131 |
0 |
Iterator windows = this.windowAccessor.getPortletWindows().iterator(); |
132 |
0 |
while (windows.hasNext()) |
133 |
|
{ |
134 |
0 |
PortletWindow window = (PortletWindow)windows.next(); |
135 |
0 |
PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition(); |
136 |
0 |
for (int ix = 0; ix < fullPortletNames.size(); ix++) |
137 |
|
{ |
138 |
0 |
if (pd.getUniqueName().equals(fullPortletNames.get(ix))) |
139 |
|
{ |
140 |
0 |
putIntoService(window); |
141 |
|
} |
142 |
|
} |
143 |
0 |
} |
144 |
0 |
} |
145 |
|
|
146 |
|
public List getOutOfServiceList(String fullPortletName) |
147 |
|
{ |
148 |
0 |
List outs = new ArrayList(); |
149 |
0 |
Iterator windows = this.windowAccessor.getPortletWindows().iterator(); |
150 |
0 |
while (windows.hasNext()) |
151 |
|
{ |
152 |
0 |
PortletWindow window = (PortletWindow)windows.next(); |
153 |
0 |
PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition(); |
154 |
0 |
if (pd.getUniqueName().equals(fullPortletName) && isOutOfService(window)) |
155 |
|
{ |
156 |
0 |
outs.add(window); |
157 |
|
} |
158 |
0 |
} |
159 |
0 |
return outs; |
160 |
|
} |
161 |
|
|
162 |
|
public List getOutOfServiceList() |
163 |
|
{ |
164 |
0 |
List outs = new ArrayList(); |
165 |
0 |
Iterator windows = this.windowAccessor.getPortletWindows().iterator(); |
166 |
0 |
while (windows.hasNext()) |
167 |
|
{ |
168 |
0 |
PortletWindow window = (PortletWindow)windows.next(); |
169 |
0 |
if (isOutOfService(window)) |
170 |
|
{ |
171 |
0 |
outs.add(window); |
172 |
|
} |
173 |
0 |
} |
174 |
0 |
return outs; |
175 |
|
} |
176 |
|
} |