<%@ include file= "../../EgTrackerAJSON.jsp"%>
<%@ page import = "java.io.*"%>
<%@ page import = "java.util.*"%>
<%@ page import="com.eg.EgURLEncoder" %>
<%@ page import = "com.eg.EgURLDecoder"%>
<%@ page import = "com.eg.RemoteControlTaskHelper"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import="net.sf.json.*" %>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%
	JSONObject rootJSON = new JSONObject();
	rootJSON.put("success","true");

	response.setContentType("application/json;charset=UTF-8");
	String agentID = EgURLDecoder.decode(request.getParameter("componentName"),"UTF-8");
	boolean timedout = true;
	if(agentID != null && agentID.length()>0 && agentID.indexOf(":")>0)
	{
		agentID = agentID.substring(0,agentID.indexOf(":"));
	}
	RemoteControlTaskHelper helper = new RemoteControlTaskHelper();
	if(helper.setAgentIntoControlMode(agentID))
	{
		helper.executeTask("GetXmxValue", session.getId(), "");
		if(helper.isOutputAvailable())
		{
			ArrayList lines = helper.getOutput();
			if(lines != null && !lines.isEmpty())
			{
				timedout = false;
				String line = (String)lines.get(0);
				if(line.equalsIgnoreCase("\"${JVM_MEMORY}\"m") || line.equalsIgnoreCase("\"${JVM_MEMORY}\""))
				{
					line = "-";
				}
				rootJSON.put("XmxValue",line);
			}
		}
	}
	rootJSON.put("timedout",timedout);
	if(request.getQueryString()!= null)
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgAgentXmxView.jsp?"+request.getQueryString());
	}
	else
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgAgentXmxView.jsp");
	}
	out.println(rootJSON);
%>