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));
}
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();
}
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;
}
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;
}
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;
}
Aggregations