stats.update(roundTrip, clusterRoundTrip, abort, error, restartCounter);
}
@Override
public void handleMessage(ByteBuffer buf, Connection c) {
ClientResponseImpl response = null;
FastDeserializer fds = new FastDeserializer(buf);
try {
response = fds.readObject(ClientResponseImpl.class);
} catch (IOException e) {
LOG.error("Invalid ClientResponse object returned by " + this, e);
return;
}
if (response == null) {
LOG.warn("Got back null ClientResponse. Ignoring...");
return;
}
final Long clientHandle = new Long(response.getClientHandle());
final Status status = response.getStatus();
final long now = System.currentTimeMillis();
CallbackValues stuff = null;
synchronized (this) {
stuff = m_callbacks.remove(clientHandle);
if (stuff != null) {
m_invocationsCompleted++;
// this.lastSeenClientHandles.add(clientHandle);
}
} // SYNCH
if (stuff != null) {
long callTime = stuff.time;
int delta = (int)(now - callTime);
ProcedureCallback cb = stuff.callback;
boolean abort = false;
boolean error = false;
if (debug.val) {
Map<String, Object> m0 = new LinkedHashMap<String, Object>();
m0.put("Txn #", response.getTransactionId());
m0.put("Status", response.getStatus());
m0.put("ClientHandle", clientHandle);
m0.put("RestartCounter", response.getRestartCounter());
m0.put("Callback", (cb != null ? cb.getClass().getSimpleName() : null));
Map<String, Object> m1 = new LinkedHashMap<String, Object>();
m1.put("Connection", this);
m1.put("Completed Invocations", m_invocationsCompleted);
m1.put("Error Invocations", m_invocationErrors);
m1.put("Abort Invocations", m_invocationAborts);
LOG.debug("ClientResponse Information:\n" + StringUtil.formatMaps(m0, m1));
}
if (status == Status.ABORT_USER || status == Status.ABORT_GRACEFUL) {
m_invocationAborts++;
abort = true;
} else if (status != Status.OK) {
m_invocationErrors++;
error = true;
}
int clusterRoundTrip = response.getClusterRoundtrip();
if (m_nanoseconds) clusterRoundTrip /= 1000000;
if (clusterRoundTrip < 0) clusterRoundTrip = 0;
this.updateStats(stuff.name, delta, clusterRoundTrip, abort, error, response.getRestartCounter());
if (cb != null) {
response.setClientRoundtrip(delta);
try {
cb.clientCallback(response);
} catch (Exception e) {
uncaughtException(cb, response, e);
}
m_callbacksToInvoke.decrementAndGet();
} else if (m_isConnected) {
// TODO: what's the right error path here?
LOG.warn("No callback available for clientHandle " + clientHandle);
}
}
else {
LOG.warn(String.format("Failed to get callback for client handle #%d from %s",
clientHandle, this, response.toString()
));
}
}