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;
019
020import java.util.Collections;
021import java.util.Map;
022import java.util.stream.Collectors;
023import org.apache.hadoop.hbase.client.RegionInfo;
024import org.apache.yetus.audience.InterfaceAudience;
025
026@InterfaceAudience.Public
027public final class CacheEvictionStats {
028
029  private final long evictedBlocks;
030  private final long maxCacheSize;
031  private final Map<byte[], Throwable> exceptions;
032
033  CacheEvictionStats(CacheEvictionStatsBuilder builder) {
034    this.evictedBlocks = builder.evictedBlocks;
035    this.maxCacheSize = builder.maxCacheSize;
036    this.exceptions = builder.exceptions;
037  }
038
039  public long getEvictedBlocks() {
040    return evictedBlocks;
041  }
042
043  public long getMaxCacheSize() {
044    return maxCacheSize;
045  }
046
047  public Map<byte[], Throwable> getExceptions() {
048    return Collections.unmodifiableMap(exceptions);
049  }
050
051  public int getExceptionCount() {
052    return exceptions.size();
053  }
054
055  private String getFailedRegions() {
056    return exceptions.keySet().stream()
057      .map(regionName -> RegionInfo.prettyPrint(RegionInfo.encodeRegionName(regionName)))
058      .collect(Collectors.toList()).toString();
059  }
060
061  @InterfaceAudience.Private
062  public static CacheEvictionStatsBuilder builder() {
063    return new CacheEvictionStatsBuilder();
064  }
065
066  @Override
067  public String toString() {
068    return "CacheEvictionStats{" + "evictedBlocks=" + evictedBlocks + ", maxCacheSize="
069      + maxCacheSize + ", failedRegionsSize=" + getExceptionCount() + ", failedRegions="
070      + getFailedRegions() + '}';
071  }
072}