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