use of com.sohu.tv.jedis.stat.model.UsefulDataModel 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 com.sohu.tv.jedis.stat.model.UsefulDataModel in project cachecloud by sohutv.
the class Connection method sendCommand.
protected Connection sendCommand(final ProtocolCommand cmd, final byte[]... args) {
try {
//统计开始
UsefulDataModel costModel = UsefulDataModel.getCostModel(threadLocal);
costModel.setCommand(cmd.toString().toLowerCase());
costModel.setStartTime(System.currentTimeMillis());
connect();
Protocol.sendCommand(outputStream, cmd, args);
return this;
} catch (JedisConnectionException ex) {
UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
/*
* When client send request which formed by invalid protocol, Redis send back error message
* before close connection. We try to read it to provide reason of failure.
*/
try {
String errorMessage = Protocol.readErrorLineIfPossible(inputStream);
if (errorMessage != null && errorMessage.length() > 0) {
ex = new JedisConnectionException(errorMessage, ex.getCause());
}
} catch (Exception e) {
/*
* Catch any IOException or JedisConnectionException occurred from InputStream#read and just
* ignore. This approach is safe because reading error message is optional and connection
* will eventually be closed.
*/
}
// Any other exceptions related to connection?
broken = true;
throw ex;
}
}
Aggregations