use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class Connection method disconnect.
public void disconnect() {
if (isConnected()) {
try {
outputStream.flush();
socket.close();
} catch (IOException ex) {
UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
broken = true;
throw new JedisConnectionException(ex);
} finally {
IOUtils.closeQuietly(socket);
}
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class Connection method readProtocolWithCheckingBroken.
protected Object readProtocolWithCheckingBroken() {
Object o = null;
try {
o = Protocol.read(inputStream);
return o;
} catch (JedisConnectionException exc) {
UsefulDataCollector.collectException(exc, getHostPort(), System.currentTimeMillis());
broken = true;
throw exc;
} finally {
UsefulDataModel costModel = UsefulDataModel.getCostModel(threadLocal);
costModel.setHostPort(getHostPort());
costModel.setEndTime(System.currentTimeMillis());
// 1.上报command + cost给指定
if (o != null) {
if (o instanceof byte[]) {
byte[] bytes = (byte[]) o;
// 2.上报字节大小
costModel.setValueBytesLength(bytes.length);
}
}
// 清除threadLocal
threadLocal.remove();
// 排除掉subscribe问题
if (costModel.getCommand() != null) {
UsefulDataCollector.collectCostAndValueDistribute(costModel);
}
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class Protocol method sendCommand.
private static void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) {
try {
os.write(ASTERISK_BYTE);
os.writeIntCrLf(args.length + 1);
os.write(DOLLAR_BYTE);
os.writeIntCrLf(command.length);
os.write(command);
os.writeCrLf();
for (final byte[] arg : args) {
os.write(DOLLAR_BYTE);
os.writeIntCrLf(arg.length);
os.write(arg);
os.writeCrLf();
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.
the class JedisSentinelPoolTest method returnResourceShouldResetState.
@Test
public void returnResourceShouldResetState() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
Jedis jedis = pool.getResource();
Jedis jedis2 = null;
try {
jedis.set("hello", "jedis");
Transaction t = jedis.multi();
t.set("hello", "world");
jedis.close();
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
jedis2 = null;
}
} finally {
jedis2.close();
pool.destroy();
}
}
use of redis.clients.jedis.exceptions.JedisConnectionException in project jstorm by alibaba.
the class RedisSinkBolt method retryGet.
private byte[] retryGet(byte[] key) {
int retry = 0;
byte[] ret;
while (true) {
Jedis jedis = null;
try {
jedis = pool.getResource();
ret = jedis.get(key);
return ret;
} catch (JedisConnectionException e) {
if (jedis != null) {
pool.returnBrokenResource(jedis);
jedis = null;
}
if (retry > retryLimit) {
throw e;
}
retry++;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
}
}
Aggregations