disconnection

This commit is contained in:
Dario Guzik
2011-05-13 18:03:38 -03:00
parent 121af74972
commit ace1588501

View File

@@ -61,6 +61,24 @@ public class Connection {
}
}
protected Object read() {
try {
return protocol.read(inputStream);
} catch (JedisConnectionException e) {
disconnect();
throw new JedisConnectionException(e);
}
}
protected void sendProtocolCommand(final Command cmd, final byte[]... args) {
try {
protocol.sendCommand(outputStream, cmd, args);
} catch (JedisConnectionException e) {
disconnect();
throw new JedisConnectionException(e);
}
}
protected Connection sendCommand(final Command cmd, final String... args) {
final byte[][] bargs = new byte[args.length][];
for (int i = 0; i < args.length; i++) {
@@ -71,14 +89,14 @@ public class Connection {
protected Connection sendCommand(final Command cmd, final byte[]... args) {
connect();
protocol.sendCommand(outputStream, cmd, args);
sendProtocolCommand(cmd, args);
pipelinedCommands++;
return this;
}
protected Connection sendCommand(final Command cmd) {
connect();
protocol.sendCommand(outputStream, cmd, new byte[0][]);
sendProtocolCommand(cmd, new byte[0][]);
pipelinedCommands++;
return this;
}
@@ -145,7 +163,7 @@ public class Connection {
protected String getStatusCodeReply() {
flush();
pipelinedCommands--;
final byte[] resp = (byte[]) protocol.read(inputStream);
final byte[] resp = (byte[]) read();
if (null == resp) {
return null;
} else {
@@ -165,13 +183,13 @@ public class Connection {
public byte[] getBinaryBulkReply() {
flush();
pipelinedCommands--;
return (byte[]) protocol.read(inputStream);
return (byte[]) read();
}
public Long getIntegerReply() {
flush();
pipelinedCommands--;
return (Long) protocol.read(inputStream);
return (Long) read();
}
public List<String> getMultiBulkReply() {
@@ -194,14 +212,14 @@ public class Connection {
public List<byte[]> getBinaryMultiBulkReply() {
flush();
pipelinedCommands--;
return (List<byte[]>) protocol.read(inputStream);
return (List<byte[]>) read();
}
@SuppressWarnings("unchecked")
public List<Object> getObjectMultiBulkReply() {
flush();
pipelinedCommands--;
return (List<Object>) protocol.read(inputStream);
return (List<Object>) read();
}
public List<Object> getAll() {
@@ -212,7 +230,7 @@ public class Connection {
List<Object> all = new ArrayList<Object>();
flush();
while (pipelinedCommands > except) {
all.add(protocol.read(inputStream));
all.add(read());
pipelinedCommands--;
}
return all;
@@ -221,6 +239,6 @@ public class Connection {
public Object getOne() {
flush();
pipelinedCommands--;
return protocol.read(inputStream);
return read();
}
}
}