Ejemplo n.º 1
0
 public static function get_client($write_mode = false)
 {
     // * Try to connect to every cassandra node in order
     // * Failed connections will be retried
     // * Once a connection is opened, it stays open
     // * TODO: add random and round robin order
     // * TODO: add write-preferred and read-preferred nodes
     if (self::$last_get instanceof CassandraClient) {
         return self::$last_get;
     }
     shuffle(self::$connections);
     foreach (self::$connections as $connection) {
         try {
             $transport = $connection['transport'];
             $client = $connection['client'];
             if (!$transport->isOpen()) {
                 $transport->open();
             }
             self::$last_get = $client;
             return $client;
         } catch (TException $tx) {
             self::$last_error = 'TException: ' . $tx->getMessage() . "\n";
             continue;
         }
     }
     throw new Exception("Could not connect to a cassandra server");
 }