Redis Session测试通过;因为Kryo必须有一个无参数的构造方法,为减少错误几率,所以将Kryo替换为FTS工具,两者性能可忽略。

This commit is contained in:
thinkgem
2018-01-20 00:13:07 +08:00
parent 8901309e8f
commit 69a8aef269
11 changed files with 188 additions and 118 deletions

1
.gitignore vendored
View File

@@ -2,5 +2,6 @@
.project
.class
**/target
**/webapps/userfiles
**/WEB-INF/classes
**/logs/log*.log

View File

@@ -49,17 +49,21 @@
</dependency>
<!-- Java serialization -->
<!-- <dependency> -->
<!-- <groupId>com.esotericsoftware</groupId> -->
<!-- <artifactId>kryo</artifactId> -->
<!-- <version>${esotericsoftware-kryo.version}</version> -->
<!-- </dependency> -->
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>${esotericsoftware.kryo.version}</version>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>${ruedigermoeller-fst.version}</version>
</dependency>
<!-- Org json -->
<!-- Json in java -->
<dependency>
<groupId>org.codeartisans</groupId>
<artifactId>org.json</artifactId>
<version>${codeartisans.json.version}</version>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<!-- Jackson json -->

View File

@@ -12,11 +12,9 @@ import java.lang.reflect.Method;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.nustaq.serialization.FSTConfiguration;
import org.springframework.beans.BeanUtils;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.jeesite.common.io.IOUtils;
/**
@@ -109,6 +107,20 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
String str = ObjectUtils.toString(val);
return !"".equals(str) && !"null".equals(str.trim().toLowerCase()) ? str : defaultVal;
}
/**
* 拷贝一个对象(但是子对象无法拷贝)
* @param source
* @param ignoreProperties
*/
public static Object copyBean(Object source, String... ignoreProperties){
if (source == null){
return null;
}
Object target = BeanUtils.instantiate(source.getClass());
BeanUtils.copyProperties(source, target, ignoreProperties);
return target;
}
/**
* 注解到对象复制,只复制能匹配上的方法。 硕正组件用。
@@ -137,29 +149,36 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
}
}
}
/**
* 序列化对象
* @param object
* @return
*/
public static byte[] serialize(Object object) {
if (object == null){
return null;
}
long beginTime = System.currentTimeMillis();
byte[] bytes = null;
ObjectOutputStream oos = null;
ByteArrayOutputStream baos = null;
try {
if (object != null) {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
return baos.toByteArray();
}
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
bytes = baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(oos);
IOUtils.closeQuietly(baos);
}
return null;
long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){
System.out.println("Serialize time: " + TimeUtils.formatDateAgo(totalTime));
}
return bytes;
}
/**
@@ -168,13 +187,18 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
* @return
*/
public static Object unserialize(byte[] bytes) {
if (bytes == null){
return null;
}
long beginTime = System.currentTimeMillis();
Object object = null;
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try {
if (bytes != null && bytes.length > 0) {
if (bytes.length > 0) {
bais = new ByteArrayInputStream(bytes);
ois = new ObjectInputStream(bais);
return ois.readObject();
object = ois.readObject();
}
} catch (Exception e) {
e.printStackTrace();
@@ -182,66 +206,112 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
IOUtils.closeQuietly(ois);
IOUtils.closeQuietly(bais);
}
return null;
long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){
System.out.println("Unserialize time: " + TimeUtils.formatDateAgo(totalTime));
}
return object;
}
// Kryo不是线程安全的所以要建立一个线程变量每一个线程实例化一次
public static final ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
@Override
protected Kryo initialValue() {
Kryo kryo = new Kryo();
return kryo;
};
};
// // Kryo不是线程安全的所以要建立一个线程变量每一个线程实例化一次
// public static final ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
// @Override
// protected Kryo initialValue() {
// Kryo kryo = new Kryo();
// // 设置false关闭注册行为 Kryo支持对注册行为如kryo.register(SomeClazz.class);
// // 这会赋予该Class一个从0开始的编号但Kryo使用注册行为最大的问题在于
// // 其不保证同一个Class每一次注册的号码想用这与注册的顺序有关也就意味着在不同的机器、
// // 同一个机器重启前后都有可能拥有不同的编号,这会导致序列化产生问题,所以在分布式项目中,一般关闭注册行为。
// kryo.setRegistrationRequired(false);
// // 支持循环引用
// kryo.setReferences(true);
// return kryo;
// };
// };
//
// /**
// * Kryo序列化对象
// * @param object
// * @return
// */
// public static byte[] serializeKryo(Object object) {
// byte[] bytes = null;
// Output output = null;
// try {
// if (object != null) {
// output = new Output(1024, -1);
// kryos.get().writeClassAndObject(output, object);
// bytes = output.toBytes();
// }
// } catch (Exception e) {
// e.printStackTrace();
// } finally {
// if (output != null) {
// output.close();
// }
// }
// return bytes;
// }
//
// /**
// * Kryo反序列化对象
// * @param bytes
// * @return
// */
// public static Object unserializeKryo(byte[] bytes) {
// Object object = null;
// Input input = null;
// try {
// if (bytes != null && bytes.length > 0) {
// input = new Input(bytes, 0, bytes.length);
// object = kryos.get().readClassAndObject(input);
// }
// } catch (Exception e) {
// e.printStackTrace();
// } finally {
// if (input != null) {
// input.close();
// }
// }
// return object;
// }
// FST序列化配置对象
private static FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration();
/**
* Kryo序列化对象
* FST 序列化对象
* @param object
* @return
*/
public static byte[] serializeKryo(Object object) {
// long beginTime = System.currentTimeMillis();
byte[] bytes = null;
Output output = null;
try {
if (object != null) {
output = new Output(1024, -1);
kryos.get().writeClassAndObject(output, object);
bytes = output.toBytes();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (output != null) {
output.close();
}
public static byte[] serializeFst(Object object) {
if (object == null){
return null;
}
long beginTime = System.currentTimeMillis();
byte[] bytes = fst.asByteArray(object);
long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){
System.out.println("Fst serialize time: " + TimeUtils.formatDateAgo(totalTime));
}
// GlobalConfig.log(ObjectUtils.class, object + " 序列化用时:" + DateUtils.formatDateTime(System.currentTimeMillis() - beginTime));
return bytes;
}
/**
* Kryo反序列化对象
* FST 反序列化对象
* @param bytes
* @return
*/
public static Object unserializeKryo(byte[] bytes) {
// long beginTime = System.currentTimeMillis();
Object object = null;
Input input = null;
try {
if (bytes != null && bytes.length > 0) {
input = new Input(bytes, 0, bytes.length);
object = kryos.get().readClassAndObject(input);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (input != null) {
input.close();
}
public static Object unserializeFst(byte[] bytes) {
if (bytes == null){
return null;
}
long beginTime = System.currentTimeMillis();
Object object = fst.asObject(bytes);
long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){
System.out.println("Fst unserialize time: " + TimeUtils.formatDateAgo(totalTime));
}
// GlobalConfig.log(ObjectUtils.class, object + " 反序列化用时:" + DateUtils.formatDateTime(System.currentTimeMillis() - beginTime));
return object;
}
@@ -253,22 +323,8 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
if (source == null){
return null;
}
byte[] bytes = ObjectUtils.serializeKryo(source);
Object target = ObjectUtils.unserializeKryo(bytes);
return target;
}
/**
* 拷贝一个对象(但是子对象无法拷贝)
* @param source
* @param ignoreProperties
*/
public static Object copyBean(Object source, String... ignoreProperties){
if (source == null){
return null;
}
Object target = BeanUtils.instantiate(source.getClass());
BeanUtils.copyProperties(source, target, ignoreProperties);
byte[] bytes = ObjectUtils.serializeFst(source);
Object target = ObjectUtils.unserializeFst(bytes);
return target;
}

View File

@@ -86,24 +86,21 @@ jdbc:
# Redis 配置
redis:
# 是否启用 Redis
enabled: false
# Redis 连接参数
host: 192.168.11.12
host: 127.0.0.1
port: 6379
isSSL: false
timeout: 2000
password: 1234
database: 0
# 定义Key的前缀标识
keyPrefix: jeesite
# Redis 连接池配置
pool:
maxIdle: 3
maxTotal: 20
# 定义Key的前缀标识
keyPrefix: ${jdbc.tablePrefix}
# 是否启用Redis系统缓存及会话
cacheAndSession: false
@@ -312,7 +309,7 @@ session:
sessionIdCookieName: jeesite.session.id
#共享的SessionId的Cookie名称保存到跟路径下第三方应用获取。同一域名下多个项目时需设置共享Cookie的名称。
shareSessionIdCookieName: jeesite.session.id
shareSessionIdCookieName: ${session.sessionIdCookieName}
# MyBatis 相关
mybatis:

View File

@@ -95,18 +95,18 @@
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required hide">*</span> 业务主键<i class="fa icon-question hide"></i></label>
<span class="required hide">*</span> 业务类型<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:input path="bizKey" maxlength="64" class="form-control "/>
<#form:input path="bizType" maxlength="64" class="form-control "/>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required hide">*</span> 业务类型<i class="fa icon-question hide"></i></label>
<span class="required hide">*</span> 业务主键<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:input path="bizType" maxlength="64" class="form-control "/>
<#form:input path="bizKey" maxlength="64" class="form-control "/>
</div>
</div>
</div>

View File

@@ -45,18 +45,18 @@
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
<label class="control-label">业务主键:</label>
<div class="control-inline">
<#form:input path="bizKey" maxlength="64" class="form-control width-90"/>
</div>
</div>
<div class="form-group">
<label class="control-label">业务类型:</label>
<div class="control-inline">
<#form:input path="bizType" maxlength="64" class="form-control width-90"/>
</div>
</div>
<div class="form-group">
<label class="control-label">业务主键:</label>
<div class="control-inline">
<#form:input path="bizKey" maxlength="64" class="form-control width-90"/>
</div>
</div>
<div class="form-group">
<label class="control-label">操作时间:</label>
<div class="control-inline">
@@ -104,8 +104,8 @@ $('#dataGrid').dataGrid({
{header:'异常', name:'isException', index:'a.is_exception', width:60, align:"center", formatter: function(val, obj, row, act){
return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '未知', true);
}},
{header:'业务主键', name:'bizKey', index:'a.biz_key', width:90, align:"center"},
{header:'业务类型', name:'bizType', index:'a.biz_type', width:90, align:"center"},
{header:'业务主键', name:'bizKey', index:'a.biz_key', width:90, align:"center"},
{header:'操作时间', name:'createDate', index:'a.create_date', width:100, align:"center"},
{header:'客户端IP', name:'remoteAddr', index:'a.remote_addr', width:100, align:"center"},
{header:'设备名称', name:'deviceName', index:'a.device_name', width:100, align:"center"},

View File

@@ -24,8 +24,9 @@
<commons-lang3.version>3.4</commons-lang3.version>
<commons-io.version>2.5</commons-io.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<esotericsoftware.kryo.version>4.0.0</esotericsoftware.kryo.version>
<codeartisans.json.version>20130603</codeartisans.json.version>
<!-- <esotericsoftware-kryo.version>4.0.1</esotericsoftware-kryo.version> -->
<ruedigermoeller-fst.version>2.56</ruedigermoeller-fst.version>
<json.version>20170516</json.version>
<dozer.version>5.5.1</dozer.version>
<poi.version>3.14</poi.version>

View File

@@ -10,7 +10,7 @@ DROP TABLE test_tree CASCADE CONSTRAINTS;
/* Create Tables */
-- test_data
-- 测试数据
CREATE TABLE test_data
(
id varchar2(64) NOT NULL,
@@ -35,7 +35,7 @@ CREATE TABLE test_data
);
-- test_data_child
-- 测试数据子表
CREATE TABLE test_data_child
(
id varchar2(64) NOT NULL,
@@ -56,7 +56,7 @@ CREATE TABLE test_data_child
);
-- test_tree
-- 测试树表
CREATE TABLE test_tree
(
id varchar2(64) NOT NULL,
@@ -81,7 +81,7 @@ CREATE TABLE test_tree
/* Comments */
COMMENT ON TABLE test_data IS 'test_data';
COMMENT ON TABLE test_data IS '测试数据';
COMMENT ON COLUMN test_data.id IS '编号';
COMMENT ON COLUMN test_data.test_input IS '单行文本';
COMMENT ON COLUMN test_data.test_textarea IS '多行文本';
@@ -90,7 +90,7 @@ COMMENT ON COLUMN test_data.test_select_multiple IS '下拉多选';
COMMENT ON COLUMN test_data.test_radio IS '单选框';
COMMENT ON COLUMN test_data.test_checkbox IS '复选框';
COMMENT ON COLUMN test_data.test_date IS '日期选择';
COMMENT ON COLUMN test_data.test_datetime IS '日期时间选择';
COMMENT ON COLUMN test_data.test_datetime IS '日期时间';
COMMENT ON COLUMN test_data.test_user_code IS '用户选择';
COMMENT ON COLUMN test_data.test_office_code IS '部门选择';
COMMENT ON COLUMN test_data.test_company_code IS '公司选择';
@@ -100,7 +100,7 @@ COMMENT ON COLUMN test_data.create_date IS '创建时间';
COMMENT ON COLUMN test_data.update_by IS '更新者';
COMMENT ON COLUMN test_data.update_date IS '更新时间';
COMMENT ON COLUMN test_data.remarks IS '备注信息';
COMMENT ON TABLE test_data_child IS 'test_data_child';
COMMENT ON TABLE test_data_child IS '测试数据子表';
COMMENT ON COLUMN test_data_child.id IS '编号';
COMMENT ON COLUMN test_data_child.test_sort IS '排序号';
COMMENT ON COLUMN test_data_child.test_data_id IS '父表主键';
@@ -111,11 +111,11 @@ COMMENT ON COLUMN test_data_child.test_select_multiple IS '下拉多选';
COMMENT ON COLUMN test_data_child.test_radio IS '单选框';
COMMENT ON COLUMN test_data_child.test_checkbox IS '复选框';
COMMENT ON COLUMN test_data_child.test_date IS '日期选择';
COMMENT ON COLUMN test_data_child.test_datetime IS '日期时间选择';
COMMENT ON COLUMN test_data_child.test_datetime IS '日期时间';
COMMENT ON COLUMN test_data_child.test_user_code IS '用户选择';
COMMENT ON COLUMN test_data_child.test_office_code IS '部门选择';
COMMENT ON COLUMN test_data_child.test_company_code IS '公司选择';
COMMENT ON TABLE test_tree IS 'test_tree';
COMMENT ON TABLE test_tree IS '测试树表';
COMMENT ON COLUMN test_tree.id IS '编号';
COMMENT ON COLUMN test_tree.parent_code IS '父级编号';
COMMENT ON COLUMN test_tree.parent_codes IS '所有父级编号';

View File

@@ -12,7 +12,7 @@
<category_index>0</category_index>
<zoom>1.0</zoom>
<x>0</x>
<y>48</y>
<y>31</y>
<default_color>
<r>128</r>
<g>128</g>
@@ -712,7 +712,7 @@
<type>timestamp</type>
</word>
<word>
<id>3b2a776b71472966918ed6f30e56b7ebf0c7b9ec</id>
<id>38b1e9d7b26e11fab47d111ba7f951b0705aabe1</id>
<length>null</length>
<decimal>null</decimal>
<array>false</array>
@@ -723,7 +723,7 @@
<args></args>
<char_semantics>false</char_semantics>
<description></description>
<logical_name>日期时间选择</logical_name>
<logical_name>日期时间</logical_name>
<physical_name>test_datetime</physical_name>
<type>timestamp</type>
</word>
@@ -1003,7 +1003,7 @@
<connections>
</connections>
<physical_name>test_tree</physical_name>
<logical_name>test_tree</logical_name>
<logical_name>测试树表</logical_name>
<description></description>
<constraint></constraint>
<primary_key_name></primary_key_name>
@@ -1102,7 +1102,7 @@
<connections>
</connections>
<physical_name>test_data</physical_name>
<logical_name>test_data</logical_name>
<logical_name>测试数据</logical_name>
<description></description>
<constraint></constraint>
<primary_key_name></primary_key_name>
@@ -1373,7 +1373,7 @@
</sequence>
</normal_column>
<normal_column>
<word_id>3b2a776b71472966918ed6f30e56b7ebf0c7b9ec</word_id>
<word_id>38b1e9d7b26e11fab47d111ba7f951b0705aabe1</word_id>
<id>c131dc5cb7ce6f1aa5e8d5f86f2002c8ae1bb8f6</id>
<description></description>
<unique_key_name></unique_key_name>
@@ -1530,7 +1530,7 @@
<connections>
</connections>
<physical_name>test_data_child</physical_name>
<logical_name>test_data_child</logical_name>
<logical_name>测试数据子表</logical_name>
<description></description>
<constraint></constraint>
<primary_key_name></primary_key_name>
@@ -1867,7 +1867,7 @@
</sequence>
</normal_column>
<normal_column>
<word_id>3b2a776b71472966918ed6f30e56b7ebf0c7b9ec</word_id>
<word_id>38b1e9d7b26e11fab47d111ba7f951b0705aabe1</word_id>
<id>b91171b99f3628aadb0e6986fbfa30cc547b280e</id>
<description></description>
<unique_key_name></unique_key_name>

View File

@@ -22,6 +22,17 @@ jdbc:
# password: jeesite
# testSql: SELECT 1
# Redis 配置
redis:
# Redis 连接参数
host: 192.168.11.12
port: 6379
password: 1234
# 是否启用Redis系统缓存及会话
cacheAndSession: false
#============================#
#===== System settings ======#
#============================#