Search in sources :

Example 1 with IOOperation

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;
        }
    });
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) IOException(java.io.IOException)

Example 2 with IOOperation

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);
    }
}
Also used : IOOperation(org.apache.tapestry5.ioc.IOOperation)

Example 3 with IOOperation

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;
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) BytestreamCache(org.apache.tapestry5.internal.services.assets.BytestreamCache) InputStream(java.io.InputStream) StreamableResourceImpl(org.apache.tapestry5.internal.services.assets.StreamableResourceImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 4 with IOOperation

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);
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) Matcher(java.util.regex.Matcher) JavaScriptStack(org.apache.tapestry5.services.javascript.JavaScriptStack) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 StreamableResource (org.apache.tapestry5.services.assets.StreamableResource)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Matcher (java.util.regex.Matcher)1 EventContext (org.apache.tapestry5.EventContext)1 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)1 BytestreamCache (org.apache.tapestry5.internal.services.assets.BytestreamCache)1 StreamableResourceImpl (org.apache.tapestry5.internal.services.assets.StreamableResourceImpl)1 IOOperation (org.apache.tapestry5.ioc.IOOperation)1 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)1 JavaScriptStack (org.apache.tapestry5.services.javascript.JavaScriptStack)1