Author: julien_viet
Date: 2009-10-25 07:30:56 -0400 (Sun, 25 Oct 2009)
New Revision: 424
Modified:
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java
portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/OutputStreamPrinterTestCase.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
GTNPORTAL-64 : the portal seems to flush too many times per request to the servlet output
stream and only once at the end of the request (actually done by the close()) is good
enough
Modified:
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java
===================================================================
---
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java 2009-10-25
10:56:09 UTC (rev 423)
+++
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java 2009-10-25
11:30:56 UTC (rev 424)
@@ -58,17 +58,20 @@
private boolean failed;
+ private final boolean flushOnClose;
+
/**
* Builds an instance with the failureFlow being {@link IOFailureFlow#RETHROW} and
* a the ignoreOnFailure property set to false.
*
* @param encoder the encoder
* @param out the output
+ * @param flushOnClose flush when stream is closed
* @throws IllegalArgumentException if any argument is null
*/
- public OutputStreamPrinter(TextEncoder encoder, OutputStream out) throws
IllegalArgumentException
+ public OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean
flushOnClose) throws IllegalArgumentException
{
- this(encoder, out, IOFailureFlow.RETHROW, false);
+ this(encoder, out, IOFailureFlow.RETHROW, false, flushOnClose);
}
/**
@@ -78,9 +81,15 @@
* @param out the output
* @param failureFlow the control flow failureFlow
* @param ignoreOnFailure the behavior on failure
+ * @param flushOnClose flush when stream is closed
* @throws IllegalArgumentException if any argument is null
*/
- public OutputStreamPrinter(TextEncoder encoder, OutputStream out, IOFailureFlow
failureFlow, boolean ignoreOnFailure)
+ public OutputStreamPrinter(
+ TextEncoder encoder,
+ OutputStream out,
+ IOFailureFlow failureFlow,
+ boolean ignoreOnFailure,
+ boolean flushOnClose)
throws IllegalArgumentException
{
if (encoder == null)
@@ -100,6 +109,7 @@
this.failureFlow = failureFlow;
this.failed = false;
this.ignoreOnFailure = ignoreOnFailure;
+ this.flushOnClose = flushOnClose;
}
/**
@@ -208,7 +218,7 @@
public void flush() throws IOException
{
- if (!failed)
+ if (!failed && !flushOnClose)
{
try
{
Modified:
portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/OutputStreamPrinterTestCase.java
===================================================================
---
portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/OutputStreamPrinterTestCase.java 2009-10-25
10:56:09 UTC (rev 423)
+++
portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/OutputStreamPrinterTestCase.java 2009-10-25
11:30:56 UTC (rev 424)
@@ -133,7 +133,7 @@
private TestOutputStream(boolean wantFailure, IOFailureFlow mode, boolean
blockOnFailure)
{
this.wantFailure = wantFailure;
- this.osp = new OutputStreamPrinter(CharsetTextEncoder.getUTF8(), this, mode,
blockOnFailure);
+ this.osp = new OutputStreamPrinter(CharsetTextEncoder.getUTF8(), this, mode,
blockOnFailure, false);
}
public void write(int b) throws IOException
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java
===================================================================
---
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java 2009-10-25
10:56:09 UTC (rev 423)
+++
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java 2009-10-25
11:30:56 UTC (rev 424)
@@ -29,9 +29,9 @@
public class PortalPrinter extends OutputStreamPrinter
{
- public PortalPrinter(TextEncoder encoder, OutputStream out) throws
IllegalArgumentException
+ public PortalPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose)
throws IllegalArgumentException
{
- super(encoder, out);
+ super(encoder, out, flushOnClose);
}
public void println()
@@ -59,7 +59,8 @@
}
else
{
- write(String.valueOf(o));
+ String s = (o == null) ? "null" : o.toString();
+ write(s);
}
}
catch (IOException e)
Modified:
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
---
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2009-10-25
10:56:09 UTC (rev 423)
+++
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2009-10-25
11:30:56 UTC (rev 424)
@@ -275,7 +275,7 @@
{
//
- PortalPrinter printer = new PortalPrinter(encoder,
response_.getOutputStream());
+ PortalPrinter printer = new PortalPrinter(encoder, response_.getOutputStream(),
true);
//
if (HtmlValidator.DEBUG_MODE)
Modified:
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
---
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-10-25
10:56:09 UTC (rev 423)
+++
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-10-25
11:30:56 UTC (rev 424)
@@ -423,83 +423,92 @@
public void processRender(WebuiRequestContext context) throws Exception
{
Writer w = context.getWriter();
- if (!context.useAjax())
+
+ try
{
- super.processRender(context);
- }
- else
- {
- PortalRequestContext pcontext = (PortalRequestContext)context;
-
- UIMaskWorkspace uiMaskWS = getChildById(UIPortalApplication.UI_MASK_WS_ID);
- if (uiMaskWS.isUpdated())
- pcontext.addUIComponentToUpdateByAjax(uiMaskWS);
- if (getUIPopupMessages().hasMessage())
+ if (!context.useAjax())
{
- pcontext.addUIComponentToUpdateByAjax(getUIPopupMessages());
+ super.processRender(context);
}
+ else
+ {
+ PortalRequestContext pcontext = (PortalRequestContext)context;
- Set<UIComponent> list = context.getUIComponentToUpdateByAjax();
- List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>(3);
- List<UIComponent> uiDataComponents = new ArrayList<UIComponent>(5);
-
- if (list != null)
- {
- for (UIComponent uicomponent : list)
+ UIMaskWorkspace uiMaskWS = getChildById(UIPortalApplication.UI_MASK_WS_ID);
+ if (uiMaskWS.isUpdated())
+ pcontext.addUIComponentToUpdateByAjax(uiMaskWS);
+ if (getUIPopupMessages().hasMessage())
{
- if (uicomponent instanceof UIPortlet)
- uiPortlets.add((UIPortlet)uicomponent);
- else
- uiDataComponents.add(uicomponent);
+ pcontext.addUIComponentToUpdateByAjax(getUIPopupMessages());
}
- }
- w.write("<div class=\"PortalResponse\">");
- w.write("<div class=\"PortalResponseData\">");
- for (UIComponent uicomponent : uiDataComponents)
- {
- if (log.isDebugEnabled())
- log.debug("AJAX call: Need to refresh the UI component " +
uicomponent.getName());
- renderBlockToUpdate(uicomponent, context, w);
- }
- w.write("</div>");
- if (!context.getFullRender())
- {
- for (UIPortlet uiPortlet : uiPortlets)
+ Set<UIComponent> list = context.getUIComponentToUpdateByAjax();
+ List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>(3);
+ List<UIComponent> uiDataComponents = new
ArrayList<UIComponent>(5);
+
+ if (list != null)
{
+ for (UIComponent uicomponent : list)
+ {
+ if (uicomponent instanceof UIPortlet)
+ uiPortlets.add((UIPortlet)uicomponent);
+ else
+ uiDataComponents.add(uicomponent);
+ }
+ }
+ w.write("<div class=\"PortalResponse\">");
+ w.write("<div class=\"PortalResponseData\">");
+ for (UIComponent uicomponent : uiDataComponents)
+ {
if (log.isDebugEnabled())
- log.debug("AJAX call: Need to refresh the Portlet " +
uiPortlet.getId());
+ log.debug("AJAX call: Need to refresh the UI component " +
uicomponent.getName());
+ renderBlockToUpdate(uicomponent, context, w);
+ }
+ w.write("</div>");
- w.write("<div class=\"PortletResponse\"
style=\"display: none\">");
- w.append("<div
class=\"PortletResponsePortletId\">" + uiPortlet.getId() +
"</div>");
- w.append("<div
class=\"PortletResponseData\">");
+ if (!context.getFullRender())
+ {
+ for (UIPortlet uiPortlet : uiPortlets)
+ {
+ if (log.isDebugEnabled())
+ log.debug("AJAX call: Need to refresh the Portlet " +
uiPortlet.getId());
- /*
- * If the portlet is using our UI framework or supports it then it
- * will return a set of block to updates. If there is not block to
- * update the javascript client will see that as a full refresh of the
- * content part
- */
- uiPortlet.processRender(context);
+ w.write("<div class=\"PortletResponse\"
style=\"display: none\">");
+ w.append("<div
class=\"PortletResponsePortletId\">" + uiPortlet.getId() +
"</div>");
+ w.append("<div
class=\"PortletResponseData\">");
- w.append("</div>");
- w.append("<div
class=\"PortletResponseScript\"></div>");
- w.write("</div>");
+ /*
+ * If the portlet is using our UI framework or supports it then it
+ * will return a set of block to updates. If there is not block to
+ * update the javascript client will see that as a full refresh of the
+ * content part
+ */
+ uiPortlet.processRender(context);
+
+ w.append("</div>");
+ w.append("<div
class=\"PortletResponseScript\"></div>");
+ w.write("</div>");
+ }
}
- }
- w.write("<div class=\"PortalResponseScript\">");
- w.write(pcontext.getJavascriptManager().getJavascript());
- w.write("eXo.core.Browser.onLoad();\n");
- w.write(pcontext.getJavascriptManager().getCustomizedOnLoadScript());
- String skin = getAddSkinScript(list);
- if (skin != null)
- {
- w.write(skin);
+ w.write("<div class=\"PortalResponseScript\">");
+ w.write(pcontext.getJavascriptManager().getJavascript());
+ w.write("eXo.core.Browser.onLoad();\n");
+ w.write(pcontext.getJavascriptManager().getCustomizedOnLoadScript());
+ String skin = getAddSkinScript(list);
+ if (skin != null)
+ {
+ w.write(skin);
+ }
+ w.write("</div>");
+ w.write("</div>");
}
- w.write("</div>");
- w.write("</div>");
}
+ finally
+ {
+ //
+ w.close();
+ }
}
private String getAddSkinScript(Set<UIComponent> updateComponents)