{
if(!isConnected()) throw new NotConnectedException ("Not connected!");
Request request = null;
Response response = null;
ResponseStatus status = null;
Protocol protocol = Assert.notNull(getProtocolHandler(), "thread protocol handler", ProviderException.class);
try {
// 1 - Request
// Log.log("RedisConnection - requesting ..." + cmd.code);
request = Assert.notNull(protocol.createRequest (cmd, args), "request object from handler", ProviderException.class);
request.write(super.getOutputStream());
// 2 - response
// Log.log("RedisConnection - read response ..." + cmd.code);
response = Assert.notNull(protocol.createResponse(cmd), "response object from handler", ProviderException.class);
response.read(super.getInputStream());
// break;
}
catch (ProviderException bug){
Log.bug ("serviceRequest() -- ProviderException: " + bug.getLocalizedMessage());
Log.log ("serviceRequest() -- closing connection ...");
disconnect();
throw bug;
}
catch (ClientRuntimeException cre) {
Log.problem ("serviceRequest() -- ClientRuntimeException => " + cre.getLocalizedMessage());
reconnect();
throw new ConnectionReset ("Connection re-established but last request not processed: " + cre.getLocalizedMessage());
}
catch (RuntimeException e){
e.printStackTrace();
Log.bug ("serviceRequest() -- *unexpected* RuntimeException: " + e.getLocalizedMessage());
Log.log ("serviceRequest() -- closing connection ...");
disconnect();
throw new ClientRuntimeException("unexpected runtime exeption: " + e.getLocalizedMessage(), e);
}
// 3 - Status
//
status = Assert.notNull (response.getStatus(), "status from response object", ProviderException.class);
if(status.isError()) {
Log.error ("Error response for " + cmd.code + " => " + status.message());
throw new RedisException(cmd, status.message());
}
else if(status.code() == ResponseStatus.Code.CIAO) {
// normal for quit and shutdown commands. we disconnect too.
disconnect();
}
return response;