本文整理了Java中redis.clients.jedis.exceptions.JedisConnectionException.<init>()
方法的一些代码示例,展示了JedisConnectionException.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JedisConnectionException.<init>()
方法的具体详情如下:
包路径:redis.clients.jedis.exceptions.JedisConnectionException
类名称:JedisConnectionException
方法名:<init>
暂无
代码示例来源:origin: sohutv/cachecloud
public void rollbackTimeout() {
try {
socket.setSoTimeout(soTimeout);
} catch (SocketException ex) {
broken = true;
throw new JedisConnectionException(ex);
}
}
代码示例来源:origin: sohutv/cachecloud
/**
* This methods assumes there are required bytes to be read. If we cannot read anymore bytes an
* exception is thrown to quickly ascertain that the stream was smaller than expected.
*/
private void ensureFill() throws JedisConnectionException {
if (count >= limit) {
try {
limit = in.read(buf);
count = 0;
if (limit == -1) {
throw new JedisConnectionException("Unexpected end of stream.");
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
}
}
代码示例来源:origin: sohutv/cachecloud
public T getResource() {
try {
return internalPool.borrowObject();
} catch (Exception e) {
throw new JedisConnectionException("Could not get a resource from the pool", e);
}
}
代码示例来源:origin: sohutv/cachecloud
protected void flush() {
try {
outputStream.flush();
} catch (IOException ex) {
broken = true;
throw new JedisConnectionException(ex);
}
}
代码示例来源:origin: sohutv/cachecloud
public void setTimeoutInfinite() {
try {
if (!isConnected()) {
connect();
}
socket.setSoTimeout(0);
} catch (SocketException ex) {
broken = true;
throw new JedisConnectionException(ex);
}
}
代码示例来源:origin: sohutv/cachecloud
public String readLine() {
final StringBuilder sb = new StringBuilder();
while (true) {
ensureFill();
byte b = buf[count++];
if (b == '\r') {
ensureFill(); // Must be one more byte
byte c = buf[count++];
if (c == '\n') {
break;
}
sb.append((char) b);
sb.append((char) c);
} else {
sb.append((char) b);
}
}
final String reply = sb.toString();
if (reply.length() == 0) {
throw new JedisConnectionException("It seems like server has closed the connection.");
}
return reply;
}
代码示例来源:origin: sohutv/cachecloud
public void unsubscribe() {
if (client == null) {
throw new JedisConnectionException("JedisPubSub was not subscribed to a Jedis instance.");
}
client.unsubscribe();
client.flush();
}
代码示例来源:origin: sohutv/cachecloud
public void subscribe(String... channels) {
if (client == null) {
throw new JedisConnectionException("JedisPubSub is not subscribed to a Jedis instance.");
}
client.subscribe(channels);
client.flush();
}
代码示例来源:origin: sohutv/cachecloud
public void punsubscribe(String... patterns) {
if (client == null) {
throw new JedisConnectionException("JedisPubSub is not subscribed to a Jedis instance.");
}
client.punsubscribe(patterns);
client.flush();
}
代码示例来源:origin: sohutv/cachecloud
public void unsubscribe(String... channels) {
if (client == null) {
throw new JedisConnectionException("JedisPubSub is not subscribed to a Jedis instance.");
}
client.unsubscribe(channels);
client.flush();
}
代码示例来源:origin: sohutv/cachecloud
public void psubscribe(String... patterns) {
if (client == null) {
throw new JedisConnectionException("JedisPubSub is not subscribed to a Jedis instance.");
}
client.psubscribe(patterns);
client.flush();
}
代码示例来源:origin: sohutv/cachecloud
public void punsubscribe() {
if (client == null) {
throw new JedisConnectionException("JedisPubSub is not subscribed to a Jedis instance.");
}
client.punsubscribe();
client.flush();
}
代码示例来源:origin: sohutv/cachecloud
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
socket.setKeepAlive(true); // Will monitor the TCP connection is
// valid
socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
// ensure timely delivery of data
socket.setSoLinger(true, 0); // Control calls close () method,
// the underlying socket is closed
// immediately
// <-@wjw_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
broken = true;
throw new JedisConnectionException(ex);
}
}
}
代码示例来源:origin: sohutv/cachecloud
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);
}
}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Jedis getConnection() {
// In antirez's redis-rb-cluster implementation,
// getRandomConnection always return valid connection (able to
// ping-pong)
// or exception if all connections are invalid
List<JedisPool> pools = getShuffledNodesPool();
for (JedisPool pool : pools) {
Jedis jedis = null;
try {
jedis = pool.getResource();
if (jedis == null) {
continue;
}
String result = jedis.ping();
if (result.equalsIgnoreCase("pong")) return jedis;
pool.returnBrokenResource(jedis);
} catch (JedisConnectionException ex) {
if (jedis != null) {
pool.returnBrokenResource(jedis);
}
}
}
throw new JedisConnectionException("no reachable node in cluster");
}
代码示例来源:origin: sohutv/cachecloud
public long readLongCrLf() {
final byte[] buf = this.buf;
ensureFill();
final boolean isNeg = buf[count] == '-';
if (isNeg) {
++count;
}
long value = 0;
while (true) {
ensureFill();
final int b = buf[count++];
if (b == '\r') {
ensureFill();
if (buf[count++] != '\n') {
throw new JedisConnectionException("Unexpected character!");
}
break;
} else {
value = value * 10 + b - '0';
}
}
return (isNeg ? -value : value);
}
代码示例来源:origin: sohutv/cachecloud
private static byte[] processBulkReply(final RedisInputStream is) {
final int len = is.readIntCrLf();
if (len == -1) {
return null;
}
final byte[] read = new byte[len];
int offset = 0;
while (offset < len) {
final int size = is.read(read, offset, (len - offset));
if (size == -1) throw new JedisConnectionException(
"It seems like server has closed the connection.");
offset += size;
}
// read 2 more bytes for the command delimiter
is.readByte();
is.readByte();
return read;
}
代码示例来源:origin: sohutv/cachecloud
String errorMessage = Protocol.readErrorLineIfPossible(inputStream);
if (errorMessage != null && errorMessage.length() > 0) {
ex = new JedisConnectionException(errorMessage, ex.getCause());
代码示例来源:origin: sohutv/cachecloud
private static Object process(final RedisInputStream is) {
final byte b = is.readByte();
if (b == PLUS_BYTE) {
return processStatusCodeReply(is);
} else if (b == DOLLAR_BYTE) {
return processBulkReply(is);
} else if (b == ASTERISK_BYTE) {
return processMultiBulkReply(is);
} else if (b == COLON_BYTE) {
return processInteger(is);
} else if (b == MINUS_BYTE) {
processError(is);
return null;
} else {
throw new JedisConnectionException("Unknown reply: " + (char) b);
}
}
代码示例来源:origin: sohutv/cachecloud
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);
}
}
内容来源于网络,如有侵权,请联系作者删除!