| 338 | |
| 339 | |
| 340 | class _HostReconnectionHandler(_ReconnectionHandler): |
| 341 | |
| 342 | def __init__(self, host, connection_factory, is_host_addition, on_add, on_up, *args, **kwargs): |
| 343 | _ReconnectionHandler.__init__(self, *args, **kwargs) |
| 344 | self.is_host_addition = is_host_addition |
| 345 | self.on_add = on_add |
| 346 | self.on_up = on_up |
| 347 | self.host = host |
| 348 | self.connection_factory = connection_factory |
| 349 | |
| 350 | def try_reconnect(self): |
| 351 | return self.connection_factory() |
| 352 | |
| 353 | def on_reconnection(self, connection): |
| 354 | log.info("Successful reconnection to %s, marking node up if it isn't already", self.host) |
| 355 | if self.is_host_addition: |
| 356 | self.on_add(self.host) |
| 357 | else: |
| 358 | self.on_up(self.host) |
| 359 | |
| 360 | def on_exception(self, exc, next_delay): |
| 361 | if isinstance(exc, AuthenticationFailed): |
| 362 | return False |
| 363 | else: |
| 364 | log.warning("Error attempting to reconnect to %s, scheduling retry in %s seconds: %s", |
| 365 | self.host, next_delay, exc) |
| 366 | log.debug("Reconnection error details", exc_info=True) |
| 367 | return True |
| 368 | |
| 369 | |
| 370 | class HostConnection(object): |