1
19
20 package com.liferay.portlet;
21
22 import com.liferay.portal.model.Portlet;
23 import com.liferay.portal.util.PropsValues;
24
25 import javax.portlet.PortletContext;
26 import javax.portlet.PortletMode;
27 import javax.portlet.PortletPreferences;
28 import javax.portlet.WindowState;
29
30 import javax.servlet.http.HttpServletRequest;
31
32 import org.apache.commons.pool.BasePoolableObjectFactory;
33 import org.apache.commons.pool.ObjectPool;
34 import org.apache.commons.pool.impl.StackObjectPool;
35
36
42 public class ActionRequestFactory {
43
44 public static ActionRequestImpl create(
45 HttpServletRequest request, Portlet portlet,
46 InvokerPortlet invokerPortlet, PortletContext portletContext,
47 WindowState windowState, PortletMode portletMode,
48 PortletPreferences prefs, long plid)
49 throws Exception {
50
51 ActionRequestImpl actionRequestImpl = null;
52
53 if (PropsValues.COMMONS_POOL_ENABLED) {
54 actionRequestImpl =
55 (ActionRequestImpl)_instance._pool.borrowObject();
56 }
57 else {
58 actionRequestImpl = new ActionRequestImpl();
59 }
60
61 actionRequestImpl.init(
62 request, portlet, invokerPortlet, portletContext, windowState,
63 portletMode, prefs, plid);
64
65 return actionRequestImpl;
66 }
67
68 public static void recycle(ActionRequestImpl actionRequestImpl)
69 throws Exception {
70
71 if (PropsValues.COMMONS_POOL_ENABLED) {
72 _instance._pool.returnObject(actionRequestImpl);
73 }
74 else if (actionRequestImpl != null) {
75 actionRequestImpl.recycle();
76 }
77 }
78
79 private ActionRequestFactory() {
80 _pool = new StackObjectPool(new Factory());
81 }
82
83 private static ActionRequestFactory _instance = new ActionRequestFactory();
84
85 private ObjectPool _pool;
86
87 private class Factory extends BasePoolableObjectFactory {
88
89 public Object makeObject() {
90 return new ActionRequestImpl();
91 }
92
93 public void passivateObject(Object obj) {
94 ActionRequestImpl actionRequestImpl = (ActionRequestImpl)obj;
95
96 actionRequestImpl.recycle();
97 }
98
99 }
100
101 }