查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2017 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.buffer;
17  
18  import io.netty.util.internal.StringUtil;
19  
20  import java.util.List;
21  
22  /**
23   * Exposed metric for {@link PooledByteBufAllocator}.
24   */
25  @SuppressWarnings("deprecation")
26  public final class PooledByteBufAllocatorMetric implements ByteBufAllocatorMetric {
27  
28      private final PooledByteBufAllocator allocator;
29  
30      PooledByteBufAllocatorMetric(PooledByteBufAllocator allocator) {
31          this.allocator = allocator;
32      }
33  
34      /**
35       * Return the number of heap arenas.
36       */
37      public int numHeapArenas() {
38          return allocator.numHeapArenas();
39      }
40  
41      /**
42       * Return the number of direct arenas.
43       */
44      public int numDirectArenas() {
45          return allocator.numDirectArenas();
46      }
47  
48      /**
49       * Return a {@link List} of all heap {@link PoolArenaMetric}s that are provided by this pool.
50       */
51      public List<PoolArenaMetric> heapArenas() {
52          return allocator.heapArenas();
53      }
54  
55      /**
56       * Return a {@link List} of all direct {@link PoolArenaMetric}s that are provided by this pool.
57       */
58      public List<PoolArenaMetric> directArenas() {
59          return allocator.directArenas();
60      }
61  
62      /**
63       * Return the number of thread local caches used by this {@link PooledByteBufAllocator}.
64       */
65      public int numThreadLocalCaches() {
66          return allocator.numThreadLocalCaches();
67      }
68  
69      /**
70       * Return the size of the tiny cache.
71       */
72      public int tinyCacheSize() {
73          return allocator.tinyCacheSize();
74      }
75  
76      /**
77       * Return the size of the small cache.
78       */
79      public int smallCacheSize() {
80          return allocator.smallCacheSize();
81      }
82  
83      /**
84       * Return the size of the normal cache.
85       */
86      public int normalCacheSize() {
87          return allocator.normalCacheSize();
88      }
89  
90      /**
91       * Return the chunk size for an arena.
92       */
93      public int chunkSize() {
94          return allocator.chunkSize();
95      }
96  
97      @Override
98      public long usedHeapMemory() {
99          return allocator.usedHeapMemory();
100     }
101 
102     @Override
103     public long usedDirectMemory() {
104         return allocator.usedDirectMemory();
105     }
106 
107     @Override
108     public String toString() {
109         StringBuilder sb = new StringBuilder(256);
110         sb.append(StringUtil.simpleClassName(this))
111                 .append("(usedHeapMemory: ").append(usedHeapMemory())
112                 .append("; usedDirectMemory: ").append(usedDirectMemory())
113                 .append("; numHeapArenas: ").append(numHeapArenas())
114                 .append("; numDirectArenas: ").append(numDirectArenas())
115                 .append("; tinyCacheSize: ").append(tinyCacheSize())
116                 .append("; smallCacheSize: ").append(smallCacheSize())
117                 .append("; normalCacheSize: ").append(normalCacheSize())
118                 .append("; numThreadLocalCaches: ").append(numThreadLocalCaches())
119                 .append("; chunkSize: ").append(chunkSize()).append(')');
120         return sb.toString();
121     }
122 }