001: /*
002: * Copyright 2002 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.portlet.impl;
014:
015: import java.io.StringWriter;
016:
017: import javax.servlet.ServletContext;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.PortletContext;
024: import javax.portlet.PortalContext;
025:
026: import com.sun.portal.common.pool.ObjectPool;
027: import com.sun.portal.common.pool.ObjectManager;
028:
029: import java.util.logging.Logger;
030: import java.util.logging.Level;
031:
032: import com.sun.portal.portletcontainercommon.PortletContainerActionRequest;
033: import com.sun.portal.portletcontainercommon.PortletContainerActionResponse;
034:
035: import com.sun.portal.portletcontainercommon.descriptor.PortletDescriptor;
036: import com.sun.portal.log.common.PortalLogger;
037:
038: /**
039: * This class maintains reusable portlet request objects in a pool.
040: * <P>
041: * Clients can use the <code>obtainObject()</code> method to retrieve an
042: * portlet request object, and <code>releaseObject()</code> to release
043: * it back to the pool once is done with it.
044: **/
045: public class ActionRequestPool extends ObjectPool {
046:
047: private static Logger _logger = PortalLogger
048: .getLogger(ActionRequestPool.class);
049:
050: private static class ActionRequestPoolManager implements
051: ObjectManager {
052:
053: //SecurityManager _securityManager = null;
054:
055: // constructor
056: public ActionRequestPoolManager(ServletContext context,
057: Logger logger) {
058: //_logger = logger;
059: }
060:
061: /**
062: * Creates a new object.
063: * <P>
064: * @param param Passed in params if needed.
065: */
066: public Object createObject(Object param) {
067: ActionRequestImpl aReq = new ActionRequestImpl();
068: _logger.finest("PSPL_PAECSPPI0001");
069:
070: return aReq;
071: }
072:
073: /**
074: * Destroys an object.
075: */
076: public void destroyObject(Object o) {
077: //do nothing
078: }
079: }
080:
081: // constructor
082: public ActionRequestPool(ServletContext context, int minSize,
083: int maxSize, boolean overflow, int partitionSize,
084: Logger logger) {
085:
086: super (new ActionRequestPoolManager(context, logger), minSize,
087: maxSize, overflow, partitionSize);
088: }
089:
090: /**
091: * Obtains an portlet request object from the pool.
092: * <P>
093: * @param req The <code>HttpServletRequest</code> object
094: * @param res The <code>HttpServletResponse</code> object
095: * <P>
096: * @return <code>ActionRequest</code>
097: */
098: public ActionRequest obtainObject(HttpServletRequest req,
099: HttpServletResponse res,
100: PortletContainerActionRequest pContReq,
101: PortletContainerActionResponse pContRes,
102: PortletContext context, PortalContext portalContext,
103: PortletDescriptor pDescriptor, StringWriter writer) {
104:
105: _logger.finest("PSPL_PAECSPPI0002");
106:
107: ActionRequestImpl aReq = (ActionRequestImpl) (getPool()
108: .obtainObject(null));
109: aReq.init(req, res, pContReq, pContRes, context, portalContext,
110: pDescriptor, writer, _logger);
111: return (ActionRequestImpl) aReq;
112: }
113:
114: /**
115: * Releases an object back to the pool.
116: *
117: * @param <code>ActionRequest</code>
118: */
119: public void releaseObject(ActionRequest aReq) {
120: ((ActionRequestImpl) aReq).clear();
121: getPool().releaseObject(aReq);
122:
123: _logger.finest("PSPL_PAECSPPI0003");
124: }
125: }
|