use of com.twitter.finagle.Failure in project distributedlog by twitter.
the class DistributedLogClientImpl method handleRequestException.
void handleRequestException(SocketAddress addr, ProxyClient sc, Optional<StreamOp> op, Throwable cause) {
boolean resendOp = false;
boolean removeOwnerFromStream = false;
SocketAddress previousAddr = addr;
String reason = cause.getMessage();
if (cause instanceof ConnectionFailedException || cause instanceof java.net.ConnectException) {
routingService.removeHost(addr, cause);
onServerLeft(addr, sc);
removeOwnerFromStream = true;
// redirect the request to other host.
resendOp = true;
} else if (cause instanceof ChannelException) {
// no process listening on remote address/port.
if (cause.getCause() instanceof java.net.ConnectException) {
routingService.removeHost(addr, cause.getCause());
onServerLeft(addr);
reason = cause.getCause().getMessage();
} else {
routingService.removeHost(addr, cause);
reason = cause.getMessage();
}
removeOwnerFromStream = true;
// redirect the request to other host.
resendOp = true;
} else if (cause instanceof ServiceTimeoutException) {
// redirect the request to itself again, which will backoff for a while
resendOp = true;
previousAddr = null;
} else if (cause instanceof WriteException) {
// redirect the request to other host.
resendOp = true;
} else if (cause instanceof ServiceException) {
// redirect the request to other host.
clientManager.removeClient(addr, sc);
resendOp = true;
} else if (cause instanceof TApplicationException) {
handleTApplicationException(cause, op, addr, sc);
} else if (cause instanceof Failure) {
handleFinagleFailure((Failure) cause, op, addr);
} else {
// Default handler
handleException(cause, op, addr);
}
if (op.isPresent()) {
if (removeOwnerFromStream) {
ownershipCache.removeOwnerFromStream(op.get().stream, addr, reason);
}
if (resendOp) {
doSend(op.get(), previousAddr);
}
}
}
Aggregations