From 4ebd92bf797ed6d4e46282903ae050c9b5fc4c5c Mon Sep 17 00:00:00 2001 From: zhuangqian Date: Thu, 5 Jan 2017 21:10:37 +0800 Subject: [PATCH] update --- .../plugins/connection/ConnectionPlugin.java | 26 ++--- .../redis/serializer/RedisSerializer.java | 107 ------------------ 2 files changed, 12 insertions(+), 121 deletions(-) delete mode 100644 src/main/java/com/smallchill/core/toolbox/redis/serializer/RedisSerializer.java diff --git a/src/main/java/com/smallchill/core/plugins/connection/ConnectionPlugin.java b/src/main/java/com/smallchill/core/plugins/connection/ConnectionPlugin.java index ff03d7ee..4b77c488 100644 --- a/src/main/java/com/smallchill/core/plugins/connection/ConnectionPlugin.java +++ b/src/main/java/com/smallchill/core/plugins/connection/ConnectionPlugin.java @@ -15,23 +15,21 @@ */ package com.smallchill.core.plugins.connection; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -import org.beetl.sql.core.IDAutoGen; -import org.beetl.sql.core.SQLManager; - -import redis.clients.jedis.JedisCluster; -import redis.clients.jedis.JedisPool; - import com.smallchill.core.config.BladeConfig; import com.smallchill.core.interfaces.IPlugin; import com.smallchill.core.toolbox.redis.IJedis; +import com.smallchill.core.toolbox.redis.IKeyNamingPolicy; import com.smallchill.core.toolbox.redis.RedisCluster; import com.smallchill.core.toolbox.redis.RedisSingle; -import com.smallchill.core.toolbox.redis.IKeyNamingPolicy; -import com.smallchill.core.toolbox.redis.serializer.RedisSerializer; +import com.smallchill.core.toolbox.redis.serializer.JdkSerializer; +import org.beetl.sql.core.IDAutoGen; +import org.beetl.sql.core.SQLManager; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.JedisPool; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class ConnectionPlugin implements IPlugin{ @@ -77,14 +75,14 @@ public class ConnectionPlugin implements IPlugin{ for(String key : BladeConfig.getJedisPool().keySet()){ JedisPool jedisPool = BladeConfig.getJedisPool().get(key); //创建redis单机操作类 - RedisSingle rs = new RedisSingle(key, jedisPool, RedisSerializer.me, IKeyNamingPolicy.defaultKeyNamingPolicy); + RedisSingle rs = new RedisSingle(key, jedisPool, JdkSerializer.me, IKeyNamingPolicy.defaultKeyNamingPolicy); redisCachePool.put(key, rs); } //注入redisCluster for(String key : BladeConfig.getJedisCluster().keySet()){ JedisCluster jedisCluster = BladeConfig.getJedisCluster().get(key); //创建redis集群操作类 - RedisCluster rc = new RedisCluster(key, jedisCluster, RedisSerializer.me, IKeyNamingPolicy.defaultKeyNamingPolicy); + RedisCluster rc = new RedisCluster(key, jedisCluster, JdkSerializer.me, IKeyNamingPolicy.defaultKeyNamingPolicy); redisCachePool.put(key, rc); } if(!redisCachePool.containsKey(MASTER) && redisCachePool.size() > 0){ diff --git a/src/main/java/com/smallchill/core/toolbox/redis/serializer/RedisSerializer.java b/src/main/java/com/smallchill/core/toolbox/redis/serializer/RedisSerializer.java deleted file mode 100644 index 5a667767..00000000 --- a/src/main/java/com/smallchill/core/toolbox/redis/serializer/RedisSerializer.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2011-2016, James Zhan 詹波 (jfinal@126.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.smallchill.core.toolbox.redis.serializer; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -import redis.clients.util.SafeEncoder; - -import com.smallchill.core.toolbox.kit.LogKit; - -/** - * RedisSerializer. - */ -public class RedisSerializer implements ISerializer { - - public static final ISerializer me = new RedisSerializer(); - - public byte[] keyToBytes(String key) { - return SafeEncoder.encode(key); - } - - public String keyFromBytes(byte[] bytes) { - return SafeEncoder.encode(bytes); - } - - public byte[] fieldToBytes(Object field) { - return valueToBytes(field); - } - - public Object fieldFromBytes(byte[] bytes) { - return valueFromBytes(bytes); - } - - public byte[] valueToBytes(Object value) { - ByteArrayOutputStream byteOut = null; - ObjectOutputStream ObjOut = null; - try { - byteOut = new ByteArrayOutputStream(); - ObjOut = new ObjectOutputStream(byteOut); - ObjOut.writeObject(value); - ObjOut.flush(); - return byteOut.toByteArray(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - finally { - try { - if (null != ObjOut) { - ObjOut.close(); - } - } - catch (IOException e) { - ObjOut = null; LogKit.error(e.getMessage(), e); - } - } - } - - public Object valueFromBytes(byte[] bytes) { - if(bytes == null || bytes.length == 0) { - return null; - } - ObjectInputStream ObjIn = null; - Object retVal = null; - try { - ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes); - ObjIn = new ObjectInputStream(byteIn); - retVal = ObjIn.readObject(); - return retVal; - } - catch (Exception e) { - throw new RuntimeException(e); - } - finally { - try { - if(null != ObjIn) { - ObjIn.close(); - } - } - catch (IOException e) { - ObjIn = null; LogKit.error(e.getMessage(), e); - } - } - } - -} - - -