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