示例#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;
            }
        }
示例#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);
        }
示例#3
0
        private IExchangeServer CreateServer(URL url)
        {
            // send readonly event when server closes, it's enabled by default
            url = url.AddParameterIfAbsent(Constants.ChannelReadonlyeventSentKey, "true");
            // enable heartbeat by default
            url = url.AddParameterIfAbsent(Constants.HeartbeatKey, Constants.DefaultHeartbeat.ToString());
            var          str         = url.GetParameter(Constants.ServerKey, Constants.DefaultRemotingServer);
            ITransporter transporter = null;

            if (!string.IsNullOrEmpty(str))
            {
                transporter = ObjectFactory.GetInstance <ITransporter>(str);
            }
            if (transporter == null)
            {
                throw new Exception("Unsupported server type: " + str + ", url: " + url);
            }

            url = url.AddParameter(Constants.CodecKey, DubboCodec.Name);
            IExchangeServer server;

            try
            {
                server = Exchangers.BindAsync(url, RequestHandler()).Result;
            }
            catch (RemotingException e)
            {
                throw new Exception("Fail to start server(url: " + url + ") " + e.Message);
            }
            str = url.GetParameter(Constants.ClientKey, "");
            if (!string.IsNullOrEmpty(str))
            {
                var supportedTypes = ObjectFactory.GetTypeKeys <ITransporter>();
                if (!supportedTypes.Contains(str))
                {
                    throw new Exception("Unsupported client type: " + str);
                }
            }
            return(server);
        }