Ejemplo n.º 1
0
        private void InitClient()
        {
            if (_client != null)
            {
                return;
            }
            if (_logger.InfoEnabled)
            {
                _logger.Info("Lazy connect to " + Url);
            }

            lock (_connectLock)
            {
                if (_client != null)
                {
                    return;
                }
                _client = Exchangers.ConnectAsync(Url, _requestHandler).Result;
            }
        }
Ejemplo n.º 2
0
        private IExchangeClient InitClient(URL url)
        {
            // client type setting.
            var str = url.GetParameter(Constants.ClientKey, url.GetParameter(Constants.ServerKey, Constants.DefaultRemotingClient));

            var version    = url.GetParameter(Constants.DubboVersionKey, "2.6.0");
            var compatible = (version != null && version.StartsWith("1.0."));

            url = url.AddParameter(Constants.CodecKey, DubboCodec.Name);
            // enable heartbeat by default
            url = url.AddParameterIfAbsent(Constants.HeartbeatKey, Constants.DefaultHeartbeat.ToString());

            // BIO is not allowed since it has severe performance issue.
            var transporter = ObjectFactory.GetInstance <ITransporter>(str);

            if (transporter == null)
            {
                throw new Exception("Unsupported client type: " + str + "," +
                                    " supported client type is " + ObjectFactory.GetTypeKeys <ITransporter>() + " ");
            }

            IExchangeClient client;

            try
            {
                // connection should be lazy
                if (url.GetParameter(Constants.LazyConnectKey, false))
                {
                    client = new LazyConnectExchangeClient(url, RequestHandler());
                }
                else
                {
                    client = Exchangers.ConnectAsync(url, RequestHandler()).Result;
                }
            }
            catch (RemotingException e)
            {
                throw new Exception("Fail to create remoting client for service(" + url + "): " + e.Message, e);
            }
            return(client);
        }