Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.avro.ipc.stats;
Exposes information provided by a StatsPlugin as a web page. This class follows the same synchronization conventions as StatsPlugin, to avoid requiring StatsPlugin to serve a copy of the data.
 public class StatsServlet extends HttpServlet {
   private final StatsPlugin statsPlugin;
   public StatsServlet(StatsPlugin statsPlugin) {
     this. = statsPlugin;
   protected void doGet(HttpServletRequest reqHttpServletResponse resp)
       throws ServletExceptionIOException {
   void writeStats(Writer wthrows IOException {
     w.append("<html><head><title>Avro RPC Stats</title></head>");
     w.append("<body><h1>Avro RPC Stats</h1>");
     w.append("<h2>Active RPCs</h2>");
     for (Entry<RPCContextStopwatchrpc : this...entrySet()) {
       writeActiveRpc(wrpc.getKey(), rpc.getValue());
     w.append("<h2>Per-method Timing</h2>");
     synchronized(this..) {
       for (Entry<MessageFloatHistogram<?>> e :
         this...entrySet()) {
         writeMethod(we.getKey(), e.getValue());
   private void writeActiveRpc(Writer wRPCContext rpcStopwatch stopwatchthrows IOException {
     w.append("<li>").append(rpc.getMessage().getName()).append(": ");
   private void writeMethod(Writer wMessage messageFloatHistogram<?> histthrows IOException {
     w.append("<p>Number of calls: ");
     w.append("</p><p>Average Duration: ");
     w.append("</p><p>Std Dev: ");
     for (Histogram.Entry<?> e : hist.entries()) {
  private CharSequence formatMillis(float millis) {
    return String.format("%.0fms"millis);
New to GrepCode? Check out our FAQ X