Search in sources :

Example 1 with TimerContext

use of com.yammer.metrics.core.TimerContext in project netty by netty.

the class CaliperRunner method main.

/**
 * Verify measure publication manually.
 */
public static void main(final String[] args) throws Exception {
    final Run run = newRun("test-main");
    for (int param = 0; param < 5; param++) {
        final CaliperMeasure measure = new CaliperMeasure();
        measure.variables().put("param", String.valueOf(param));
        for (int step = 0; step < 5; step++) {
            measure.rate().mark(50 + step);
            final TimerContext time = measure.time().time();
            Thread.sleep(15);
            time.stop();
            measure.size().value(50 + step);
            measure.mark();
        }
        measure.appendTo(run);
    }
    final Result result = newResult(run);
    publish(result);
    System.out.println(json(result));
}
Also used : TimerContext(com.yammer.metrics.core.TimerContext) Run(com.google.caliper.Run) ScenarioResult(com.google.caliper.ScenarioResult) Result(com.google.caliper.Result)

Example 2 with TimerContext

use of com.yammer.metrics.core.TimerContext in project photon-core by 1000Memories.

the class PhotoResource method getPhoto.

@GET
@Timed
@CacheControl(immutable = true)
public Response getPhoto(@PathParam("name") String name, @MatrixParam("w") Integer width, @MatrixParam("r") RotationParam rotateAngle, @MatrixParam("c") RectangleParam crop) throws Exception {
    InputStream resultStream;
    InputStream imageStream;
    try {
        imageStream = new BufferedInputStream(photoProvider.getPhotoInputStream(name));
    } catch (FileNotFoundException fnfe) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    String mimeType = URLConnection.guessContentTypeFromStream(imageStream);
    if (mimeType == null) {
        // Not implemented
        throw new WebApplicationException(501);
    }
    if (width != null || rotateAngle != null || crop != null) {
        BufferedImage image;
        TimerContext readContext = readTimer.time();
        try {
            image = ImageIO.read(imageStream);
        } finally {
            imageStream.close();
            readContext.stop();
        }
        if (crop != null) {
            image = com.thousandmemories.photon.core.Processor.crop(image, crop.get());
        }
        if (rotateAngle != null) {
            image = com.thousandmemories.photon.core.Processor.rotate(image, rotateAngle.get());
        }
        if (width != null) {
            image = com.thousandmemories.photon.core.Processor.fitToWidth(image, width);
        }
        Iterator<ImageWriter> i = ImageIO.getImageWritersByMIMEType(mimeType);
        if (!i.hasNext()) {
            mimeType = "image/jpeg";
            i = ImageIO.getImageWritersByMIMEType(mimeType);
        }
        ImageWriter writer = i.next();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        writer.setOutput(new MemoryCacheImageOutputStream(os));
        writer.write(image);
        image.flush();
        image = null;
        resultStream = new ByteArrayInputStream(os.toByteArray());
    } else {
        resultStream = imageStream;
    }
    return Response.ok(resultStream, mimeType).build();
}
Also used : MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) TimerContext(com.yammer.metrics.core.TimerContext) ImageWriter(javax.imageio.ImageWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Timed(com.yammer.metrics.annotation.Timed) CacheControl(com.yammer.dropwizard.jersey.caching.CacheControl)

Example 3 with TimerContext

use of com.yammer.metrics.core.TimerContext in project photon-core by 1000Memories.

the class Processor method fitToWidth.

public static BufferedImage fitToWidth(BufferedImage image, int width) throws Exception {
    // TODO: Don't ever make an image bigger
    TimerContext resizeContext = resizeTimer.time();
    BufferedImage result = AsyncScalr.resize(image, Scalr.Mode.FIT_TO_WIDTH, width).get();
    image.flush();
    resizeContext.stop();
    return result;
}
Also used : TimerContext(com.yammer.metrics.core.TimerContext) BufferedImage(java.awt.image.BufferedImage)

Example 4 with TimerContext

use of com.yammer.metrics.core.TimerContext in project photon-core by 1000Memories.

the class Processor method crop.

public static BufferedImage crop(BufferedImage image, Rectangle bounds) throws Exception {
    TimerContext cropContext = cropTimer.time();
    BufferedImage result = AsyncScalr.crop(image, bounds.x, bounds.y, bounds.width, bounds.height).get();
    image.flush();
    cropContext.stop();
    return result;
}
Also used : TimerContext(com.yammer.metrics.core.TimerContext) BufferedImage(java.awt.image.BufferedImage)

Example 5 with TimerContext

use of com.yammer.metrics.core.TimerContext in project photon-core by 1000Memories.

the class Processor method rotate.

public static BufferedImage rotate(BufferedImage image, Scalr.Rotation rotation) throws Exception {
    TimerContext rotateContext = rotateTimer.time();
    BufferedImage result = AsyncScalr.rotate(image, rotation).get();
    image.flush();
    rotateContext.stop();
    return result;
}
Also used : TimerContext(com.yammer.metrics.core.TimerContext) BufferedImage(java.awt.image.BufferedImage)

Aggregations

TimerContext (com.yammer.metrics.core.TimerContext)10 BufferedImage (java.awt.image.BufferedImage)4 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 Row (org.apache.hadoop.hbase.client.Row)2 Result (com.google.caliper.Result)1 Run (com.google.caliper.Run)1 ScenarioResult (com.google.caliper.ScenarioResult)1 CacheControl (com.yammer.dropwizard.jersey.caching.CacheControl)1 Timed (com.yammer.metrics.annotation.Timed)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 Map (java.util.Map)1 ImageWriter (javax.imageio.ImageWriter)1