This commit is contained in:
thinkgem
2018-09-24 12:21:15 +08:00
parent 34125ee274
commit 2717f036ec
2 changed files with 9 additions and 12 deletions

View File

@@ -158,7 +158,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
* @param object * @param object
* @return * @return
*/ */
public static <T> byte[] serialize(T object) { public static byte[] serialize(Object object) {
if (object == null){ if (object == null){
return null; return null;
} }
@@ -183,17 +183,16 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
* @param bytes * @param bytes
* @return * @return
*/ */
@SuppressWarnings("unchecked") public static Object unserialize(byte[] bytes) {
public static <T> T unserialize(byte[] bytes) {
if (bytes == null){ if (bytes == null){
return null; return null;
} }
long beginTime = System.currentTimeMillis(); long beginTime = System.currentTimeMillis();
T object = null; Object object = null;
if (bytes.length > 0) { if (bytes.length > 0) {
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes); try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);) { ObjectInputStream ois = new ObjectInputStream(bais);) {
object = (T)ois.readObject(); object = ois.readObject();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -217,7 +216,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
* @param object * @param object
* @return * @return
*/ */
public static <T> byte[] serializeFst(T object) { public static byte[] serializeFst(Object object) {
if (object == null){ if (object == null){
return null; return null;
} }
@@ -235,13 +234,12 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
* @param bytes * @param bytes
* @return * @return
*/ */
@SuppressWarnings("unchecked") public static Object unserializeFst(byte[] bytes) {
public static <T> T unserializeFst(byte[] bytes) {
if (bytes == null){ if (bytes == null){
return null; return null;
} }
long beginTime = System.currentTimeMillis(); long beginTime = System.currentTimeMillis();
T object = (T)fst.get().asObject(bytes); Object object = fst.get().asObject(bytes);
long totalTime = System.currentTimeMillis() - beginTime; long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){ if (totalTime > 3000){
System.out.println("Fst unserialize time: " + TimeUtils.formatDateAgo(totalTime)); System.out.println("Fst unserialize time: " + TimeUtils.formatDateAgo(totalTime));
@@ -253,12 +251,12 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
* 克隆一个对象(完全拷贝) * 克隆一个对象(完全拷贝)
* @param source * @param source
*/ */
public static <T> T cloneBean(T source){ public static Object cloneBean(Object source){
if (source == null){ if (source == null){
return null; return null;
} }
byte[] bytes = ObjectUtils.serializeFst(source); byte[] bytes = ObjectUtils.serializeFst(source);
T target = ObjectUtils.unserializeFst(bytes); Object target = ObjectUtils.unserializeFst(bytes);
return target; return target;
} }

View File

@@ -80,7 +80,6 @@ caffeine.region.sessionCache = 100000, 30m
#redis storage mode (generic|hash) #redis storage mode (generic|hash)
redis.storage = generic redis.storage = generic
#redis.storage = hash
## redis pub/sub channel name ## redis pub/sub channel name
redis.channel = j2cache redis.channel = j2cache