01: /*
02:
03: Copyright 2004, Martian Software, Inc.
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16:
17: */
18:
19: package com.martiansoftware.nailgun.builtins;
20:
21: import java.util.Iterator;
22: import java.util.Map;
23:
24: import com.martiansoftware.nailgun.NGServer;
25: import com.martiansoftware.nailgun.NGContext;
26:
27: /**
28: * <p>Displays all <a href="NailStats.html">NailStats</a> tracked by the server.</p>
29: *
30: * <p>This can be run standalone with no arguments. It will also run automatically
31: * upon <code>NGServer</code> shutdown, sending its output to the server's <code>System.out</code>.</p>
32: *
33: * <p>This is aliased by default to the command "<code>ng-stats</code>".</p>
34: * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
35: */
36:
37: public class NGServerStats {
38:
39: public static void nailShutdown(NGServer server) {
40: dumpStats(server, server.out);
41: }
42:
43: public static void nailMain(NGContext context) {
44: dumpStats(context.getNGServer(), context.out);
45: }
46:
47: private static void dumpStats(NGServer server,
48: java.io.PrintStream out) {
49: Map stats = server.getNailStats();
50: for (Iterator i = stats.values().iterator(); i.hasNext();) {
51: out.println(i.next());
52: }
53: }
54:
55: }
|