1 // Copyright 2012 Google Inc. All Rights Reserved.
2 package com
.google
.appengine
.tools
.appstats
;
4 import static com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
.CHANNEL_OPEN
;
5 import static com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
.DATASTORE_READ
;
6 import static com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
.DATASTORE_SMALL
;
7 import static com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
.DATASTORE_WRITE
;
8 import static com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
.MAIL_RECIPIENT
;
9 import static com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
.XMPP_STANZA
;
11 import com
.google
.appengine
.tools
.appstats
.StatsProtos
.BilledOpProto
.BilledOp
;
12 import com
.google
.common
.collect
.Maps
;
17 * {@link RpcOperationCostManager} implementation with all the costs hard-coded.
20 class StaticRpcOperationCostManager
implements RpcOperationCostManager
{
22 private static final long MILLION
= 1000000;
23 private static final long PER_HUNDRED_THOUSAND
= MILLION
/ 100000;
24 private static final long PER_THOUSAND
= MILLION
/ 1000;
25 private static final long PER_HUNDRED
= MILLION
/ 100;
27 static final Map
<BilledOp
, Long
> COST_MAP
;
30 COST_MAP
= Maps
.newHashMap();
32 COST_MAP
.put(DATASTORE_READ
, perHundredThousand(7));
34 COST_MAP
.put(DATASTORE_WRITE
, perHundredThousand(10));
36 COST_MAP
.put(DATASTORE_SMALL
, perHundredThousand(1));
38 COST_MAP
.put(MAIL_RECIPIENT
, perThousand(1));
40 COST_MAP
.put(CHANNEL_OPEN
, perHundred(1));
42 COST_MAP
.put(XMPP_STANZA
, perHundredThousand(10));
45 private static long perHundredThousand(long centsPerHundredThousand
) {
46 return centsPerHundredThousand
* PER_HUNDRED_THOUSAND
;
50 private static long perThousand(long centsPerThousand
) {
51 return centsPerThousand
* PER_THOUSAND
;
55 private static long perHundred(long centsPerHundred
) {
56 return centsPerHundred
* PER_HUNDRED
;
61 public long costOf(BilledOp op
) {
62 return COST_MAP
.get(op
);