Example #1
0
        public bool Connect()
        {
            try
            {
                _transport = new TFramedTransport(new TSocket(_host, _port));
                TProtocol protocol = new TBinaryProtocol(_transport);
                _client = new Apache.Cassandra.Cassandra.Client(protocol);

                _transport.Open();

                _client.set_keyspace(_keyspace);

                _isConnected = true;
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
            return(_isConnected);
        }
        private Apache.Cassandra.Cassandra.Client CreateConnection(String host)
        {
            TSocket socket = new TSocket(host, this.port);
            TTransport trans = new TFramedTransport(socket);
            try
            {
                trans.Open();
            }
            catch (TTransportException exception)
            {
                throw new Exception("unable to connect to server", exception);
            }

            Apache.Cassandra.Cassandra.Client client = new Apache.Cassandra.Cassandra.Client(new TBinaryProtocol(trans));
            if (this.ringKs != null)
            {
                try
                {
                    client.set_keyspace(this.ringKs);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }

            return client;
        }
Example #3
0
        public void login(string keyspace, string username, string password)
        {
            client.set_keyspace(keyspace);

            AuthenticationRequest       authrequst  = new AuthenticationRequest();
            Dictionary <string, string> credentials = new Dictionary <string, string>();

            credentials.Add(username, password);
            authrequst.Credentials = credentials;
            try
            {
                client.login(authrequst);
            }
            catch (AuthenticationException e)
            {
                //To-do handle thirift auth exception with our own auth exception
                throw;
            }
        }