| 418 | } |
| 419 | |
| 420 | void connect() |
| 421 | { |
| 422 | CHECK(state == DISCONNECTED || state == CONNECTING) << state; |
| 423 | |
| 424 | connectionId = id::UUID::random(); |
| 425 | |
| 426 | state = CONNECTING; |
| 427 | |
| 428 | // This automatic variable is needed for lambda capture. We need to |
| 429 | // create a copy here because `connectionId` might change by the time the |
| 430 | // second `http::connect()` gets called. |
| 431 | id::UUID connectionId_ = connectionId.get(); |
| 432 | |
| 433 | // We create two persistent connections here, one for subscribe |
| 434 | // call/streaming response and another for non-subscribe calls/responses. |
| 435 | process::http::connect(agent) |
| 436 | .onAny(defer(self(), [this, connectionId_]( |
| 437 | const Future<Connection>& connection) { |
| 438 | process::http::connect(agent) |
| 439 | .onAny(defer(self(), |
| 440 | &Self::connected, |
| 441 | connectionId_, |
| 442 | connection, |
| 443 | lambda::_1)); |
| 444 | })); |
| 445 | } |
| 446 | |
| 447 | void connected( |
| 448 | const id::UUID& _connectionId, |