Esempio n. 1
0
        static async Task Main(string[] args)
        {
            int port = 9090;

            string host = args.Length == 1 ? args[0] : "localhost";

            var ip        = IPAddress.Parse(host);
            var transport = new TBufferedClientTransport(new TSocketClientTransport(ip, port));
            var proto     = new TBinaryProtocol(transport);

            _hbase = new Hbase.Thrift.Hbase.Client(proto);

            try
            {
                await transport.OpenAsync();

                var names = await _hbase.getTableNamesAsync(CancellationToken.None);

                names.ForEach(msg => Console.WriteLine(Encoding.UTF8.GetString(msg)));

                await CreateTable();
                await Insert();
                await Get();

                transport.Close();
            }
            catch (Exception e)
            {
                Console.Error.Write(e.ToString());
            }
        }
        protected override async Task <TClientTransport> AcceptImplementationAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(await Task.FromCanceled <TClientTransport>(cancellationToken));
            }

            if (_server == null)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
            }

            try
            {
                TClientTransport tSocketTransport = null;
                var tcpClient = await _server.AcceptTcpClientAsync();

                try
                {
                    tSocketTransport = new TSocketClientTransport(tcpClient)
                    {
                        Timeout = _clientTimeout
                    };

                    if (_useBufferedSockets)
                    {
                        tSocketTransport = new TBufferedClientTransport(tSocketTransport);
                    }

                    if (_useFramedTransport)
                    {
                        tSocketTransport = new TFramedClientTransport(tSocketTransport);
                    }

                    return(tSocketTransport);
                }
                catch (Exception)
                {
                    if (tSocketTransport != null)
                    {
                        tSocketTransport.Dispose();
                    }
                    else //  Otherwise, clean it up ourselves.
                    {
                        ((IDisposable)tcpClient).Dispose();
                    }

                    throw;
                }
            }
            catch (Exception ex)
            {
                throw new TTransportException(ex.ToString());
            }
        }
Esempio n. 3
0
            public TClientTransport CreateTransport()
            {
                if (url == null)
                {
                    // endpoint transport
                    TClientTransport trans = null;

                    if (pipe != null)
                    {
                        trans = new TNamedPipeClientTransport(pipe);
                    }
                    else
                    {
                        if (encrypted)
                        {
                            var cert = GetClientCert();

                            if (cert == null || !cert.HasPrivateKey)
                            {
                                throw new InvalidOperationException("Certificate doesn't contain private key");
                            }

                            trans = new TTlsSocketClientTransport(host, port, 0, cert,
                                                                  (sender, certificate, chain, errors) => true,
                                                                  null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12);
                        }
                        else
                        {
                            trans = new TSocketClientTransport(host, port);
                        }
                    }

                    // layered transport
                    if (buffered)
                    {
                        trans = new TBufferedClientTransport(trans);
                    }

                    if (framed)
                    {
                        trans = new TFramedClientTransport(trans);
                    }

                    return(trans);
                }

                return(new THttpClientTransport(new Uri(url), null));
            }
Esempio n. 4
0
        protected override async Task <TClientTransport> AcceptImplementationAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(await Task.FromCanceled <TClientTransport>(cancellationToken));
            }

            if (_server == null)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
            }

            try
            {
                var client = await _server.AcceptTcpClientAsync();

                client.SendTimeout = client.ReceiveTimeout = _clientTimeout;

                //wrap the client in an SSL Socket passing in the SSL cert
                var tTlsSocket = new TTlsSocketClientTransport(client, _serverCertificate, true, _clientCertValidator,
                                                               _localCertificateSelectionCallback, _sslProtocols);

                await tTlsSocket.SetupTlsAsync();

                TClientTransport trans = tTlsSocket;

                if (_useBufferedSockets)
                {
                    trans = new TBufferedClientTransport(trans);
                }

                if (_useFramedTransport)
                {
                    trans = new TFramedClientTransport(trans);
                }

                return(trans);
            }
            catch (Exception ex)
            {
                throw new TTransportException(ex.ToString());
            }
        }
            public TClientTransport CreateTransport()
            {
                if (url == null)
                {
                    // endpoint transport
                    TClientTransport trans = null;

                    if (pipe != null)
                    {
                        trans = new TNamedPipeClientTransport(pipe);
                    }
                    else
                    {
                        if (encrypted)
                        {
                            var certPath = "../../keys/client.p12";
                            var cert     = new X509Certificate2(certPath, "thrift");
                            trans = new TTlsSocketClientTransport(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls);
                        }
                        else
                        {
                            trans = new TSocketClientTransport(host, port);
                        }
                    }

                    // layered transport
                    if (buffered)
                    {
                        trans = new TBufferedClientTransport(trans);
                    }

                    if (framed)
                    {
                        trans = new TFramedClientTransport(trans);
                    }

                    return(trans);
                }

                return(new THttpClientTransport(new Uri(url), null));
            }