Package org.apache.geronimo.console.jsr77

Source Code of org.apache.geronimo.console.jsr77.Jsr77Lookup

/**
*  Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  See the NOTICE file distributed with
*  this work for additional information regarding copyright ownership.
*  The ASF licenses this file to You under the Apache License, Version 2.0
*  (the "License"); you may not use this file except in compliance with
*  the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package org.apache.geronimo.console.jsr77;

import javax.servlet.http.HttpSession;
import javax.management.j2ee.statistics.JVMStats;
import javax.management.j2ee.statistics.BoundedRangeStatistic;
import uk.ltd.getahead.dwr.WebContextFactory;
import org.apache.geronimo.console.util.PortletManager;
import org.apache.geronimo.console.util.ManagementHelper;
import org.apache.geronimo.management.geronimo.J2EEDomain;
import org.apache.geronimo.management.StatisticsProvider;
import org.apache.geronimo.management.geronimo.J2EEServer;
import org.apache.geronimo.management.geronimo.JVM;

/**
* Looks up JSR-77 statistics in response to AJAX calls from portlets.
*
* @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
*/
public class Jsr77Lookup {
    public DynamicServerInfo getJavaVMStatistics() {
        HttpSession session = WebContextFactory.get().getSession(false);
        ManagementHelper helper = PortletManager.getManagementHelper(session);
        J2EEDomain[] domains = helper.getDomains();
        J2EEServer[] servers = domains[0].getServerInstances();
        JVM[] jvms = helper.getJavaVMs(servers[0]);
        long elapsed = System.currentTimeMillis() - jvms[0].getKernelBootTime().getTime();
        if(jvms[0].isStatisticsProvider()) {
            JVMStats stats = (JVMStats) ((StatisticsProvider)jvms[0]).getStats();
            BoundedRangeStatistic heap = stats.getHeapSize();
            return new DynamicServerInfo(heap.getCurrent(), heap.getHighWaterMark(), heap.getUpperBound(), elapsed);
        } else {
            return new DynamicServerInfo(elapsed);
        }
    }
}
TOP

Related Classes of org.apache.geronimo.console.jsr77.Jsr77Lookup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.