update
This commit is contained in:
parent
0a5a5bc58a
commit
4ebd92bf79
|
|
@ -15,23 +15,21 @@
|
||||||
*/
|
*/
|
||||||
package com.smallchill.core.plugins.connection;
|
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.config.BladeConfig;
|
||||||
import com.smallchill.core.interfaces.IPlugin;
|
import com.smallchill.core.interfaces.IPlugin;
|
||||||
import com.smallchill.core.toolbox.redis.IJedis;
|
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.RedisCluster;
|
||||||
import com.smallchill.core.toolbox.redis.RedisSingle;
|
import com.smallchill.core.toolbox.redis.RedisSingle;
|
||||||
import com.smallchill.core.toolbox.redis.IKeyNamingPolicy;
|
import com.smallchill.core.toolbox.redis.serializer.JdkSerializer;
|
||||||
import com.smallchill.core.toolbox.redis.serializer.RedisSerializer;
|
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{
|
public class ConnectionPlugin implements IPlugin{
|
||||||
|
|
||||||
|
|
@ -77,14 +75,14 @@ public class ConnectionPlugin implements IPlugin{
|
||||||
for(String key : BladeConfig.getJedisPool().keySet()){
|
for(String key : BladeConfig.getJedisPool().keySet()){
|
||||||
JedisPool jedisPool = BladeConfig.getJedisPool().get(key);
|
JedisPool jedisPool = BladeConfig.getJedisPool().get(key);
|
||||||
//创建redis单机操作类
|
//创建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);
|
redisCachePool.put(key, rs);
|
||||||
}
|
}
|
||||||
//注入redisCluster
|
//注入redisCluster
|
||||||
for(String key : BladeConfig.getJedisCluster().keySet()){
|
for(String key : BladeConfig.getJedisCluster().keySet()){
|
||||||
JedisCluster jedisCluster = BladeConfig.getJedisCluster().get(key);
|
JedisCluster jedisCluster = BladeConfig.getJedisCluster().get(key);
|
||||||
//创建redis集群操作类
|
//创建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);
|
redisCachePool.put(key, rc);
|
||||||
}
|
}
|
||||||
if(!redisCachePool.containsKey(MASTER) && redisCachePool.size() > 0){
|
if(!redisCachePool.containsKey(MASTER) && redisCachePool.size() > 0){
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user