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 javax.servlet.http.HttpServletRequest;
016: import javax.servlet.http.HttpServletResponse;
017:
018: import javax.portlet.ActionRequest;
019: import javax.portlet.ActionResponse;
020:
021: import com.sun.portal.common.pool.ObjectPool;
022: import com.sun.portal.common.pool.ObjectManager;
023:
024: import java.util.logging.Logger;
025:
026: import com.sun.portal.portletcontainercommon.PortletContainerActionRequest;
027: import com.sun.portal.portletcontainercommon.PortletContainerActionResponse;
028: import com.sun.portal.log.common.PortalLogger;
029:
030: /**
031: * This class maintains reusable action response objects in a pool.
032: * <P>
033: * Clients can use the <code>obtainObject()</code> method to retrieve an
034: * action response object, and <code>releaseObject()</code> to release
035: * it back to the pool once is done with it.
036: **/
037: public class ActionResponsePool extends ObjectPool {
038:
039: private static Logger _logger = PortalLogger
040: .getLogger(ActionResponsePool.class);
041:
042: // constructor
043: private static class ActionResponsePoolManager implements
044: ObjectManager {
045:
046: public ActionResponsePoolManager(Logger logger) {
047: }
048:
049: /**
050: * Creates a new object.
051: * <P>
052: * @param param Passed in params if needed.
053: */
054: public Object createObject(Object param) {
055: ActionResponse aRes = new ActionResponseImpl();
056:
057: _logger.finest("PSPL_PAECSPPI0004");
058:
059: return aRes;
060: }
061:
062: /**
063: * Destroys an object.
064: */
065: public void destroyObject(Object o) {
066: //do nothing
067: }
068: }
069:
070: // constructor
071: public ActionResponsePool(int minSize, int maxSize,
072: boolean overflow, int partitionSize, Logger logger) {
073:
074: super (new ActionResponsePoolManager(logger), minSize, maxSize,
075: overflow, partitionSize);
076: }
077:
078: /**
079: * Obtains an action response object from the pool.
080: * <P>
081: * @return <code>ActionResponse</code>
082: */
083: public ActionResponse obtainObject(HttpServletRequest req,
084: HttpServletResponse res, ActionRequest aReq,
085: PortletContainerActionRequest pContReq,
086: PortletContainerActionResponse pContRes) {
087:
088: _logger.finest("PSPL_PAECSPPI0005");
089: ActionResponseImpl aRes = (ActionResponseImpl) (getPool()
090: .obtainObject(null));
091: aRes.init(req, res, aReq, pContReq, pContRes, _logger);
092: return aRes;
093: }
094:
095: /**
096: * Releases an object back to the pool.
097: *
098: * @param <code>ActionResponse</code>
099: */
100: public void releaseObject(ActionResponse aRes) {
101: ((ActionResponseImpl) aRes).clear();
102: getPool().releaseObject(aRes);
103:
104: _logger.finest("PSPL_PAECSPPI0006");
105: }
106: }
|