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.console.jsr77;
17:
18: import javax.servlet.http.HttpSession;
19: import javax.management.j2ee.statistics.JVMStats;
20: import javax.management.j2ee.statistics.BoundedRangeStatistic;
21: import uk.ltd.getahead.dwr.WebContextFactory;
22: import org.apache.geronimo.console.util.PortletManager;
23: import org.apache.geronimo.console.util.ManagementHelper;
24: import org.apache.geronimo.management.geronimo.J2EEDomain;
25: import org.apache.geronimo.management.StatisticsProvider;
26: import org.apache.geronimo.management.geronimo.J2EEServer;
27: import org.apache.geronimo.management.geronimo.JVM;
28: import org.directwebremoting.annotations.RemoteProxy;
29:
30: /**
31: * Looks up JSR-77 statistics in response to AJAX calls from portlets.
32: *
33: * @version $Rev: 556507 $ $Date: 2007-07-15 22:37:07 -0700 (Sun, 15 Jul 2007) $
34: */
35: @RemoteProxy(name="Jsr77Stats")
36: public class Jsr77Lookup {
37: public DynamicServerInfo getJavaVMStatistics() {
38: HttpSession session = WebContextFactory.get().getSession(true);
39: ManagementHelper helper = PortletManager
40: .getManagementHelper(session);
41: J2EEDomain[] domains = helper.getDomains();
42: J2EEServer[] servers = domains[0].getServerInstances();
43: JVM[] jvms = helper.getJavaVMs(servers[0]);
44: long elapsed = System.currentTimeMillis()
45: - jvms[0].getKernelBootTime().getTime();
46: if (jvms[0].isStatisticsProvider()) {
47: JVMStats stats = (JVMStats) ((StatisticsProvider) jvms[0])
48: .getStats();
49: BoundedRangeStatistic heap = stats.getHeapSize();
50: return new DynamicServerInfo(heap.getCurrent(), heap
51: .getHighWaterMark(), heap.getUpperBound(), elapsed);
52: } else {
53: return new DynamicServerInfo(elapsed);
54: }
55: }
56: }
|