KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > core > stats > cmc > GetStatsJMX


1
2 /*
3  * Copyright 2002 by
4  * <a HREF="http://www.coridan.com">Coridan</a>
5  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with the
9  * License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is "MantaRay" (TM).
18  *
19  * The Initial Developer of the Original Code is lital kasif.
20  * Portions created by the Initial Developer are Copyright (C) 2006
21  * Coridan Inc. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source
24  * code where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
35  
36  *
37  * This library is free software; you can redistribute it and/or modify it
38  * under the terms of the MPL as stated above or under the terms of the GNU
39  * Lesser General Public License as published by the Free Software Foundation;
40  * either version 2.1 of the License, or any later version.
41  *
42  * This library is distributed in the hope that it will be useful, but WITHOUT
43  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
45  * License for more details.
46  */
/*
47  * Created on Sep 26, 2004
48  */

49 package org.mr.core.stats.cmc;
50
51 import org.mr.MantaAgent;
52 import org.apache.commons.logging.Log;
53 import org.apache.commons.logging.LogFactory;
54 import org.mr.core.stats.StatManager;
55
56 import javax.management.*;
57
58 /**
59  * @author lital kasif
60  *
61  * returns various agent stats, such as memory usage, message & byte count.
62  */

63 public class GetStatsJMX extends StandardMBean implements GetStatsJMXMBean {
64     public Log log;
65     
66     public GetStatsJMX()throws NotCompliantMBeanException{
67         super(GetStatsJMXMBean.class);
68         log=LogFactory.getLog("GetStatsJMX");
69     }
70
71     
72     /**
73      * gets stats of the agent
74      * @return a String with all the stats.
75      */

76     public String JavaDoc[] getStatsString() {
77         StatManager manager = MantaAgent.getInstance().getSingletonRepository().getStatManager();
78         CMCAgentStats stats = manager.getCurrentCMCStats();
79         String JavaDoc[] result = { "last five minutes bytes = "+stats.getFiveMinBytes(),
80                             "total bytes = "+stats.getTotalBytes(),
81                             "last five minutes messages = "+stats.getFiveMinMessages(),
82                             "total messages = "+stats.getTotalMessages(),
83                             "free memory = "+stats.getFreeMem(),
84                             "total memory = "+stats.getTotalMem()};
85         return result;
86     }
87
88     protected String JavaDoc getDescription(MBeanInfo i_mBeanInfo) {
89         return "returns various stats of the peer (memory usage, message & byte count)";
90     }
91
92     protected String JavaDoc getDescription(MBeanAttributeInfo i_mBeanAttributeInfo) {
93         if(i_mBeanAttributeInfo.getName().equals("StatsString"))
94             return "returns the current stats of the peer in a String.";
95         return "gets the current stats of the peer";
96     }
97
98 }
99
100
101
Popular Tags