1 // Copyright 2009 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.quota
;
5 import com
.google
.apphosting
.api
.ApiProxy
;
6 import com
.google
.apphosting
.api
.ApiStats
;
7 import com
.google
.apphosting
.api
.ApiProxy
.Environment
;
10 * Implementation details for the QuotaService.
14 class QuotaServiceImpl
implements QuotaService
{
16 private static final double MCYCLES_PER_SECOND
= 1200.0;
18 private static ApiStats
getStats() {
19 Environment env
= ApiProxy
.getCurrentEnvironment();
23 return ApiStats
.get(env
);
26 public boolean supports(DataType type
) {
28 return getStats() != null;
31 public long getApiTimeInMegaCycles() {
32 ApiStats stats
= getStats();
33 return (stats
== null) ?
0L : stats
.getApiTimeInMegaCycles();
36 public long getCpuTimeInMegaCycles() {
37 ApiStats stats
= getStats();
38 return (stats
== null) ?
0L : stats
.getCpuTimeInMegaCycles();
42 public long convertCpuSecondsToMegacycles(double cpuSeconds
) {
43 return (long) (cpuSeconds
* MCYCLES_PER_SECOND
);
47 public double convertMegacyclesToCpuSeconds(long megaCycles
) {
48 return megaCycles
/ MCYCLES_PER_SECOND
;