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()) {
69        return 0;
70      }
71      return server.numConnections;
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  
82    @Override
83    public int getActiveGeneralRpcHandlerCount() {
84      if (!isServerStarted() || this.server.getScheduler() == null) {
85        return 0;
86      }
87      return server.getScheduler().getActiveGeneralRpcHandlerCount();
88    }
89  
90    @Override
91    public int getActivePriorityRpcHandlerCount() {
92      if (!isServerStarted() || this.server.getScheduler() == null) {
93        return 0;
94      }
95      return server.getScheduler().getActivePriorityRpcHandlerCount();
96    }
97  
98    @Override
99    public int getActiveReplicationRpcHandlerCount() {
100     if (!isServerStarted() || this.server.getScheduler() == null) {
101       return 0;
102     }
103     return server.getScheduler().getActiveReplicationRpcHandlerCount();
104   }
105 
106   @Override
107   public long getNumGeneralCallsDropped() {
108     if (!isServerStarted() || this.server.getScheduler() == null) {
109       return 0;
110     }
111     return server.getScheduler().getNumGeneralCallsDropped();
112   }
113 
114   @Override
115   public long getNumLifoModeSwitches() {
116     if (!isServerStarted() || this.server.getScheduler() == null) {
117       return 0;
118     }
119     return server.getScheduler().getNumLifoModeSwitches();
120   }
121 
122   @Override
123   public int getWriteQueueLength() {
124     if (!isServerStarted() || this.server.getScheduler() == null) {
125       return 0;
126     }
127     return server.getScheduler().getWriteQueueLength();
128   }
129 
130   @Override
131   public int getReadQueueLength() {
132     if (!isServerStarted() || this.server.getScheduler() == null) {
133       return 0;
134     }
135     return server.getScheduler().getReadQueueLength();
136   }
137 
138   @Override
139   public int getScanQueueLength() {
140     if (!isServerStarted() || this.server.getScheduler() == null) {
141       return 0;
142     }
143     return server.getScheduler().getScanQueueLength();
144   }
145 
146   @Override
147   public int getActiveWriteRpcHandlerCount() {
148     if (!isServerStarted() || this.server.getScheduler() == null) {
149       return 0;
150     }
151     return server.getScheduler().getActiveWriteRpcHandlerCount();
152   }
153 
154   @Override
155   public int getActiveReadRpcHandlerCount() {
156     if (!isServerStarted() || this.server.getScheduler() == null) {
157       return 0;
158     }
159     return server.getScheduler().getActiveReadRpcHandlerCount();
160   }
161 
162   @Override
163   public int getActiveScanRpcHandlerCount() {
164     if (!isServerStarted() || this.server.getScheduler() == null) {
165       return 0;
166     }
167     return server.getScheduler().getActiveScanRpcHandlerCount();
168   }
169 }