Version 1.7.4
[gae.git] / java / src / main / com / google / appengine / api / quota / QuotaServiceImpl.java
blobd9d6b1a2e9bafedabc063af77d8fdf87c5cc87aa
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;
9 /**
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();
20 if (env == null) {
21 return null;
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();
41 @Override
42 public long convertCpuSecondsToMegacycles(double cpuSeconds) {
43 return (long) (cpuSeconds * MCYCLES_PER_SECOND);
46 @Override
47 public double convertMegacyclesToCpuSeconds(long megaCycles) {
48 return megaCycles / MCYCLES_PER_SECOND;