1.9.5
[gae.git] / java / src / main / com / google / appengine / tools / appstats / ChannelRpcCostCalculator.java
blob1539406cc6fd17e85d2e6517d9ecb9f719bbbe7e
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;
6 import java.util.Arrays;
7 import java.util.Map;
9 /**
10 * {@link RpcCostCalculator} implementation for the Channel API.
13 class ChannelRpcCostCalculator implements RpcCostCalculator {
15 private static final String PKG = "channel";
17 private final StatsProtos.BilledOpProto billedOpProto =
18 StatsProtos.BilledOpProto.newBuilder().setNumOps(1).setOp(CHANNEL_OPEN).build();
20 private final RpcCost channelOpenCostMicropennies;
22 ChannelRpcCostCalculator(long channelOpenCostMicropennies) {
23 this.channelOpenCostMicropennies =
24 new RpcCost(channelOpenCostMicropennies, Arrays.asList(billedOpProto));
27 @Override
28 public RpcCost determineCost(String methodName, byte[] request, byte[] response) {
29 if (methodName.equals("CreateChannel")) {
30 return channelOpenCostMicropennies;
32 return FREE;
35 static void register(
36 Map<String, RpcCostCalculator> costCalculatorMap, RpcOperationCostManager opCostMgr) {
37 costCalculatorMap.put(PKG, new ChannelRpcCostCalculator(opCostMgr.costOf(CHANNEL_OPEN)));