Creates and returns a new :class:`~.Session` object. If `keyspace` is specified, that keyspace will be the default keyspace for operations on the ``Session``. `wait_for_all_pools` specifies whether this call should wait for all connection pools to be establ
(self, keyspace=None, wait_for_all_pools=False)
| 1669 | self.protocol_version = new_version |
| 1670 | |
| 1671 | def connect(self, keyspace=None, wait_for_all_pools=False): |
| 1672 | """ |
| 1673 | Creates and returns a new :class:`~.Session` object. |
| 1674 | |
| 1675 | If `keyspace` is specified, that keyspace will be the default keyspace for |
| 1676 | operations on the ``Session``. |
| 1677 | |
| 1678 | `wait_for_all_pools` specifies whether this call should wait for all connection pools to be |
| 1679 | established or attempted. Default is `False`, which means it will return when the first |
| 1680 | successful connection is established. Remaining pools are added asynchronously. |
| 1681 | """ |
| 1682 | with self._lock: |
| 1683 | if self.is_shutdown: |
| 1684 | raise DriverException("Cluster is already shut down") |
| 1685 | |
| 1686 | if not self._is_setup: |
| 1687 | log.debug("Connecting to cluster, contact points: %s; protocol version: %s", |
| 1688 | self.contact_points, self.protocol_version) |
| 1689 | self.connection_class.initialize_reactor() |
| 1690 | _register_cluster_shutdown(self) |
| 1691 | for endpoint in self.endpoints_resolved: |
| 1692 | host, new = self.add_host(endpoint, signal=False) |
| 1693 | if new: |
| 1694 | host.set_up() |
| 1695 | for listener in self.listeners: |
| 1696 | listener.on_add(host) |
| 1697 | |
| 1698 | self.profile_manager.populate( |
| 1699 | weakref.proxy(self), self.metadata.all_hosts()) |
| 1700 | self.load_balancing_policy.populate( |
| 1701 | weakref.proxy(self), self.metadata.all_hosts() |
| 1702 | ) |
| 1703 | |
| 1704 | try: |
| 1705 | self.control_connection.connect() |
| 1706 | |
| 1707 | # we set all contact points up for connecting, but we won't infer state after this |
| 1708 | for endpoint in self.endpoints_resolved: |
| 1709 | h = self.metadata.get_host(endpoint) |
| 1710 | if h and self.profile_manager.distance(h) == HostDistance.IGNORED: |
| 1711 | h.is_up = None |
| 1712 | |
| 1713 | log.debug("Control connection created") |
| 1714 | except Exception: |
| 1715 | log.exception("Control connection failed to connect, " |
| 1716 | "shutting down Cluster:") |
| 1717 | self.shutdown() |
| 1718 | raise |
| 1719 | |
| 1720 | self.profile_manager.check_supported() # todo: rename this method |
| 1721 | |
| 1722 | if self.idle_heartbeat_interval: |
| 1723 | self._idle_heartbeat = ConnectionHeartbeat( |
| 1724 | self.idle_heartbeat_interval, |
| 1725 | self.get_connection_holders, |
| 1726 | timeout=self.idle_heartbeat_timeout |
| 1727 | ) |
| 1728 | self._is_setup = True |