01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. 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: */package org.apache.geronimo.monitoring;
17:
18: import java.net.URI;
19: import java.util.HashSet;
20: import java.util.Iterator;
21: import java.util.Set;
22:
23: import javax.management.ObjectName;
24:
25: import org.apache.geronimo.kernel.Kernel;
26: import org.apache.geronimo.kernel.KernelRegistry;
27:
28: import org.apache.geronimo.gbean.AbstractName;
29: import org.apache.geronimo.gbean.AbstractNameQuery;
30:
31: public class MBeanHelper {
32:
33: /**
34: * Return all MBeans that provide stats
35: */
36: public static Set<String> getStatsProvidersMBeans(
37: Set<String> allMBeans) {
38: Kernel kernel = KernelRegistry.getSingleKernel();
39: Set<String> result = new HashSet();
40:
41: try {
42: for (Iterator it = allMBeans.iterator(); it.hasNext();) {
43: try {
44: String mbeanName = (String) it.next();
45: Boolean statisticsProvider = (Boolean) kernel
46: .getAttribute(new ObjectName(mbeanName),
47: "statisticsProvider");
48: if (Boolean.TRUE.equals(statisticsProvider)) {
49: result.add(mbeanName);
50: }
51: } catch (Exception e) {
52: // this will happen if there is not a matching attribute "statisticsProvider"
53: }
54: }
55: } catch (Exception e) {
56: e.printStackTrace();
57: }
58:
59: return result;
60: }
61: }
|