<?xml version="1.0" encoding="euc-kr"?>
<%@page import="java.util.concurrent.ConcurrentMap"%>
<%@page import="java.util.concurrent.ConcurrentHashMap"%>
<%@ page contentType="text/xml; charset=utf-8"%>
<%@ page import="java.util.*,com.eactive.eai.common.util.Logger" %>
<%@ page import="java.io.*"%>
<%@ page import="com.eactive.eai.adapter.socket2.config.SocketAdapterManager"%>
<%@ page import="com.eactive.eai.common.session.SessionManager,com.eactive.eai.common.session.TerminalVO"%>
<%@ page import="java.util.*"%>
<%@ page import="com.eactive.eai.adapter.socket2.protocol.ISocketAdapter"%>
<%@ page import="org.apache.mina.common.IoSession"%>
<%@ page import="net.sf.ehcache.Cache,net.sf.ehcache.Element"%>
<%@ page import="net.sf.ehcache.Cache"%>
<%@ page import="com.eactive.eai.adapter.socket2.common.ExpiringMap"%>
<%@ page import="com.eactive.eai.adapter.socket2.common.TimeUtil"%>
<%@ page import="com.eactive.eai.common.server.EAIServerManager"%>
<Dataset>
    <Columns>
          <Column Name="eaiSvrInstNm" Type="string" Size="50" />
          <Column Name="adapterGroupName" Type="string" Size="50" />
          <Column Name="terminalNo" Type="string" Size="50" />
          <Column Name="localSocketAddress" Type="string" Size="50" />
          <Column Name="remoteSocketAddress" Type="string" Size="50" />
          <Column Name="createTime" Type="string" Size="20" />
          <Column Name="idleTime" Type="string" Size="20" />
    </Columns>
    <Rows>
<%
	String eaiSvrInstNm = EAIServerManager.getInstance().getLocalServerName();
    //String terminalNo = request.getParameter("terminalNo");
    String terminalNo = "";
    //boolean isSpUserFound = false;   
	int rowCount = 0;
	try {
	/*
    	if(terminalNo == null) {
    		terminalNo = "";
    	}
    	else {
    		SessionManager	sessionManager = SessionManager.getInstance();
    	  	terminalNo = terminalNo.trim();
    		if(terminalNo.length() > 0) {
    			isSpUserFound = true;
    			Cache lcache = sessionManager.getTerminalCache();
    			Element el = lcache.get(terminalNo);
    			if(el != null) {
    		    	TerminalVO svo = (TerminalVO)el.getValue();
    			}
    		}
    	}
    	*/
    	ConcurrentMap<String, ConcurrentHashMap<String, ISocketAdapter>> adapterGroups = SocketAdapterManager.getInstance().getSocketAdapterGroups();
		for (String adapterGroupName : adapterGroups.keySet()) {
			ConcurrentHashMap<String, ISocketAdapter> adapters = adapterGroups.get(adapterGroupName);
	    	for (Map.Entry<String, ISocketAdapter> entry : adapters.entrySet()) {
	    		ISocketAdapter adapter = entry.getValue();
		    	if ("!XC3EPB".equals(adapter.getContext().getProtocol())){
		    		continue;
		    	}
		    	for (Iterator<IoSession> iii = adapter.getSessionPool().iterator() ; iii.hasNext(); ) {
			    	IoSession session1 = iii.next();
			    	TerminalVO vo = (TerminalVO)session1.getAttribute("TERMINAL_KEY");
			    	if (vo != null){
			    		terminalNo = vo.getTerminalNo();
			    	}
	%>
<Row>
  <Data><%= eaiSvrInstNm %></Data>
  <Data><%= adapterGroupName %></Data>
  <Data><%= terminalNo %></Data>
  <Data><%= session1.getLocalAddress() %></Data>
  <Data><%= session1.getRemoteAddress() %></Data>
  <Data><%= TimeUtil.formatDate(session1.getCreationTime())%></Data>
  <Data><%= TimeUtil.elapsedTime(session1.getLastIoTime())%></Data>
</Row>	
	<%			    	
			    }
		    }
		}
	}catch(Exception e){
	}
	%>
    </Rows>
</Dataset>