View Javadoc

1   // Autogenerated Jamon implementation
2   // /home/stack/trunk/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/common/TaskMonitorTmpl.jamon
3   
4   package org.apache.hadoop.hbase.tmpl.common;
5   
6   // 20, 1
7   import java.util.*;
8   // 21, 1
9   import org.apache.hadoop.hbase.monitoring.*;
10  // 22, 1
11  import org.apache.hadoop.util.StringUtils;
12  
13  public class TaskMonitorTmplImpl
14    extends org.jamon.AbstractTemplateImpl
15    implements org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.Intf
16  
17  {
18    private final String format;
19    private final TaskMonitor taskMonitor;
20    private final String filter;
21    protected static org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.ImplData __jamon_setOptionalArguments(org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.ImplData p_implData)
22    {
23      if(! p_implData.getFormat__IsNotDefault())
24      {
25        p_implData.setFormat("html");
26      }
27      if(! p_implData.getTaskMonitor__IsNotDefault())
28      {
29        p_implData.setTaskMonitor(TaskMonitor.get());
30      }
31      if(! p_implData.getFilter__IsNotDefault())
32      {
33        p_implData.setFilter("general");
34      }
35      return p_implData;
36    }
37    public TaskMonitorTmplImpl(org.jamon.TemplateManager p_templateManager, org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.ImplData p_implData)
38    {
39      super(p_templateManager, __jamon_setOptionalArguments(p_implData));
40      format = p_implData.getFormat();
41      taskMonitor = p_implData.getTaskMonitor();
42      filter = p_implData.getFilter();
43    }
44    
45    public void renderNoFlush(@SuppressWarnings({"unused","hiding"}) final java.io.Writer jamonWriter)
46      throws java.io.IOException
47    {
48      // 29, 1
49      
50  List<? extends MonitoredTask> tasks = taskMonitor.getTasks();
51  Iterator<? extends MonitoredTask> iter = tasks.iterator();
52  // apply requested filter
53  while (iter.hasNext()) {
54    MonitoredTask t = iter.next();
55    if (filter.equals("general")) {
56      if (t instanceof MonitoredRPCHandler)
57        iter.remove();
58    } else if (filter.equals("handler")) {
59      if (!(t instanceof MonitoredRPCHandler))
60        iter.remove();
61    } else if (filter.equals("rpc")) {
62      if (!(t instanceof MonitoredRPCHandler) || 
63          !((MonitoredRPCHandler) t).isRPCRunning())
64        iter.remove();
65    } else if (filter.equals("operation")) {
66      if (!(t instanceof MonitoredRPCHandler) || 
67          !((MonitoredRPCHandler) t).isOperationRunning())
68        iter.remove();
69    }
70  }
71  long now = System.currentTimeMillis();
72  Collections.reverse(tasks);
73  boolean first = true;
74  
75      // 55, 1
76      if (format.equals("json"))
77      {
78        // 55, 29
79        jamonWriter.write("\n[");
80        // 56, 2
81        for (MonitoredTask task : tasks)
82        {
83          // 56, 36
84          if (first)
85          {
86            // 56, 48
87            first = false;
88          }
89          // 56, 77
90          else
91          {
92            // 56, 84
93            jamonWriter.write(",");
94          }
95          // 56, 91
96          org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.toJSON()), jamonWriter);
97        }
98        // 56, 117
99        jamonWriter.write("]\n");
100     }
101     // 57, 1
102     else
103     {
104       // 57, 8
105       jamonWriter.write("\n<h2>Tasks</h2>\n  <ul class=\"nav nav-pills\">\n    <li ");
106       // 60, 9
107       if (filter.equals("all"))
108       {
109         // 60, 36
110         jamonWriter.write("class=\"active\"");
111       }
112       // 60, 56
113       jamonWriter.write("><a href=\"?filter=all\">Show All Monitored Tasks</a></li>\n    <li ");
114       // 61, 9
115       if (filter.equals("general"))
116       {
117         // 61, 40
118         jamonWriter.write("class=\"active\"");
119       }
120       // 61, 60
121       jamonWriter.write("><a href=\"?filter=general\">Show non-RPC Tasks</a></li>\n    <li ");
122       // 62, 9
123       if (filter.equals("handler"))
124       {
125         // 62, 40
126         jamonWriter.write("class=\"active\"");
127       }
128       // 62, 60
129       jamonWriter.write("><a href=\"?filter=handler\">Show All RPC Handler Tasks</a></li>\n    <li ");
130       // 63, 9
131       if (filter.equals("rpc"))
132       {
133         // 63, 36
134         jamonWriter.write("class=\"active\"");
135       }
136       // 63, 56
137       jamonWriter.write("><a href=\"?filter=rpc\">Show Active RPC Calls</a></li>\n    <li ");
138       // 64, 9
139       if (filter.equals("operation"))
140       {
141         // 64, 42
142         jamonWriter.write("class=\"active\"");
143       }
144       // 64, 62
145       jamonWriter.write("><a href=\"?filter=operation\">Show Client Operations</a></li>\n    <li><a href=\"?format=json&filter=");
146       // 65, 38
147       org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(filter), jamonWriter);
148       // 65, 50
149       jamonWriter.write("\">View as JSON</a></li>\n  </ul>\n  ");
150       // 67, 3
151       if (tasks.isEmpty())
152       {
153         // 67, 25
154         jamonWriter.write("\n    <p>No tasks currently running on this node.</p>\n  ");
155       }
156       // 69, 3
157       else
158       {
159         // 69, 10
160         jamonWriter.write("\n    <table class=\"table\">\n    <tr>\n      <th>Start Time</th>\n      <th>Description</th>\n      <th>State</th>\n      <th>Status</th>\n    </tr>\n    ");
161         // 77, 5
162         for (MonitoredTask task : tasks )
163         {
164           // 77, 40
165           jamonWriter.write("\n    <tr class=\"");
166           // 78, 16
167           {
168             // 78, 16
169             __jamon_innerUnit__stateCss(jamonWriter, task.getState() );
170           }
171           // 78, 55
172           jamonWriter.write("\">\n      <td>");
173           // 79, 11
174           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(new Date(task.getStartTime())), jamonWriter);
175           // 79, 46
176           jamonWriter.write("</td>\n      <td>");
177           // 80, 11
178           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.getDescription()), jamonWriter);
179           // 80, 38
180           jamonWriter.write("</td>\n      <td>");
181           // 81, 11
182           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.getState()), jamonWriter);
183           // 81, 32
184           jamonWriter.write("\n          (since ");
185           // 82, 18
186           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(StringUtils.formatTimeDiff(now, task.getStateTime())), jamonWriter);
187           // 82, 76
188           jamonWriter.write(" ago)\n      </td>\n      <td>");
189           // 84, 11
190           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.getStatus()), jamonWriter);
191           // 84, 33
192           jamonWriter.write("\n          (since ");
193           // 85, 18
194           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(StringUtils.formatTimeDiff(now, task.getStatusTime())), jamonWriter);
195           // 85, 77
196           jamonWriter.write(" \n          ago)</td>\n    </tr>\n    ");
197         }
198         // 88, 12
199         jamonWriter.write("\n    </table>\n\n  ");
200       }
201       // 91, 9
202       jamonWriter.write("\n");
203     }
204     // 92, 7
205     jamonWriter.write("\n\n\n");
206   }
207   
208   
209   // 95, 1
210   private void __jamon_innerUnit__stateCss(@SuppressWarnings({"unused","hiding"}) final java.io.Writer jamonWriter, final MonitoredTask.State state)
211     throws java.io.IOException
212   {
213     // 99, 1
214            if (state == MonitoredTask.State.COMPLETE) { 
215     // 99, 68
216     jamonWriter.write("alert alert-success");
217     // 99, 87
218      } 
219     // 100, 1
220       else if (state == MonitoredTask.State.ABORTED)  { 
221     // 100, 68
222     jamonWriter.write("alert alert-error");
223     // 100, 85
224        } 
225   }
226   
227   
228 }