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