use of org.apache.tapestry5.ioc.IOOperation in project tapestry-5 by apache.
the class StreamPageContentResultProcessor method processResultValue.
public void processResultValue(StreamPageContent value) throws IOException {
Class<?> pageClass = value.getPageClass();
Object[] activationContext = value.getPageActivationContext();
final String pageName = pageClass == null ? requestGlobals.getActivePageName() : resolver.resolvePageClassNameToPageName(pageClass.getName());
final EventContext context = activationContext == null ? new EmptyEventContext() : new ArrayEventContext(typeCoercer, activationContext);
if (value.isBypassActivation()) {
request.setAttribute(InternalConstants.BYPASS_ACTIVATION, true);
}
request.setAttribute(TapestryConstants.RESPONSE_RENDERER, new IOOperation<Void>() {
public Void perform() throws IOException {
handler.handle(new PageRenderRequestParameters(pageName, context, false));
return null;
}
});
}
use of org.apache.tapestry5.ioc.IOOperation in project tapestry-5 by apache.
the class DeferredResponseRenderer method invokeQueuedRenderer.
private void invokeQueuedRenderer() throws IOException {
while (true) {
IOOperation responseRenderer = (IOOperation) request.getAttribute(TapestryConstants.RESPONSE_RENDERER);
if (responseRenderer == null) {
break;
}
// There's a particular case where an operation puts a different operation into the attribute;
// we'll handle that on the next pass.
request.setAttribute(TapestryConstants.RESPONSE_RENDERER, null);
tracker.perform("Executing deferred response renderer.", responseRenderer);
}
}
use of org.apache.tapestry5.ioc.IOOperation in project tapestry-5 by apache.
the class AbstractMinimizer method minimize.
@Override
public StreamableResource minimize(final StreamableResource input) throws IOException {
if (!isEnabled(input)) {
return input;
}
long startNanos = System.nanoTime();
final ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
tracker.perform("Minimizing " + input, new IOOperation<Void>() {
@Override
public Void perform() throws IOException {
InputStream in = doMinimize(input);
TapestryInternalUtils.copy(in, bos);
in.close();
return null;
}
});
// The content is minimized, but can still be (GZip) compressed.
StreamableResource output = new StreamableResourceImpl("minimized " + input.getDescription(), input.getContentType(), CompressionStatus.COMPRESSABLE, input.getLastModified(), new BytestreamCache(bos), checksumGenerator, input.getResponseCustomizer());
if (logger.isInfoEnabled()) {
long elapsedNanos = System.nanoTime() - startNanos;
int inputSize = input.getSize();
int outputSize = output.getSize();
double elapsedMillis = ((double) elapsedNanos) * NANOS_TO_MILLIS;
// e.g., reducing 100 bytes to 25 would be a (100-25)/100 reduction, or 75%
double reduction = 100d * ((double) (inputSize - outputSize)) / ((double) inputSize);
logger.info(String.format("Minimized %s (%,d input bytes of %s to %,d output bytes in %.2f ms, %.2f%% reduction)", input.getDescription(), inputSize, resourceType, outputSize, elapsedMillis, reduction));
}
return output;
}
use of org.apache.tapestry5.ioc.IOOperation in project tapestry-5 by apache.
the class StackAssetRequestHandler method streamStackResource.
private boolean streamStackResource(String extraPath) throws IOException {
Matcher matcher = pathPattern.matcher(extraPath);
if (!matcher.matches()) {
logger.warn("Unable to parse '{}' as an asset stack path", extraPath);
return false;
}
String checksum = matcher.group(1);
String localeName = matcher.group(2);
final String stackName = matcher.group(3);
final boolean compressed = checksum.startsWith("z");
if (compressed) {
checksum = checksum.substring(1);
}
final JavaScriptStack stack = stackSource.findStack(stackName);
if (stack == null) {
logger.warn("JavaScript stack '{}' not found.", stackName);
return false;
}
// Yes, I have a big regret that the JavaScript stack stuff relies on this global, rather than
// having it passed around properly.
localizationSetter.setNonPersistentLocaleFromLocaleName(localeName);
StreamableResource resource = tracker.perform(String.format("Assembling JavaScript asset stack '%s' (%s)", stackName, localeName), new IOOperation<StreamableResource>() {
public StreamableResource perform() throws IOException {
return javaScriptStackAssembler.assembleJavaScriptResourceForStack(stackName, compressed, stack.getJavaScriptAggregationStrategy());
}
});
if (resource == null) {
return false;
}
return resourceStreamer.streamResource(resource, checksum, ResourceStreamer.DEFAULT_OPTIONS);
}
Aggregations