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