001: /* $Id: EventRequestPool.java,v 1.6 2006/08/03 09:58:04 dg154973 Exp $
002: * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
003: * Use is subject to license terms.
004: */
005: package com.sun.portal.portlet.impl;
006:
007: import com.sun.portal.common.pool.ObjectManager;
008: import com.sun.portal.common.pool.ObjectPool;
009: import com.sun.portal.portletappengine.ipc.EventRequest;
010: import com.sun.portal.portletcontainercommon.PortletContainerConstants;
011: import com.sun.portal.portletcontainercommon.PortletContainerEventRequest;
012: import com.sun.portal.portletcontainercommon.PortletContainerEventResponse;
013: import com.sun.portal.portletcontainercommon.descriptor.PortletDescriptor;
014:
015: import javax.servlet.ServletContext;
016: import javax.servlet.http.HttpServletRequest;
017: import javax.servlet.http.HttpServletResponse;
018: import javax.portlet.PortletContext;
019: import javax.portlet.PortalContext;
020: import java.io.ByteArrayInputStream;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: public class EventRequestPool extends ObjectPool {
025:
026: private static Logger logger = null;
027:
028: private static class EventRequestPoolManager implements
029: ObjectManager {
030:
031: //SecurityManager _securityManager = null;
032: private static Logger logger;
033:
034: // constructor
035: public EventRequestPoolManager(ServletContext context,
036: Logger logger) {
037: this .logger = logger;
038: }
039:
040: /**
041: * Creates a new object.
042: * <P>
043: * @param param Passed in params if needed.
044: */
045: public Object createObject(Object param) {
046: EventRequestImpl aReq = new EventRequestImpl();
047:
048: if (logger.isLoggable(Level.INFO)) {
049: logger
050: .log(Level.INFO,
051: "PorletRequestPool.createObject(): created object");
052: }
053:
054: return aReq;
055: }
056:
057: /**
058: * Destroys an object.
059: */
060: public void destroyObject(Object o) {
061: //do nothing
062: }
063: }
064:
065: // constructor
066: public EventRequestPool(ServletContext context, int minSize,
067: int maxSize, boolean overflow, int partitionSize, Logger log) {
068:
069: super (new EventRequestPoolManager(context, logger), minSize,
070: maxSize, overflow, partitionSize);
071: logger = log;
072: }
073:
074: /**
075: * Obtains an portlet request object from the pool.
076: * <P>
077: * @param req The <code>HttpServletRequest</code> object
078: * @param res The <code>HttpServletResponse</code> object
079: * <P>
080: * @return <code>ActionRequest</code>
081: */
082: public EventRequest obtainObject(HttpServletRequest req,
083: HttpServletResponse res,
084: PortletContainerEventRequest pceRequest,
085: PortletContainerEventResponse pceResponse,
086: PortletContext context, PortalContext portalContext,
087: PortletDescriptor pDescriptor) {
088:
089: if (logger.isLoggable(Level.INFO)) {
090: logger.log(Level.INFO,
091: "EventRequestPool.obtainerObject(): obtained");
092: }
093:
094: EventRequestImpl eventRequest = (EventRequestImpl) (getPool()
095: .obtainObject(null));
096: eventRequest.init(req, res, pceRequest, pceResponse, context,
097: portalContext, pDescriptor);
098:
099: String evtName = (String) req
100: .getAttribute(PortletContainerConstants.EVENT_NAME);
101: eventRequest.setEventName(evtName);
102: byte[] serializedData = (byte[]) req
103: .getAttribute(PortletContainerConstants.EVENT_DATA);
104: ByteArrayInputStream evtStream = null;
105: //serializedData can be in case of event Failure
106: if (serializedData != null)
107: evtStream = new ByteArrayInputStream(serializedData);
108: if (evtStream != null)
109: evtStream.mark(0);
110: eventRequest.setEventStream(evtStream);
111:
112: return (EventRequestImpl) eventRequest;
113: }
114:
115: /**
116: * Releases an object back to the pool.
117: *
118: * @param <code>ActionRequest</code>
119: */
120: public void releaseObject(EventRequest aReq) {
121: ((EventRequestImpl) aReq).clear();
122: getPool().releaseObject(aReq);
123:
124: if (logger.isLoggable(Level.INFO)) {
125: logger.log(Level.INFO,
126: "ActionRequestPool.releaseObject(): released");
127: }
128: }
129:
130: }
|