Package org.jvnet.glassfish.comms.admin.gui.extensions.handlers

Source Code of org.jvnet.glassfish.comms.admin.gui.extensions.handlers.SipCallFlowHandlers

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License").  You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code.  If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license."  If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above.  However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.jvnet.glassfish.comms.admin.gui.extensions.handlers;

import com.sun.appserv.management.monitor.CallFlowMonitor;
import com.sun.enterprise.tools.admingui.util.GuiUtil;
import org.jvnet.glassfish.comms.admin.gui.extensions.util.SipUtil;
import com.sun.enterprise.tools.admingui.handlers.CallFlowHandlers;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import com.sun.jsftemplating.util.MessageUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
import java.text.NumberFormat;

public class SipCallFlowHandlers {

    /**
     *  <p> This handler returns all the info necessary to display the call flow detailpage.
   *  The handler is called from the SipUtilities file using reflection.
     *  @param  context The HandlerContext.
     *
     */
    public static void updateCallFlowDetail(HandlerContext handlerCtx) {

        HashMap infoMap = new HashMap((Map)handlerCtx.getInputValue("infoMap"));
        String requestId = (String) handlerCtx.getInputValue("requestId");
        String instanceName = (String) handlerCtx.getInputValue("instanceName");

        CallFlowMonitor cfm = CallFlowHandlers.getCallFlowMonitor(instanceName);
        float total = 0;
        MessageUtil msgUtil = MessageUtil.getInstance();
        Map<String, String> timeSpendMap = null;
        timeSpendMap = (Map<String,String>) cfm.queryPieInformation(requestId);

        for(String key : timeSpendMap.keySet()){
            total += Float.parseFloat(timeSpendMap.get(key));
        }

        NumberFormat nf = NumberFormat.getInstance(GuiUtil.getLocale());
        nf.setMinimumFractionDigits(1);

        String ms = null;
        float percent = 0;
        String percentStr = "";

        List valueList = new ArrayList();
        List labels = new ArrayList();
        Set set = infoMap.keySet();
        Iterator iter = set.iterator();
        while(iter.hasNext())
        {
            if(iter.next().equals("xLabels"))
            {
               labels = (ArrayList) infoMap.get("xLabels");
            }
        }

        if (timeSpendMap.containsKey("SIP_APPLICATION")){
            infoMap.put("hasSipApp", true);
            ms = timeSpendMap.get("SIP_APPLICATION");
            percent =  Float.parseFloat(ms)/total * 100;
            percentStr = nf.format(percent);
            infoMap.put("sipApp", CallFlowHandlers.formatStr("callFlowDetail.percentMs", percentStr, ms));
            labels.add(sipChartLabelMap(msgUtil.getMessage(SipUtil.SIP_RESOURCE_BUNDLE, "callFlowDetail.chart.sipApp"), percent, percentStr, ms)
);
        }else{
            infoMap.put("hasSipApp", false);
            labels.add(CallFlowHandlers.emptyMap(msgUtil.getMessage(SipUtil.SIP_RESOURCE_BUNDLE, "callFlowDetail.chart.sipApp")));
        }

        Collections.sort(labels, new CallFlowHandlers.TimeSpentComparator());

        infoMap.put("xLabels", labels);
        for(int i=0;  i < labels.size() ;  i++){
            Float ff = (Float) ((Map)labels.get(i)).get("compValue");
            valueList.add( Math.round(ff));
        }

        Map vMap = new HashMap();
        vMap.put("color", "green");
        vMap.put("values", valueList);

        List vList = new ArrayList();
        vList.add(vMap);
        infoMap.put("valueList", vList);

        handlerCtx.setOutputValue("detailInfo", infoMap);

    }

    public static Map sipChartLabelMap(String key, float percent, String percentStr, String ms ){
        Map aMap = new HashMap();
        MessageUtil msgUtil = MessageUtil.getInstance();
        aMap.put("label", msgUtil.getMessage(SipUtil.SIP_RESOURCE_BUNDLE, "callFlowDetail.chart.sipApp"));
        String formattedString = msgUtil.getMessage(SipUtil.SIP_RESOURCE_BUNDLE, "callFlowDetail.chart.sipApp"+"DD", new Object[]{percent, CallFlowHandlers.convertNanoToMs(ms)});

        aMap.put("title", formattedString);
        aMap.put("compValue", Float.valueOf(percent));
        return aMap;
    }
}
TOP

Related Classes of org.jvnet.glassfish.comms.admin.gui.extensions.handlers.SipCallFlowHandlers

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.