1 // Copyright 2009 Google Inc. All Rights Reserved.
3 package com
.google
.apphosting
.api
;
6 * Represents automatic statistics collected by the ApiProxy. If present, this
7 * object will be stored under the KEY-variable in an Environment's property.
8 * This object is basically a pojo, a simple container for collected values.
11 public abstract class ApiStats
{
14 * The name that this object is stored in.
16 private static final String KEY
= ApiStats
.class.getName();
19 * For a given environment, return the corresponding ApiStats object. If the
20 * environment does not have an ApiStats object, null will be returned.
22 public static ApiStats
get(ApiProxy
.Environment env
) {
23 return (ApiStats
) env
.getAttributes().get(KEY
);
27 * @return the overall time spent in API cycles, as returned by the system.
30 public abstract long getApiTimeInMegaCycles();
33 * @return the overall time spent in CPU processing. Unit is megacycles.
35 public abstract long getCpuTimeInMegaCycles();
38 * Creates a new ApiStats object and binds it to a given Environment.
39 * @param env the Environment object to bind this object to.
40 * @exception IllegalStateException if an object is already bound
42 protected ApiStats(ApiProxy
.Environment env
){
47 * Binds this object to a particular environment. This step enables the
48 * stats object to access and make available request-specific statistics that
49 * would usually not be accessible.
50 * @param env the Environment object to bind this object to.
51 * @exception IllegalStateException if an object is already bound
53 private void bind(ApiProxy
.Environment env
) {
54 ApiStats original
= get(env
);
55 if (original
!= null) {
57 if (original
!= this) {
58 throw new IllegalStateException(
59 "Cannot replace existing ApiStats object");
64 env
.getAttributes().put(KEY
, this);