first commit

This commit is contained in:
2025-02-20 14:59:35 +08:00
parent d7be84fac6
commit d4a3bb8ffc
2541 changed files with 336536 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/zhiqim.jar" sourcepath="libsrc/zhiqim-src.jar"/>
<classpathentry kind="lib" path="lib/zhiqim_httpd.jar" sourcepath="libsrc/zhiqim_httpd-src.jar"/>
<classpathentry kind="lib" path="lib/zhiqim_orm.jar" sourcepath="libsrc/zhiqim_orm-src.jar"/>
<classpathentry kind="lib" path="lib/zhiqim_ui.jar"/>
<classpathentry kind="lib" path="lib/zhiqim_zml.jar" sourcepath="libsrc/zhiqim_zml-src.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+2
View File
@@ -0,0 +1,2 @@
/bin
/logs
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>zhiqim_sessioner</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ZHIQIM-CONFIG PUBLIC "-//ZHIQIM //DTD Zhiqim-Config Configuration 1.5.0//EN" "http://zhiqim.org/xmldtds/zhiqim_config_1_5_0.dtd">
<zhiqim-config>
<group id="httpd" desc="WEB服务器">
<item key="context" value="httpd.root" type="protected" desc="必须,WEB服务下包括的上下文环境表,多个用逗号隔开" />
<item key="scheme" value="HTTP" type="protected" desc="HTTP或HTTPS协议" />
<item key="port" value="10180" type="protected" desc="监听端口" />
<item key="minPoolSize" value="5" type="protected" desc="HTTP处理线程池最小值" />
<item key="maxPoolSize" value="10" type="protected" desc="HTTP处理线程池最大值" />
</group>
<group id="httpd.root" desc="WEB服务根上下文环境">
<item key="path" value="/" type="protected" desc="必须,上下文环境路径" />
<item key="resourceType" value="directory" type="protected" desc="资源目录类型classpath|directory" />
<item key="resourcePath" value="./resource" type="protected" desc="资源目录" />
<item key="welcomeUrl" value="/index.htm" type="protected" desc="欢迎页" />
<item key="zmr.orm" value="orm" type="protected" desc="管理台对应的数据库映射" />
<item key="rmi.sessioner" value="58fda2df" type="protected" desc="管理台对应的数据库映射" />
</group>
</zhiqim-config>
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ZHIQIM-CONFIG PUBLIC "-//ZHIQIM //DTD Zhiqim-Config Configuration 1.5.0//EN" "http://zhiqim.org/xmldtds/zhiqim_config_1_5_0.dtd">
<zhiqim-config>
<group id="logging" desc="日志配置">
<item key="logging.info" value="debug-info" type="protected" desc="信息日志配置" />
<item key="logging.error" value="error-fatal" type="protected" desc="错误日志配置" />
</group>
<group id="logging.info" desc="信息日志配置">
<item key="console.out" value="true" type="protected" desc="是否输出到控制台" />
<item key="file.out" value="true" type="protected" desc="是否输出到文件" />
<item key="file.path" value="./logs/info.log" type="protected" desc="输出到文件路径" />
</group>
<group id="logging.error" desc="错误日志配置">
<item key="console.out" value="true" type="protected" desc="是否输出到控制台" />
<item key="file.out" value="true" type="protected" desc="是否输出到文件" />
<item key="file.path" value="./logs/error.log" type="protected" desc="输出到文件路径" />
</group>
</zhiqim-config>
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ZHIQIM-CONFIG PUBLIC "-//ZHIQIM //DTD Zhiqim-Config Configuration 1.5.0//EN" "http://zhiqim.org/xmldtds/zhiqim_config_1_5_0.dtd">
<zhiqim-config>
<group id="boot" desc="系统启动引导配置">
<item key="name" value="知启蒙会话管理器" type="protected" desc="系统名称" />
<item key="version" value="V1.5.0" type="protected" desc="系统版本" />
<item key="port" value="50180" type="protected" desc="系统监听端口,用于启动监听和命令关闭工程" />
<item key="home" value="d:/Java/jdk1.7.0_80/" type="protected" desc="JDK根目录" />
<item key="process" value="zhiqim_sessioner" type="protected" desc="使用的进程名" />
<item key="args" value="-server -Xms64m -Xmx1024m" type="protected" desc="JVM参数" />
</group>
<group id="config" desc="系统其他配置文件,./开头表示工程相对路径下,绝对路径使用/或d:/等(Windows也使用顺斜杠作路径)">
<item key="logging" value="./conf/logging.xml" type="protected" desc="日志配置"/>
<item key="httpd" value="./conf/httpd.xml" type="protected" desc="HTTPD配置"/>
</group>
<group id="service" desc="系统服务配置,有依赖时注意顺序,系统按顺序加载,按倒序销毁">
<item key="logging" value="org.zhiqim.kernel.logging.LogServer" type="protected" desc="日志服务"/>
<item key="logcutter" value="org.zhiqim.kernel.logging.LogLinuxNohupCutter" type="protected" desc="日志LinuxNohup切割服务"/>
<item key="httpd" value="org.zhiqim.httpd.HttpServer" type="protected" desc="HTTP服务"/>
<item key="sessioner" value="org.zhiqim.httpd.sessioner.Sessioner" type="protected" desc="会话服务"/>
</group>
<group id="sessioner" desc="数据库映射服务">
<item key="session.timeout" value="1800" type="protected" desc="会话超时时长,单位:秒,最小20秒,未配置缺省1800秒(30分钟)" />
<item key="session.idName" value="jsessionid" type="protected" desc="cookie或redirect-url时的取sessionid的名称,未配置缺省jsessionid" />
</group>
</zhiqim-config>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<section name="Fadfox">
<section name="ExportProject">
<item value="release,logs/*" key="excludeDirs"/>
<item value="" key="excludePackages"/>
<item value="release,logs/*,document,libsrc" key="excludeResourceDirs"/>
<item value="false" key="isDivided"/>
<item value="true" key="isExportAndZipProject"/>
<item value="false" key="isExportJavaSource"/>
<item value="true" key="isGenExe"/>
<item value="true" key="isGenZip"/>
<item value="false" key="isIncludeJavaFile"/>
<item value="zhiqim_sessioner" key="jarName"/>
<item value="" key="metaInfoPath"/>
<item value="" key="projectConfPath"/>
<item value="zhiqim_sessioner_v1.5.0" key="projectSourceName"/>
<item value="zhiqim_sessioner" key="releaseName"/>
<item value="D:/_gitee/zhiqim/V1.5.0/ZhiqimDK" key="releasePath"/>
</section>
</section>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ZHIQIM-CONTEXT PUBLIC "-//ZHIQIM //DTD Zhiqim-Context Configuration 1.5.0//EN" "http://zhiqim.org/xmldtds/zhiqim_context_1_5_0.dtd">
<zhiqim-context>
<!-- 属性配置 -->
<attribute name="系统名称" key="name" value="知启蒙管理台"/>
<attribute name="系统版本" key="version" value="V1.5.0"/>
</zhiqim-context>
+12
View File
@@ -0,0 +1,12 @@
<#---------------------------------------------------->
<#-- 以下为变量定义 ------------------------>
<#---------------------------------------------------->
<#var name="知启蒙会话管理器"/>
<#var version="V1.5.0"/>
<#var keywords="知启蒙 开源 zhiqim zhiqimeng ZhiqimDK ZhiqimStudio ZhiqimPM"/>
<#var description="湖南知启蒙科技有限公司致力打造求知-启蒙的程序员社区、程序员文学、程序搜索、技术即服务平台"/>
<#---------------------------------------------------->
<#-- 以下为函数定义 ------------------------>
<#---------------------------------------------------->
+18
View File
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="${keywords}">
<meta name="description" content="${description}">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=no">
<title>${name}</title>
${Styles.htmlOverflowHidden()}
</head>
<body>
<div style="position:absolute;margin:auto;top:0;bottom:0;left:0;right:0;width:100%;height:100%;display:table;">
<div style="display:table-cell;font-size:60px;font-weight:bold;text-align:center;vertical-align:middle;">${name}</div>
</div>
</body>
</html>
@@ -0,0 +1,143 @@
/*
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
*
* 知启蒙WEB容器(zhiqim_httpd)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_httpd.htm
*
* This file is part of [zhiqim_httpd].
*
* [zhiqim_httpd] is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* [zhiqim_httpd] is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with [zhiqim_httpd].
* If not, see <http://www.gnu.org/licenses/>.
*/
package org.zhiqim.httpd.sessioner;
import org.zhiqim.kernel.json.Jsons;
/**
* HTTP会话对象
*
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
*/
public class Session
{
private String oldSessionId;
private String sessionId;
private long created;
private long accessed;
private int maxInactiveInterval;
private String sessionIp;
private String userAgent;
private String sessionUser;
private String attributes;
public String getOldSessionId()
{
return oldSessionId;
}
public void setOldSessionId(String oldSessionId)
{
this.oldSessionId = oldSessionId;
}
public String getSessionId()
{
return sessionId;
}
public void setSessionId(String sessionId)
{
this.sessionId = sessionId;
}
public long getCreated()
{
return created;
}
public void setCreated(long created)
{
this.created = created;
}
public long getAccessed()
{
return accessed;
}
public void setAccessed(long accessed)
{
this.accessed = accessed;
}
public int getMaxInactiveInterval()
{
return maxInactiveInterval;
}
public void setMaxInactiveInterval(int maxInactiveInterval)
{
this.maxInactiveInterval = maxInactiveInterval;
}
public String getSessionIp()
{
return sessionIp;
}
public void setSessionIp(String sessionIp)
{
this.sessionIp = sessionIp;
}
public String getUserAgent()
{
return userAgent;
}
public void setUserAgent(String userAgent)
{
this.userAgent = userAgent;
}
public String getSessionUser()
{
return sessionUser;
}
public void setSessionUser(String sessionUser)
{
this.sessionUser = sessionUser;
}
public String getAttributes()
{
return attributes;
}
public void setAttributes(String attributes)
{
this.attributes = attributes;
}
/**********************************************/
//清理和转换成字符串
/**********************************************/
public String toString()
{
return Jsons.toString(this);
}
}
@@ -0,0 +1,288 @@
/*
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
*
* 知启蒙WEB容器(zhiqim_httpd)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_httpd.htm
*
* This file is part of [zhiqim_httpd].
*
* [zhiqim_httpd] is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* [zhiqim_httpd] is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with [zhiqim_httpd].
* If not, see <http://www.gnu.org/licenses/>.
*/
package org.zhiqim.httpd.sessioner;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.zhiqim.httpd.HttpdConstants;
import org.zhiqim.kernel.Global;
import org.zhiqim.kernel.Servicer;
import org.zhiqim.kernel.annotation.AnFilterNot;
import org.zhiqim.kernel.extend.HashMapSV;
import org.zhiqim.kernel.json.Jsons;
import org.zhiqim.kernel.schedule.Interval;
import org.zhiqim.kernel.schedule.Task;
import org.zhiqim.kernel.util.Asserts;
/**
* Hash会话管理器,通过HashMap对会话进行管理
*
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
*/
public class Sessioner extends Servicer implements Task, HttpdConstants
{
private int sessionTimeout;
private String sessionIdName;
private HashMapSV<Session> sessionMap;
private Interval interval;
/** 创建服务 */
public boolean create() throws Exception
{
this.sessionTimeout = Global.getInt(id, "session.timeout", 30 * 60);
this.sessionIdName = Global.getString(id, "session.idName", _JSESSIONID_);
this.sessionMap = new HashMapSV<>(999, true);
this.interval = Interval.shedule(this, 29 * 1000);//定义29秒检查一次,保证最小1分钟清除即可,太频繁也不大合适
return true;
}
/** 销毁服务 */
public void destroy()
{
if (this.interval != null)
{
this.interval.close();
this.interval = null;
}
if (this.sessionMap != null)
{
this.sessionMap.clear();
this.sessionMap = null;
}
}
/**************************************************/
//获取参数部分
/**************************************************/
/** 获取会话编号名称 */
public String getSessionIdName()
{
return sessionIdName;
}
/** 获取超时时长 */
public int getSessionTimeout()
{
return sessionTimeout;
}
/**************************************************/
//设置 & 获取 & 失效 会话
/**************************************************/
/** 设置一个会话 */
@AnFilterNot
public void setSession(String sessionInfo)
{
Session session = Jsons.toObject(sessionInfo, Session.class);
sessionMap.put(session.getSessionId(), session);
}
/** 通过会话编号获取会话对象 */
public String getSession(String sessionId)
{
Session session = sessionMap.get(sessionId);
return Jsons.toString(session);
}
/** 判断会话是否存在 */
public boolean hasSession(String sessionId)
{
return sessionMap.containsKey(sessionId);
}
/** 删除一个会话,指定会话编号 */
public void invalidateSession(String sessionId)
{
sessionMap.remove(sessionId);
}
/** 更新会话最后访问时间 */
public void updateLastAccessed(String sessionId)
{
Session session = sessionMap.get(sessionId);
if (session == null)
return;
session.setAccessed(System.currentTimeMillis());
}
/** 更新会话信息 */
@AnFilterNot
public void updateInfo(String sessionId, String sessionIp, String userAgent)
{
Session session = sessionMap.get(sessionId);
if (session == null)
return;
session.setAccessed(System.currentTimeMillis());
session.setSessionId(sessionId);
session.setUserAgent(userAgent);
}
/******************************************************************************************/
//会话查询和统计
/******************************************************************************************/
/** 查会话数 */
public int size()
{
return sessionMap.size();
}
/** 获取会话列表 */
public String getSessionList()
{
return Jsons.toString(sessionMap.values());
}
/** 获取会话分页信息 */
public String getSessionList(int pageNo, int pageSize)
{
int size = sessionMap.size();
if (size == 0)
return "[]";
int pageNoMax = (size-1) / pageSize + 1;
if (pageNo < 1) pageNo = 1;
if (pageNo > pageNoMax) pageNo = pageNoMax;
int start = (pageNo-1) * pageSize;
int end = pageNo * pageSize;
ArrayList<Session> list = new ArrayList<>();
Iterator<Session> it = sessionMap.values().iterator();
for (int i=0;it.hasNext();i++)
{
Session s = it.next();
if (i < start)
continue;
else if (i >= end)
break;
else
list.add(s);
}
return Jsons.toString(list);
}
/******************************************************************************************/
//会话用户查询和统计
/******************************************************************************************/
/** 查用户数,有登录状态 */
public int sizeUser()
{
int size = 0;
for (Session s : sessionMap.values())
{
if (s.getSessionUser() != null)
size++;
}
return size;
}
/** 是否有会话名称对应的会话 */
public boolean hasSessionName(String sessionName)
{
Asserts.notNull(sessionName, "sessionName");
for (Session s : sessionMap.values())
{
String sessionUser = s.getSessionUser();
if (sessionUser == null)
continue;
if (sessionName.equals(Jsons.getString(sessionUser, "sessionName")))
return true;
}
return false;
}
/** 获取会话登录用户列表,指定会话用户类名(如前后端共用session管理器的情况) */
public String getSessionUserList()
{
List<String> list = new ArrayList<>();
for (Session s : sessionMap.values())
{
String sessionUser = s.getSessionUser();
if (sessionUser != null)
list.add(sessionUser);
}
return Jsons.toString(list);
}
/** 获取会话登录用户分页信息,指定会话用户类名(如前后端共用session管理器的情况) */
public String getSessionUserList(int pageNo, int pageSize)
{
if (pageNo < 1) pageNo = 1;
int start = (pageNo-1) * pageSize;
int end = pageNo * pageSize;
int total = 0;
List<String> list = new ArrayList<>();
for (Session s : sessionMap.values())
{
String sessionUser = s.getSessionUser();
if (sessionUser == null)
continue;
total++;
if (total <= start || total > end)
continue;//非当前页
else
list.add(sessionUser);
}
return Jsons.toString(list);
}
/********************************************************************/
//定时任务
/********************************************************************/
/** 定时检查超时用户 */
public void execute()
{
for (Iterator<Session> it=sessionMap.values().iterator();it.hasNext();)
{
Session session = it.next();
if (session.getMaxInactiveInterval() <= 0)
continue;//设置为0或负数表示永驻内存
if(System.currentTimeMillis()-session.getAccessed() < session.getMaxInactiveInterval() * 1000)
continue;//未超时
//已超时清理
it.remove();
session = null;
}
}
}