| 392 | } |
| 393 | |
| 394 | void connected( |
| 395 | const id::UUID& _connectionId, |
| 396 | const Future<tuple<Connection, Connection>>& _connections) |
| 397 | { |
| 398 | // It is possible that a new master was detected while we had an ongoing |
| 399 | // (re-)connection attempt with the old master. |
| 400 | if (connectionId != _connectionId) { |
| 401 | VLOG(1) << "Ignoring connection attempt from stale connection"; |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | CHECK_EQ(CONNECTING, state); |
| 406 | CHECK_SOME(connectionId); |
| 407 | |
| 408 | if (!_connections.isReady()) { |
| 409 | disconnected(connectionId.get(), |
| 410 | _connections.isFailed() |
| 411 | ? _connections.failure() |
| 412 | : "Connection future discarded"); |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | VLOG(1) << "Connected with the master at " << master.get(); |
| 417 | |
| 418 | state = CONNECTED; |
| 419 | |
| 420 | connections = |
| 421 | Connections {get<0>(_connections.get()), get<1>(_connections.get())}; |
| 422 | |
| 423 | connections->subscribe.disconnected() |
| 424 | .onAny(defer(self(), |
| 425 | &Self::disconnected, |
| 426 | connectionId.get(), |
| 427 | "Subscribe connection interrupted")); |
| 428 | |
| 429 | connections->nonSubscribe.disconnected() |
| 430 | .onAny(defer(self(), |
| 431 | &Self::disconnected, |
| 432 | connectionId.get(), |
| 433 | "Non-subscribe connection interrupted")); |
| 434 | |
| 435 | // Invoke the connected callback once we have established both subscribe |
| 436 | // and non-subscribe connections with the master. |
| 437 | mutex.lock() |
| 438 | .then(defer(self(), [this]() { |
| 439 | return async(callbacks.connected); |
| 440 | })) |
| 441 | .onAny(lambda::bind(&Mutex::unlock, mutex)); |
| 442 | } |
| 443 | |
| 444 | void disconnected( |
| 445 | const id::UUID& _connectionId, |