KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > stats > PWCVirtualServerStatsImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.web.stats;
25
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import javax.management.j2ee.statistics.Stats JavaDoc;
29 import javax.management.j2ee.statistics.Statistic JavaDoc;
30 import com.sun.logging.LogDomains;
31 import com.sun.enterprise.web.VirtualServer;
32 import com.sun.enterprise.admin.monitor.stats.StringStatistic;
33 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl;
34 import com.sun.enterprise.admin.monitor.stats.PWCVirtualServerStats;
35 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
36
37 /**
38  * Class representing Virtual Server stats in PE.
39  */

40 public class PWCVirtualServerStatsImpl implements PWCVirtualServerStats {
41
42     private static Logger JavaDoc _logger = LogDomains.getLogger(
43                                                     LogDomains.WEB_LOGGER);
44
45     private long startTime;
46     private GenericStatsImpl baseStatsImpl;
47     private StringStatistic idStats;
48     private StringStatistic modeStats;
49     private StringStatistic hostsStats;
50     private StringStatistic interfacesStats;
51
52     /*
53      * Constructor.
54      */

55     public PWCVirtualServerStatsImpl(VirtualServer vs) {
56
57         initializeStatistics(vs);
58
59         baseStatsImpl = new GenericStatsImpl(
60             com.sun.enterprise.admin.monitor.stats.PWCVirtualServerStats.class,
61             this);
62     }
63
64     /**
65      * Returns the virtual server ID.
66      *
67      * @return Virtual server ID
68      */

69     public StringStatistic getId() {
70         return idStats;
71     }
72
73     /**
74      * Returns the virtual server mode.
75      *
76      * @return Virtual server mode
77      */

78     public StringStatistic getMode() {
79         return modeStats;
80     }
81
82     /**
83      * Returns the host names of this virtual server
84      *
85      * @return Host names of this virtual server
86      */

87     public StringStatistic getHosts() {
88         return hostsStats;
89     }
90     
91     /**
92      * Returns the interfaces of this virtual server
93      *
94      * @return Interfaces of this virtual server
95      */

96     public StringStatistic getInterfaces() {
97         return interfacesStats;
98     }
99
100     public Statistic JavaDoc[] getStatistics() {
101         return baseStatsImpl.getStatistics();
102     }
103     
104     public String JavaDoc[] getStatisticNames() {
105         return baseStatsImpl.getStatisticNames();
106     }
107
108     public Statistic JavaDoc getStatistic(String JavaDoc str) {
109         return baseStatsImpl.getStatistic(str);
110     }
111
112     /**
113      * Initializes the stats from the given virtual server
114      *
115      * @param vs Virtual server from which to derive stats
116      */

117     private void initializeStatistics(VirtualServer vs) {
118
119         startTime = System.currentTimeMillis();
120
121         // ID
122
idStats = new StringStatisticImpl(
123                                 vs.getID(),
124                                 "Id",
125                                 "String",
126                                 "Virtual Server ID",
127                                 startTime,
128                                 startTime);
129
130         // Mode
131
modeStats = new StringStatisticImpl(
132                                 vs.isActive() ? "active" : "unknown",
133                                 "Mode",
134                                 "unknown/active",
135                                 "Virtual Server mode",
136                                 startTime,
137                                 startTime);
138
139         // Hosts
140
String JavaDoc hosts = null;
141         String JavaDoc[] aliases = vs.findAliases();
142         if (aliases != null) {
143             for (int i=0; i<aliases.length; i++) {
144                 if (hosts == null) {
145                     hosts = aliases[i];
146                 } else {
147                     hosts += ", " + aliases[i];
148                 }
149             }
150         }
151         hostsStats = new StringStatisticImpl(
152                                 hosts,
153                                 "Hosts",
154                                 "String",
155                                 "The software virtual hostnames serviced by "
156                                 + "this Virtual Server",
157                                 startTime,
158                                 startTime);
159
160         // Interfaces
161
interfacesStats = new StringStatisticImpl(
162                                 "0.0.0.0", // XXX FIX
163
"Interfaces",
164                                 "String",
165                                 "The interfaces for which this Virtual Server "
166                                 + "has been configured",
167                                 startTime,
168                                 startTime);
169     }
170
171
172 }
173
Popular Tags