Source Code Cross Referenced for RequestResponseFactoryImpl.java in  » Portal » Open-Portal » com » sun » portal » portletappengine » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.portletappengine.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2005 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject 
004:         * to license terms. Federal Acquisitions: 
005:         * Commercial Software -- Government Users 
006:         * Subject to Standard License Terms and 
007:         * Conditions. 
008:         * 
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
010:         * are trademarks or registered trademarks of Sun Microsystems, 
011:         * Inc. in the United States and other countries. 
012:         */
013:        package com.sun.portal.portletappengine.impl;
014:
015:        import com.sun.portal.log.common.PortalLogger;
016:        import com.sun.portal.portlet.impl.ActionRequestPool;
017:        import com.sun.portal.portlet.impl.ActionResponsePool;
018:        import com.sun.portal.portlet.impl.EventRequestPool;
019:        import com.sun.portal.portlet.impl.EventResponsePool;
020:        import com.sun.portal.portlet.impl.RenderRequestPool;
021:        import com.sun.portal.portlet.impl.RenderResponsePool;
022:        import com.sun.portal.portletappengine.RequestResponseFactory;
023:        import com.sun.portal.portletappengine.ipc.EventRequest;
024:        import com.sun.portal.portletappengine.ipc.EventResponse;
025:        import com.sun.portal.portletcontainercommon.PortletContainerActionRequest;
026:        import com.sun.portal.portletcontainercommon.PortletContainerActionResponse;
027:        import com.sun.portal.portletcontainercommon.PortletContainerEventRequest;
028:        import com.sun.portal.portletcontainercommon.PortletContainerEventResponse;
029:        import com.sun.portal.portletcontainercommon.PortletContainerRenderRequest;
030:        import com.sun.portal.portletcontainercommon.PortletContainerRenderResponse;
031:        import com.sun.portal.portletcontainercommon.descriptor.PortletDescriptor;
032:
033:        import javax.portlet.ActionRequest;
034:        import javax.portlet.ActionResponse;
035:        import javax.portlet.PortalContext;
036:        import javax.portlet.PortletContext;
037:        import javax.portlet.RenderRequest;
038:        import javax.portlet.RenderResponse;
039:        import javax.servlet.ServletContext;
040:        import javax.servlet.http.HttpServletRequest;
041:        import javax.servlet.http.HttpServletResponse;
042:        import java.io.ByteArrayOutputStream;
043:        import java.io.StringWriter;
044:        import java.util.logging.Level;
045:        import java.util.logging.Logger;
046:
047:        /**
048:         * The request and response factory is responsible for generating the 
049:         * Portlet request and response objects for the Portlet Application Servlet 
050:         * Engine. 
051:         * <P>
052:         * Object pooling is used in order to optimize the process and avoid messive 
053:         * generation of objects.There are 4 pools the request and response factory
054:         * maintains:
055:         * <UL>
056:         *   <LI>Portlet request pool
057:         *   <LI>Action response pool
058:         *   <LI>Portlet response pool
059:         * </UL>
060:         * <P>
061:         * The get**() methods are used to get a reusable object from the pools.
062:         * <P>
063:         * The release**() methods are used to release objects back to the pools.
064:         * Clients of this class are responsible for releasing the corresponding
065:         * objects by calling these methods.
066:         **/
067:        public class RequestResponseFactoryImpl implements 
068:                RequestResponseFactory {
069:
070:            // Property names for req/res factory object in servlet context
071:
072:            public static final String MIN_SIZE = "minSizeParam";
073:            public static final String MAX_SIZE = "maxSizeParam";
074:            public static final String PARTITION = "partitionParam";
075:
076:            private ActionRequestPool _actionRequestPool;
077:            private RenderRequestPool _renderRequestPool;
078:            private ActionResponsePool _actionResponsePool;
079:            private RenderResponsePool _renderResponsePool;
080:            private static Logger _logger = PortalLogger
081:                    .getLogger(RequestResponseFactoryImpl.class);
082:
083:            private EventRequestPool eventRequestPool;
084:            private EventResponsePool eventResponsePool;
085:            private ServletContext sc = null;
086:            //
087:            // Request and response pools are initialized to size 0. 
088:            // items are added to to the pool as they are used
089:            // and returned. The pools are allowed to expand
090:            // to a very large size.
091:            //
092:            // We always let the pools offer instances beyond the
093:            // max pool size.
094:            //
095:            static private final int DEFAULT_MIN_SIZE = 0;
096:            static private final int DEFAULT_MAX_SIZE = 200;
097:            static private final int DEFAULT_PARTITION_SIZE = 10;
098:
099:            static private final int ACTION_REQUEST = 1;
100:            static private final int RENDER_REQUEST = 2;
101:            static private final int ACTION_RESPONSE = 3;
102:            static private final int RENDER_RESPONSE = 4;
103:
104:            static private final int EVENT_REQUEST = 5;
105:            static private final int EVENT_RESPONSE = 6;
106:
107:            /**
108:             * Initializes the global variables.
109:             * 
110:             * @param context The servlet context
111:             */
112:            public RequestResponseFactoryImpl(ServletContext context) {
113:                sc = context;
114:                String min = context.getInitParameter(
115:                        REQUEST_RESPONSE_FACTORY_PREFIX + "." + MIN_SIZE)
116:                        .trim();
117:
118:                String max = context.getInitParameter(
119:                        REQUEST_RESPONSE_FACTORY_PREFIX + "." + MAX_SIZE)
120:                        .trim();
121:
122:                String partition = context.getInitParameter(
123:                        REQUEST_RESPONSE_FACTORY_PREFIX + "." + PARTITION)
124:                        .trim();
125:
126:                _logger.log(Level.FINEST, "PSPL_PAECSPPAI0001", min);
127:                _logger.log(Level.FINEST, "PSPL_PAECSPPAI0002", max);
128:                _logger.log(Level.FINEST, "PSPL_PAECSPPAI0003", partition);
129:                initRequestResponsePool(context, Integer.parseInt(min), Integer
130:                        .parseInt(max), Integer.parseInt(partition),
131:                        ACTION_REQUEST);
132:                initRequestResponsePool(context, Integer.parseInt(min), Integer
133:                        .parseInt(max), Integer.parseInt(partition),
134:                        RENDER_REQUEST);
135:                initRequestResponsePool(context, Integer.parseInt(min), Integer
136:                        .parseInt(max), Integer.parseInt(partition),
137:                        ACTION_RESPONSE);
138:                initRequestResponsePool(context, Integer.parseInt(min), Integer
139:                        .parseInt(max), Integer.parseInt(partition),
140:                        RENDER_RESPONSE);
141:
142:                initRequestResponsePool(context, Integer.parseInt(min), Integer
143:                        .parseInt(max), Integer.parseInt(partition),
144:                        EVENT_REQUEST);
145:
146:                initRequestResponsePool(context, Integer.parseInt(min), Integer
147:                        .parseInt(max), Integer.parseInt(partition),
148:                        EVENT_RESPONSE);
149:                context.setAttribute("_actionRequestPool", _actionRequestPool);
150:                context.setAttribute("_renderRequestPool", _renderRequestPool);
151:                context
152:                        .setAttribute("_actionResponsePool",
153:                                _actionResponsePool);
154:                context
155:                        .setAttribute("_renderResponsePool",
156:                                _renderResponsePool);
157:                context.setAttribute("eventRequestPool", eventRequestPool);
158:                context.setAttribute("eventResponsePool", eventResponsePool);
159:            }
160:
161:            /**
162:             * Gets a reusable action request object from the pool.
163:             *
164:             * @param req The http servlet request object
165:             * @param res The http servlet response object
166:             *
167:             * @return <code>ActionRequest</code>
168:             */
169:            public ActionRequest getActionRequest(HttpServletRequest req,
170:                    HttpServletResponse res,
171:                    PortletContainerActionRequest pContReq,
172:                    PortletContainerActionResponse pContRes,
173:                    PortletContext context, PortalContext portalContext,
174:                    PortletDescriptor pDescriptor, StringWriter writer) {
175:                if (_actionRequestPool == null) {
176:                    _actionRequestPool = (ActionRequestPool) sc
177:                            .getAttribute("_actionRequestPool");
178:                }
179:                return _actionRequestPool.obtainObject(req, res, pContReq,
180:                        pContRes, context, portalContext, pDescriptor, writer);
181:            }
182:
183:            /**
184:             * Gets a reusable render request object from the pool.
185:             *
186:             * @param req The http servlet request object
187:             * @param res The http servlet response object
188:             *
189:             * @return <code>RenderRequest</code>
190:             */
191:            public RenderRequest getRenderRequest(HttpServletRequest req,
192:                    HttpServletResponse res,
193:                    PortletContainerRenderRequest pContReq,
194:                    PortletContainerRenderResponse pContRes,
195:                    PortletContext context, PortalContext portalContext,
196:                    PortletDescriptor pDescriptor) {
197:                if (_renderRequestPool == null) {
198:                    _renderRequestPool = (RenderRequestPool) sc
199:                            .getAttribute("_renderRequestPool");
200:                }
201:                return _renderRequestPool.obtainObject(req, res, pContReq,
202:                        pContRes, context, portalContext, pDescriptor);
203:            }
204:
205:            /**
206:             * Gets a reusable action response object from the pool.
207:             *
208:             * @return <code>ActionResponse</code>
209:             */
210:            public ActionResponse getActionResponse(HttpServletRequest req,
211:                    HttpServletResponse res, ActionRequest aReq,
212:                    PortletContainerActionRequest pContReq,
213:                    PortletContainerActionResponse pContRes) {
214:                if (_actionResponsePool == null) {
215:                    _actionResponsePool = (ActionResponsePool) sc
216:                            .getAttribute("_actionResponsePool");
217:                }
218:                return _actionResponsePool.obtainObject(req, res, aReq,
219:                        pContReq, pContRes);
220:
221:            }
222:
223:            /**
224:             * Gets a reusable portlet response object from the pool.
225:             *
226:             * @param res The http servlet response object
227:             * @param writer The <code>StringWriter</code> that will be used as the
228:             * writer when <code>RenderResponse.getWriter()</code> is called.
229:             * 
230:             * @return <code>RenderResponse</code>
231:             */
232:            public RenderResponse getRenderResponse(HttpServletRequest req,
233:                    HttpServletResponse res, RenderRequest rReq,
234:                    PortletContainerRenderRequest pContReq,
235:                    PortletContainerRenderResponse pContRes,
236:                    StringWriter writer, ByteArrayOutputStream output,
237:                    PortletDescriptor pDescriptor) {
238:                if (_renderResponsePool == null) {
239:                    _renderResponsePool = (RenderResponsePool) sc
240:                            .getAttribute("_renderResponsePool");
241:                }
242:                return _renderResponsePool.obtainObject(req, res, rReq,
243:                        pContReq, pContRes, writer, output, pDescriptor);
244:            }
245:
246:            /**
247:             * Releases the action request object back to the pool.
248:             *
249:             * @param actionReq The <code>ActionRequest</code>
250:             */
251:            public void releaseActionRequest(ActionRequest actionReq) {
252:                _actionRequestPool.releaseObject(actionReq);
253:            }
254:
255:            /**
256:             * Releases the render request object back to the pool.
257:             *
258:             * @param renderReq The <code>RenderRequest</code>
259:             */
260:            public void releaseRenderRequest(RenderRequest renderReq) {
261:                _renderRequestPool.releaseObject(renderReq);
262:            }
263:
264:            /**
265:             * Releases the action response object back to the pool.
266:             *
267:             * @param actionRes The <code>ActionResponse</code>
268:             */
269:            public void releaseActionResponse(ActionResponse actionRes) {
270:                _actionResponsePool.releaseObject(actionRes);
271:            }
272:
273:            /**
274:             * Releases the portlet response object back to the pool.
275:             *
276:             * @param portletRes The <code>RenderResponse</code>
277:             */
278:            public void releaseRenderResponse(RenderResponse portletRes) {
279:                _renderResponsePool.releaseObject(portletRes);
280:            }
281:
282:            public EventRequest getEventRequest(HttpServletRequest req,
283:                    HttpServletResponse res,
284:                    PortletContainerEventRequest pceRequest,
285:                    PortletContainerEventResponse pceResponse,
286:                    PortletContext context, PortalContext portalContext,
287:                    PortletDescriptor pDescriptor) {
288:
289:                return eventRequestPool.obtainObject(req, res, pceRequest,
290:                        pceResponse, context, portalContext, pDescriptor);
291:            }
292:
293:            public EventResponse getEventResponse(
294:                    PortletContainerEventResponse pceResponse) {
295:                return eventResponsePool.obtainObject(pceResponse);
296:            }
297:
298:            public void releaseEventRequest(EventRequest ereq) {
299:                eventRequestPool.releaseObject(ereq);
300:            }
301:
302:            public void releaseEventResponse(EventResponse eres) {
303:                eventResponsePool.releaseObject(eres);
304:            }
305:
306:            /**
307:             * Initializes the portlet request pool.
308:             */
309:            private void initRequestResponsePool(ServletContext context,
310:                    int minSize, int maxSize, int partition, int type) {
311:
312:                if (minSize < 0) {
313:                    _logger.log(Level.FINER, "PSPL_PAECSPPAI0004", new Integer(
314:                            DEFAULT_MIN_SIZE));
315:                    minSize = DEFAULT_MIN_SIZE;
316:                }
317:                if (maxSize < 0) {
318:                    _logger.log(Level.FINER, "PSPL_PAECSPPAI0005", new Integer(
319:                            DEFAULT_MAX_SIZE));
320:                    maxSize = DEFAULT_MAX_SIZE;
321:                }
322:                if (partition < 0) {
323:                    _logger.log(Level.FINER, "PSPL_PAECSPPAI0006", new Integer(
324:                            DEFAULT_PARTITION_SIZE));
325:                    partition = DEFAULT_PARTITION_SIZE;
326:                }
327:                if (minSize > maxSize) {
328:                    _logger.log(Level.FINER, "PSPL_PAECSPPAI0007", new Integer(
329:                            DEFAULT_MAX_SIZE));
330:                    minSize = DEFAULT_MAX_SIZE;
331:                }
332:                if (partition > maxSize) {
333:                    _logger.log(Level.FINER, "PSPL_PAECSPPAI0008", new Integer(
334:                            DEFAULT_MAX_SIZE));
335:                    partition = DEFAULT_MAX_SIZE;
336:                }
337:
338:                switch (type) {
339:
340:                case ACTION_REQUEST:
341:                    _actionRequestPool = new ActionRequestPool(context,
342:                            minSize, maxSize, true, partition, _logger);
343:                    break;
344:
345:                case RENDER_REQUEST:
346:                    _renderRequestPool = new RenderRequestPool(context,
347:                            minSize, maxSize, true, partition, _logger);
348:                    break;
349:
350:                case ACTION_RESPONSE:
351:                    _actionResponsePool = new ActionResponsePool(minSize,
352:                            maxSize, true, partition, _logger);
353:                    break;
354:
355:                case RENDER_RESPONSE:
356:                    _renderResponsePool = new RenderResponsePool(minSize,
357:                            maxSize, true, partition, _logger);
358:                case EVENT_REQUEST:
359:                    eventRequestPool = new EventRequestPool(context, minSize,
360:                            maxSize, true, partition, _logger);
361:                case EVENT_RESPONSE:
362:                    eventResponsePool = new EventResponsePool(minSize, maxSize,
363:                            true, partition, _logger);
364:
365:                    break;
366:                }
367:
368:            }
369:
370:            /**
371:             * Clears the pool objects.
372:             */
373:            public void destroy() {
374:                _actionRequestPool = null;
375:                _renderRequestPool = null;
376:                _actionResponsePool = null;
377:                _renderResponsePool = null;
378:            }
379:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.