View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.ipc;
21  
22  public class MetricsHBaseServerWrapperImpl implements MetricsHBaseServerWrapper {
23  
24    private RpcServer server;
25  
26    MetricsHBaseServerWrapperImpl(RpcServer server) {
27      this.server = server;
28    }
29  
30    private boolean isServerStarted() {
31      return this.server != null && this.server.isStarted();
32    }
33  
34    @Override
35    public long getTotalQueueSize() {
36      if (!isServerStarted()) {
37        return 0;
38      }
39      return server.callQueueSize.get();
40    }
41  
42    @Override
43    public int getGeneralQueueLength() {
44      if (!isServerStarted() || this.server.getScheduler() == null) {
45        return 0;
46      }
47      return server.getScheduler().getGeneralQueueLength();
48    }
49  
50    @Override
51    public int getReplicationQueueLength() {
52      if (!isServerStarted() || this.server.getScheduler() == null) {
53        return 0;
54      }
55      return server.getScheduler().getReplicationQueueLength();
56    }
57  
58    @Override
59    public int getPriorityQueueLength() {
60      if (!isServerStarted() || this.server.getScheduler() == null) {
61        return 0;
62      }
63      return server.getScheduler().getPriorityQueueLength();
64    }
65  
66    @Override
67    public int getNumOpenConnections() {
68      if (!isServerStarted() || this.server.connectionList == null) {
69        return 0;
70      }
71      return server.connectionList.size();
72    }
73  
74    @Override
75    public int getActiveRpcHandlerCount() {
76      if (!isServerStarted() || this.server.getScheduler() == null) {
77        return 0;
78      }
79      return server.getScheduler().getActiveRpcHandlerCount();
80    }
81  }