<?xml version="1.0" encoding="euc-kr"?>
<%@ 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.websocket.WebSocketSessionManager,org.java_websocket.WebSocket"%>
<%@ page import="java.util.concurrent.ConcurrentHashMap"%>
<%@ page import="com.eactive.eai.common.session.SessionManager,com.eactive.eai.common.session.SessionVO"%>
<%@ page import="com.eactive.eai.common.session.CacheInfoVO"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.mina.common.IoSession"%>
<%@ page import="java.util.concurrent.ConcurrentHashMap"%>
<%@ page import="net.sf.ehcache.Cache,net.sf.ehcache.Element"%>
<%@ page import="com.eactive.eai.adapter.socket2.common.ExpiringMap"%>
<%@ page import="com.eactive.eai.common.util.DatetimeUtil"%>
<%@ page import="com.eactive.eai.common.server.EAIServerManager"%>
<%@ page import="com.eactive.eai.common.session.*"%>
<Dataset>
    <Columns>
          <Column Name="eaiSvrInstNm" Type="string" Size="50" />
          <Column Name="loginUserId" Type="string" Size="50" />
          <Column Name="loginInstId" Type="string" Size="50" />
          <Column Name="wsInstId" Type="string" Size="50" />
          <Column Name="wsAdapterGroupName" Type="string" Size="50" />
          <Column Name="uuid" Type="string" Size="50" />
          <Column Name="hitCount" Type="string" Size="50" />
          <Column Name="creationTime " Type="string" Size="50" />
          <Column Name="lastAccessTime" Type="string" Size="50" />
    </Columns>
    <Rows>
<%
String eaiSvrInstNm = EAIServerManager.getInstance().getLocalServerName();
String loginUserId = request.getParameter("loginUserId");
boolean isSpUserFound = false;   
int rowCount = 0;
String spUuid = null;
try {
	SessionManager	sessionManager = SessionManager.getInstance();
  	
	if(loginUserId == null) {
		loginUserId = "";
	}
	else {
		loginUserId = loginUserId.trim();
		if(loginUserId.length() > 0) {
			isSpUserFound = true;
			for(String uuid : sessionManager.getHttpLoginCache().getKeys()) {
				SessionVO httpLogin = sessionManager.getHttpLogin(uuid);
				if( loginUserId.equals(httpLogin.getLoginUserId()) ) {    					
    				spUuid = httpLogin.getUuid();
    				break;
				}
			}			
		}
	}
	
	CacheInfoVO cache = sessionManager.getHttpLoginCache();
	if(isSpUserFound) {
		SessionVO svo = sessionManager.getHttpLogin(spUuid);
		if(svo != null) {
			rowCount++;
%>
			<Row>
			  <Data><%= eaiSvrInstNm %></Data>
			  <Data><%= svo.getLoginUserId() %></Data>
			  <Data><%= svo.getLoginInstId() %></Data>
			  <Data><%= svo.getWsInstId() %></Data>
			  <Data><%= svo.getWsAdapterGroupName() %></Data>
			  <Data><%= svo.getUuid() %></Data>			  
			</Row>
<% 
		}
	}
	else {
		String cacheName = cache.getName();
		String cacheSize = String.valueOf(cache.getSize());
		String cacheTime = String.valueOf(cache.getTimeToLiveSeconds());
		
		for(String key : cache.getKeys()) {
		    SessionVO svo = sessionManager.getHttpLogin(key);
%>
<Row>
  <Data><%= eaiSvrInstNm %></Data>
  <Data><%= svo.getLoginUserId() %></Data>
  <Data><%= svo.getLoginInstId() %></Data>
  <Data><%= svo.getWsInstId() %></Data>
  <Data><%= svo.getWsAdapterGroupName() %></Data>
  <Data><%= svo.getUuid() %></Data>
</Row>
<% 
			rowCount++;
		}
	}
	
	if(rowCount == 0) {
%>
		<Row>
		  <Data><%= eaiSvrInstNm %></Data>
		  <Data></Data>
		  <Data></Data>
		  <Data></Data>
		  <Data></Data>
		  <Data></Data>
		  <Data></Data>
		  <Data></Data>
		  <Data></Data>
		</Row>
<% 
	}
}
catch(Exception e) {
	e.printStackTrace();
	//e.printStackTrace(out);
}
%>
    </Rows>
</Dataset>
