KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > monitor > stats > LoadBalancerServerStatsImpl


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.management.monitor.stats;
25
26 import java.util.Date JavaDoc;
27 import java.util.Map JavaDoc;
28 import javax.management.j2ee.statistics.Statistic JavaDoc;
29 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
30 import com.sun.appserv.management.j2ee.statistics.CountStatisticImpl;
31 import com.sun.appserv.management.j2ee.statistics.StringStatistic;
32 import com.sun.appserv.management.j2ee.statistics.StringStatisticImpl;
33 import com.sun.appserv.management.monitor.statistics.LoadBalancerServerStats;
34 import com.sun.enterprise.admin.monitor.stats.lb.ClusterStats;
35 import com.sun.enterprise.admin.monitor.stats.lb.InstanceStats;
36 import com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStatsInterface;
37 import com.sun.enterprise.server.ApplicationServer;
38 import com.sun.enterprise.server.pluggable.LBFeatureFactory;
39
40 public final class LoadBalancerServerStatsImpl implements CustomStatsImpl {
41     
42     /** Returns the statistics for a load-balanced server instance
43      * @return an array of {@link Statistic}
44      */

45     public Statistic JavaDoc[] getStatistics() {
46         LoadBalancerStatsInterface lbstats = lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName);
47         Statistic JavaDoc[] statArr1 = new Statistic JavaDoc[3];
48         StringStatistic stat11 = new StringStatisticImpl("Health", "Instance Health", "NONE", 0, 0, "");
49         CountStatistic JavaDoc stat21 = new CountStatisticImpl("NumberOfActiveRequests", "Number Of Active Requests", "NONE", 0, 0, 0);
50         CountStatistic JavaDoc stat31 = new CountStatisticImpl("NumberOfTotalRequests", "Number Of Total Requests", "NONE", 0, 0, 0);
51         statArr1[0]=stat11;
52         statArr1[1]=stat21;
53         statArr1[2]=stat31;
54         if(lbstats == null)
55             return statArr1;
56         ClusterStats [] cstats = lbstats.getClusterStats();
57         for(ClusterStats cstat :cstats){
58             for(InstanceStats istat : cstat.getInstanceStats()){
59                 if(!istat.getId().equals(instanceName))
60                     continue;
61                     Statistic JavaDoc[] statArr = new Statistic JavaDoc[3];
62                     String JavaDoc health = istat.getHealth();
63                     long activeReq = Long.parseLong(istat.getNumActiveRequests());
64                     long totalReq = Long.parseLong(istat.getNumTotalRequests());
65                     long sampleTime = new Date JavaDoc().getTime();
66                     StringStatistic stat1 = new StringStatisticImpl("Health", "Instance Health", "NONE", startTime, sampleTime, health);
67                     CountStatistic JavaDoc stat2 = new CountStatisticImpl("NumberOfActiveRequests", "Number Of Active Requests", "NONE", startTime, sampleTime, activeReq);
68                     CountStatistic JavaDoc stat3 = new CountStatisticImpl("NumberOfTotalRequests", "Number Of Total Requests", "NONE", startTime, sampleTime, totalReq);
69                     statArr[0] = stat1;
70                     statArr[1] = stat2;
71                     statArr[2] = stat3;
72                     return statArr;
73             }
74         }
75         return null;
76     }
77
78     /** Returns the server's health status - Healthy, Unhealthy or Quiesced.
79      * @return an instance of {@link StringStatistic}
80      */

81     public StringStatistic getHealth() {
82         Statistic JavaDoc[] statArr = getStatistics();
83         return (StringStatistic)statArr[0];
84     }
85     
86     /** Returns the number of active requests on this instance
87      * @return an instance of {@link CountStatistic}
88      */

89     public CountStatistic JavaDoc getNumberOfActiveRequests() {
90         Statistic JavaDoc[] statArr = getStatistics();
91         return (CountStatistic JavaDoc)statArr[1];
92     }
93     
94     /** Returns the total number of requests for this instance.
95      * @return an instance of {@link CountStatistic}
96      */

97     public CountStatistic JavaDoc getNumberOfTotalRequests() {
98         Statistic JavaDoc[] statArr = getStatistics();
99         return (CountStatistic JavaDoc)statArr[2];
100     }
101
102
103     public LoadBalancerServerStatsImpl(String JavaDoc lbName,String JavaDoc lbConfigName,String JavaDoc clusterName,String JavaDoc instanceName) {
104         this.lbName=lbName;
105         this.clusterName=clusterName;
106         this.instanceName=instanceName;
107         this.lbConfigName=lbConfigName;
108         this.lbff = ApplicationServer.getServerContext().getPluggableFeatureFactory().getLBFeatureFactory();
109         this.startTime=new Date JavaDoc().getTime();
110    }
111     
112     public LoadBalancerServerStatsImpl() {
113     }
114     
115     private String JavaDoc instanceName = null;
116     private String JavaDoc lbName = null;
117     private String JavaDoc lbConfigName = null;
118     private String JavaDoc clusterName = null;
119     private LBFeatureFactory lbff = null;
120     private long startTime = 0;
121
122     
123 }
124
Popular Tags