001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.ipc;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022import java.util.HashMap;
023import java.util.Map;
024import java.util.Set;
025
026
027@InterfaceAudience.Private
028public class CallQueueInfo {
029  private final Map<String, Map<String, Long>> callQueueMethodCountsSummary;
030  private final Map<String, Map<String, Long>> callQueueMethodSizeSummary;
031
032  CallQueueInfo() {
033    callQueueMethodCountsSummary = new HashMap<>();
034    callQueueMethodSizeSummary = new HashMap<>();
035  }
036
037  public Set<String> getCallQueueNames() {
038    return callQueueMethodCountsSummary.keySet();
039  }
040
041  public Set<String> getCalledMethodNames(String callQueueName) {
042    return callQueueMethodCountsSummary.get(callQueueName).keySet();
043  }
044
045  public long getCallMethodCount(String callQueueName, String methodName) {
046    long methodCount;
047
048    Map<String, Long> methodCountMap = callQueueMethodCountsSummary.getOrDefault(callQueueName, null);
049
050    if (null != methodCountMap) {
051      methodCount = methodCountMap.getOrDefault(methodName, 0L);
052    } else {
053      methodCount = 0L;
054    }
055
056    return methodCount;
057  }
058
059  void setCallMethodCount(String callQueueName, Map<String, Long> methodCountMap) {
060    callQueueMethodCountsSummary.put(callQueueName, methodCountMap);
061  }
062
063  public long getCallMethodSize(String callQueueName, String methodName) {
064    long methodSize;
065
066    Map<String, Long> methodSizeMap = callQueueMethodSizeSummary.getOrDefault(callQueueName, null);
067
068    if (null != methodSizeMap) {
069      methodSize = methodSizeMap.getOrDefault(methodName, 0L);
070    } else {
071      methodSize = 0L;
072    }
073
074    return methodSize;
075  }
076
077  void setCallMethodSize(String callQueueName, Map<String, Long> methodSizeMap) {
078    callQueueMethodSizeSummary.put(callQueueName, methodSizeMap);
079  }
080
081}