use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class ProfileContainer method afterPaint.
/**
* Override afterPaint to write the statistics after the component is painted.
*
* @param renderContext the renderContext to send output to.
*/
@Override
protected void afterPaint(final RenderContext renderContext) {
super.afterPaint(renderContext);
// UIC serialization stats
UicStats stats = new UicStats(UIContextHolder.getCurrent());
stats.analyseWC(this);
if (renderContext instanceof WebXmlRenderContext) {
PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
writer.println("<h2>Serialization Profile of UIC</h2>");
UicStatsAsHtml.write(writer, stats);
// ObjectProfiler
writer.println("<h2>ObjectProfiler - " + getClass().getName() + "</h2>");
writer.println("<pre>");
try {
writer.println(ObjectGraphDump.dump(this).toFlatSummary());
} catch (Exception e) {
LOG.error("Failed to dump component", e);
}
writer.println("</pre>");
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class VelocityRenderer method render.
/**
* Paints the component in HTML using the Velocity Template.
*
* @param component the component to paint.
* @param context the context to send the XML output to.
*/
@Override
public void render(final WComponent component, final RenderContext context) {
PrintWriter out = ((WebXmlRenderContext) context).getWriter();
// If we are debugging the layout, write markers so that the html
// designer can see where templates start and end.
boolean debugLayout = ConfigurationProperties.getDeveloperVelocityDebug();
if (debugLayout) {
String templateUrl = url;
if (url == null && component instanceof AbstractWComponent) {
templateUrl = ((AbstractWComponent) component).getTemplate();
}
out.println("<!-- Start " + templateUrl + " -->");
paintXml(component, out);
out.println("<!-- End " + templateUrl + " -->");
} else {
paintXml(component, out);
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class VelocityWriter method doReplace.
/**
* Replaces the search string by rendering the corresponding component.
*
* @param search the search String that was matched.
* @param backing the underlying writer to write the replacement to.
*/
@Override
protected void doReplace(final String search, final Writer backing) {
WComponent component = componentsByKey.get(search);
UIContextHolder.pushContext(uic);
try {
component.paint(new WebXmlRenderContext((PrintWriter) backing));
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScalingWithInterceptorChain.
@Test
public void testRenderingScalingWithInterceptorChain() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
makeAllInputsMandatory(component1);
component1.setLocked(true);
final UIContext uic1 = createUIContext();
final UIContext uicChain = createUIContext();
sendRequest(component1, uic1);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Just paint component
component1.preparePaint(new MockRequest());
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uicChain);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Paint with the interceptor chain
WebUtilities.renderWithTransformToHTML(component1);
}
}
};
// JIT warm-up
runnable.run();
long renderTimeChain = time(runnable) / NUM_REPETITIONS;
LOG.info("Render Component time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render Component/Chain time: " + (renderTimeChain / 1000000.0) + "ms");
Assert.assertTrue("Render with Chain time scaling should not be more than 3x.", renderTimeChain < renderTime1 * 3);
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScaling.
@Test
public void testRenderingScaling() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
final UIContext uic1 = createUIContext();
sendRequest(component1, uic1);
final AllComponents component10 = new AllComponents(10);
final UIContext uic10 = createUIContext();
sendRequest(component10, uic10);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic10);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component10.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime10 = time(runnable) / NUM_REPETITIONS;
LOG.info("Render 1x time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render 10x time: " + (renderTime10 / 1000000.0) + "ms");
Assert.assertTrue("Render time scaling should be O(n)", renderTime10 < renderTime1 * 12);
}
Aggregations